name: CI/CD
on:
push:
branches:
- main tags:
- "v*.*.*" pull_request:
branches:
- main
jobs:
build-and-test:
name: Build & Test ${{ matrix.build }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- build: linux-amd64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
cmd: cargo
- build: windows-amd64
os: windows-latest
target: x86_64-pc-windows-gnu
cmd: cargo
- build: macos-amd64
os: macos-latest
target: x86_64-apple-darwin
cmd: cargo
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
components: rustfmt, clippy
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: ". -> target"
- name: Run fmt check
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: |
echo "::group::Running tests (${{ matrix.build }})"
${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }}
echo "::endgroup::"
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Rust cache
uses: Swatinem/rust-cache@v2
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --no-deps --document-private-items
build-artifacts:
name: Build Artifacts ${{ matrix.build }}
if: startsWith(github.ref, 'refs/tags/')
needs: build-and-test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- build: linux-amd64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- build: windows-gnu
os: windows-latest
target: x86_64-pc-windows-gnu
- build: macos-amd64
os: macos-latest
target: x86_64-apple-darwin
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
components: rustfmt, clippy
- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
workspaces: ". -> target/release"
cache-on-failure: true
- name: Build release binary
run: |
echo "::group::Building release binary (${{ matrix.build }})"
cargo build --verbose --locked --release --target ${{ matrix.target }}
echo "::endgroup::"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: gait-${{ matrix.build }}
path: |
./target/${{ matrix.target }}/release/git-changelog${{ matrix.os == 'windows-latest' && '.exe' || '' }}
./target/${{ matrix.target }}/release/git-message${{ matrix.os == 'windows-latest' && '.exe' || '' }}
./target/${{ matrix.target }}/release/git-pr${{ matrix.os == 'windows-latest' && '.exe' || '' }}
./target/${{ matrix.target }}/release/git-release-notes${{ matrix.os == 'windows-latest' && '.exe' || '' }}
./target/${{ matrix.target }}/release/git-review${{ matrix.os == 'windows-latest' && '.exe' || '' }}
./target/${{ matrix.target }}/release/git-wire${{ matrix.os == 'windows-latest' && '.exe' || '' }}
if-no-files-found: error
retention-days: 1
cargo-publish:
name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/')
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Rust cache
uses: Swatinem/rust-cache@v2
- name: Setup crates.io token
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish to crates.io
run: |
echo "::group::Publishing to crates.io"
cargo publish
echo "::endgroup::"
- name: crates.io publish successful
run: echo "✨ Successfully published to crates.io"
create-release:
name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
needs: [build-artifacts, cargo-publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare release assets
run: |
echo "::group::Preparing release assets"
mkdir -p release-assets
find ./artifacts -type f -exec cp {} ./release-assets/ \;
ls -la ./release-assets
echo "::endgroup::"
- name: Generate release notes with gait
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
echo "::group::Generating release notes"
if [ -n "$OPENAI_API_KEY" ]; then
# Build gait locally to generate release notes
cargo build --release
# Get previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREVIOUS_TAG" ]; then
# Generate release notes using gait
./target/release/git-release-notes --from "$PREVIOUS_TAG" --to "$GITHUB_REF_NAME" --print > RELEASE_NOTES.md
echo "✨ Generated release notes with gait"
else
echo "No previous tag found, using default release notes"
echo "# Release $GITHUB_REF_NAME" > RELEASE_NOTES.md
echo "See commit history for changes." >> RELEASE_NOTES.md
fi
else
echo "No OpenAI API key available, using default release notes"
echo "# Release $GITHUB_REF_NAME" > RELEASE_NOTES.md
echo "See commit history for changes." >> RELEASE_NOTES.md
fi
cat RELEASE_NOTES.md
echo "::endgroup::"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: |
./release-assets/*
body_path: RELEASE_NOTES.md