Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Pull Request Checks

on:
pull_request:
branches:
- main
- feature/**

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
check:
name: Check Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Check formatting
run: cargo fmt -- --check

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

test:
name: Test Suite
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
run: cargo test --verbose --all

- name: Run tests (release)
run: cargo test --verbose --all --release

build:
name: Build Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --release -p cfkv

- name: Verify binary
run: ./target/release/cfkv --version
201 changes: 201 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: Test and Release

on:
push:
branches:
- main
- feature/**
tags:
- "v*"
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
run: cargo test --verbose --all

- name: Run tests (release)
run: cargo test --verbose --all --release

- name: Check formatting
run: cargo fmt -- --check

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

build:
name: Build ${{ matrix.asset_name }}
runs-on: ${{ matrix.os }}
needs: test
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: cfkv
asset_name: cfkv-linux-x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: cfkv
asset_name: cfkv-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: cfkv
asset_name: cfkv-macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: cfkv.exe
asset_name: cfkv-windows-x86_64.exe
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --release --target ${{ matrix.target }} -p cfkv

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.asset_name }}
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}

create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: artifacts

- name: Prepare release assets
run: |
mkdir -p release-assets
cd artifacts
for asset_dir in */; do
asset_name="${asset_dir%/}"
if [[ "$asset_name" == *"windows"* ]]; then
cp "$asset_dir"* "../release-assets/$asset_name"
else
cp "$asset_dir"* "../release-assets/$asset_name"
cd ../release-assets
tar -czf "${asset_name}.tar.gz" "$asset_name"
rm "$asset_name"
cd ../artifacts
fi
done
cd ..
echo "Release assets prepared:"
ls -lh release-assets/

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: release-assets/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

auto-release:
name: Auto-Create Release Tag
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get version from Cargo.toml
id: version
run: |
VERSION=$(grep -m1 'version = ' Cargo.toml | sed 's/.*version = "\([^"]*\)".*/\1/')
TAG="v${VERSION}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Detected version: ${TAG}"

- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.version.outputs.tag }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.version.outputs.tag }} does not exist, will create"
fi

- name: Create and push tag
if: steps.check_tag.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
echo "Created and pushed tag: ${{ steps.version.outputs.tag }}"
Loading