Add multi-platform binary releases and automated publishing #17
Workflow file for this run
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: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install nextest | |
| uses: taiki-e/install-action@nextest | |
| - name: Format check | |
| run: cargo fmt --check | |
| - name: Lint | |
| run: cargo clippy -- -D warnings | |
| - name: Run tests | |
| run: cargo nextest run | |
| - name: Build | |
| run: cargo build --release | |
| release: | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check if version changed | |
| id: version-check | |
| run: | | |
| # Get current version from Cargo.toml | |
| CURRENT_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| # Get previous version from parent commit | |
| git show HEAD^:Cargo.toml > /tmp/old-cargo.toml 2>/dev/null || echo 'version = "0.0.0"' > /tmp/old-cargo.toml | |
| PREVIOUS_VERSION=$(grep '^version' /tmp/old-cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') | |
| echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT | |
| # Check if version changed | |
| if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Version changed: $PREVIOUS_VERSION -> $CURRENT_VERSION" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Version unchanged: $CURRENT_VERSION" | |
| fi | |
| - name: Check if tag exists | |
| if: steps.version-check.outputs.changed == 'true' | |
| id: tag-check | |
| run: | | |
| if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.version-check.outputs.current }}$"; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Tag v${{ steps.version-check.outputs.current }} already exists" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Rust | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false' | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false' | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Build release | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false' | |
| run: cargo build --release | |
| - name: Create tag | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.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 "v${{ steps.version-check.outputs.current }}" -m "Release v${{ steps.version-check.outputs.current }}" | |
| git push origin "v${{ steps.version-check.outputs.current }}" | |
| - name: Create GitHub Release | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version-check.outputs.current }} | |
| name: v${{ steps.version-check.outputs.current }} | |
| generate_release_notes: true | |
| files: target/release/migrate | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to crates.io | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false' | |
| run: cargo publish | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |