git-ai 1.1.1

Git AI: Automates commit messages using ChatGPT. Stage your files, and Git AI generates the messages.
Documentation
name: CD

on:
  push:
    branches:
      - main
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

permissions:
  contents: write
  actions: write
  packages: write

env:
  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  GH_TOKEN: ${{ secrets.GH_TOKEN }}
  ACTIONS_RUNTIME_TOKEN: dummy
  CARGO_TERM_COLOR: always

jobs:
  artifact:
    runs-on: ${{ matrix.os }}
    continue-on-error: false
    strategy:
      matrix:
        include:
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
    steps:
      - uses: actions/checkout@v5
      - uses: Swatinem/rust-cache@v2
        with:
          cache-on-failure: true

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

      - name: Add x86_64-unknown-linux-musl target
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: |
          rustup target add x86_64-unknown-linux-musl
          sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Install Dependencies for musl Target
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: |
          sudo apt-get update
          sudo apt-get install -y musl-tools musl-dev perl make pkg-config libssl-dev
          # Set up environment for musl compilation
          echo "CC_x86_64_unknown_linux_musl=musl-gcc" >> $GITHUB_ENV
          echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> $GITHUB_ENV

      - name: Install Dependencies for Linux Target
        if: matrix.target == 'x86_64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y pkg-config libssl-dev

      - name: Build for target
        run: |
          cargo build \
            -Z unstable-options \
            --profile release-with-debug \
            --artifact-dir bin \
            --target ${{ matrix.target }}

      - name: Upload and compress artifacts
        uses: actions/upload-artifact@v4
        with:
          name: git-ai-${{ matrix.target }}
          if-no-files-found: error
          path: bin/git-*

  release:
    runs-on: ubuntu-latest
    needs: artifact
    steps:
      - uses: actions/checkout@v5
      - uses: Swatinem/rust-cache@v2

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@nightly

      - name: Configure git user name
        run: git config user.name ${{ github.actor }}

      - name: Configure git email
        run: git config user.email ${{ github.actor }}@users.noreply.github.com

      - name: Install cargo-bump
        run: cargo install cargo-bump

      - name: Bump version
        run: cargo bump patch --git-tag

      - name: Commit Version Bump
        run: git commit -a --amend --no-edit

      - name: New version
        id: app
        run: echo "version=$(git describe --tags --abbrev=0 HEAD)" >> $GITHUB_OUTPUT

      - name: Delete old tag
        run: git tag -d ${{ steps.app.outputs.version }}

      - name: Create new tag
        run: git tag v${{ steps.app.outputs.version }}

      - name: Publish to crates.io
        if: github.ref == 'refs/heads/main'
        run: cargo publish --allow-dirty

      - name: Test publish to crates.io (dry run)
        if: github.ref != 'refs/heads/main'
        run: cargo publish --dry-run --allow-dirty

      - name: Push to origin
        if: github.ref == 'refs/heads/main'
        run: git push origin HEAD --tags

      - name: Test push to origin (dry run)
        if: github.ref != 'refs/heads/main'
        run: git push origin HEAD --tags --dry-run

      - name: Download all artifacts
        run: gh run download ${{ github.run_id }}

      - name: Zip each downloaded directory
        run: |
          for dir in $(ls -d git-ai-*); do
            tar -czf ${dir}.tar.gz ${dir}
          done

      - name: Uploads compressed artifacts
        if: github.ref == 'refs/heads/main'
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ steps.app.outputs.version }}
          fail_on_unmatched_files: true
          files: git-ai-*.tar.gz