Implement automatic update system for Digstore CLI #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [ main, master ] | |
pull_request: | |
branches: [ main, master ] | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
bump-version: | |
name: Bump Version | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
outputs: | |
new_version: ${{ steps.bump.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GH_ACCESS_TOKEN }} | |
- name: Setup Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Bump version | |
id: bump | |
run: | | |
# Read current version | |
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | cut -d '"' -f 2) | |
echo "Current version: $CURRENT_VERSION" | |
# Parse semantic version | |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
# Increment patch version | |
new_patch=$((patch + 1)) | |
NEW_VERSION="$major.$minor.$new_patch" | |
echo "New version: $NEW_VERSION" | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
# Update Cargo.toml | |
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml | |
# Commit version bump | |
git add Cargo.toml | |
git commit -m "Bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit" | |
git push || echo "No changes to push" | |
test: | |
name: Test Suite | |
runs-on: ${{ matrix.os }} | |
needs: bump-version | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
rust: [stable, beta] | |
exclude: | |
# Reduce matrix size by excluding beta on macOS and Windows | |
- os: macos-latest | |
rust: beta | |
- os: windows-latest | |
rust: beta | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ matrix.rust }} | |
components: rustfmt, clippy | |
- 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-index-${{ 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 -- -D warnings | |
- name: Build | |
run: cargo build --verbose | |
- name: Run tests | |
run: cargo test --verbose | |
- name: Test CLI functionality | |
run: | | |
# Test basic CLI workflow | |
cargo run -- init --name "ci-test" | |
cargo run -- add README.md | |
cargo run -- status | |
cargo run -- commit -m "CI test commit" | |
cargo run -- get README.md > /dev/null | |
cargo run -- log | |
cargo run -- info | |
echo "CLI workflow test passed!" | |
build: | |
name: Build Release | |
runs-on: ${{ matrix.os }} | |
needs: bump-version | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
artifact_name: digstore-linux-x86_64 | |
- os: windows-latest | |
target: x86_64-pc-windows-msvc | |
artifact_name: digstore-windows-x86_64.exe | |
- os: macos-latest | |
target: x86_64-apple-darwin | |
artifact_name: digstore-macos-x86_64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Build release | |
run: cargo build --release --target ${{ matrix.target }} | |
- name: Rename binary (Unix) | |
if: matrix.os != 'windows-latest' | |
run: | | |
cp target/${{ matrix.target }}/release/digstore ${{ matrix.artifact_name }} | |
- name: Rename binary (Windows) | |
if: matrix.os == 'windows-latest' | |
run: | | |
copy target\${{ matrix.target }}\release\digstore.exe ${{ matrix.artifact_name }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.artifact_name }} | |
path: ${{ matrix.artifact_name }} | |
security: | |
name: Security Audit | |
runs-on: ubuntu-latest | |
needs: bump-version | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- name: Install cargo-audit | |
run: cargo install cargo-audit | |
- name: Run security audit | |
run: cargo audit | |
coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
needs: bump-version | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
components: llvm-tools-preview | |
- name: Install cargo-llvm-cov | |
run: cargo install cargo-llvm-cov | |
- name: Generate coverage | |
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
files: lcov.info | |
fail_ci_if_error: false | |
docs: | |
name: Documentation | |
runs-on: ubuntu-latest | |
needs: bump-version | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- name: Build documentation | |
run: cargo doc --no-deps --all-features | |
- name: Deploy to GitHub Pages | |
if: github.ref == 'refs/heads/main' | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./target/doc |