Release #4
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: Release | |
| on: | |
| push: | |
| tags: | |
| - "v[0-9]+.[0-9]+.[0-9]+" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag to release (e.g., v1.0.0)" | |
| required: true | |
| type: string | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| setup: | |
| name: Setup | |
| runs-on: ubuntu-latest | |
| outputs: | |
| ref: ${{ steps.get-ref.outputs.ref }} | |
| version: ${{ steps.get-ref.outputs.version }} | |
| version_number: ${{ steps.get-ref.outputs.version_number }} | |
| steps: | |
| - name: Determine ref and version | |
| id: get-ref | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| REF="${{ github.event.inputs.tag }}" | |
| else | |
| REF="${{ github.ref }}" | |
| fi | |
| echo "ref=$REF" >> $GITHUB_OUTPUT | |
| # Extract version from ref (remove refs/tags/ prefix if present) | |
| VERSION="${REF#refs/tags/}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Also create version without 'v' prefix for cargo | |
| VERSION_NUMBER="${VERSION#v}" | |
| echo "version_number=$VERSION_NUMBER" >> $GITHUB_OUTPUT | |
| echo "Using ref: $REF" | |
| echo "Using version: $VERSION" | |
| echo "Using version number: $VERSION_NUMBER" | |
| verify-version: | |
| name: Verify version matches tag | |
| needs: setup | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref }} | |
| - name: Verify Cargo.toml version matches tag | |
| run: | | |
| TAG_VERSION="${{ needs.setup.outputs.version }}" | |
| # Remove 'v' prefix if present | |
| TAG_VERSION="${TAG_VERSION#v}" | |
| CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2) | |
| echo "Tag version: $TAG_VERSION" | |
| echo "Cargo.toml version: $CARGO_VERSION" | |
| if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then | |
| echo "❌ Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)" | |
| echo "Please ensure the version in Cargo.toml matches the tag you're trying to release." | |
| exit 1 | |
| fi | |
| echo "✅ Version check passed!" | |
| test: | |
| name: Run tests | |
| needs: [setup, verify-version] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref }} | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Run tests | |
| run: cargo test --all-features --verbose | |
| - name: Run clippy | |
| run: cargo clippy --all-features -- -D warnings | |
| build-binaries: | |
| name: Build binaries | |
| needs: [setup, verify-version, test] | |
| strategy: | |
| matrix: | |
| include: | |
| # Linux | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: sql-schema-x86_64-linux | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: sql-schema-aarch64-linux | |
| # macOS | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| name: sql-schema-x86_64-macos | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| name: sql-schema-aarch64-macos | |
| # Windows | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| name: sql-schema-x86_64-windows.exe | |
| - target: aarch64-pc-windows-msvc | |
| os: windows-latest | |
| name: sql-schema-aarch64-windows.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref }} | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools for aarch64-linux | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Build binary | |
| run: cargo build --release --target ${{ matrix.target }} --verbose | |
| env: | |
| CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | |
| - name: Prepare binary | |
| shell: bash | |
| run: | | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| cp target/${{ matrix.target }}/release/sql-schema.exe ${{ matrix.name }} | |
| else | |
| cp target/${{ matrix.target }}/release/sql-schema ${{ matrix.name }} | |
| fi | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.name }} | |
| path: ${{ matrix.name }} | |
| create-release: | |
| name: Create GitHub Release | |
| needs: [setup, build-binaries] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref }} | |
| fetch-depth: 0 # Fetch all history for git-cliff | |
| - name: Generate changelog | |
| id: git-cliff | |
| uses: orhun/git-cliff-action@v4 | |
| with: | |
| config: cliff.toml | |
| args: --current --strip all | |
| env: | |
| OUTPUT: CHANGELOG.md | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./binaries | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ needs.setup.outputs.ref }} | |
| release_name: Release ${{ needs.setup.outputs.version }} | |
| draft: false | |
| prerelease: false | |
| body: | | |
| ## Changes in ${{ needs.setup.outputs.version }} | |
| ${{ steps.git-cliff.outputs.content }} | |
| ### Installation | |
| #### From crates.io | |
| ```bash | |
| cargo install sql-schema@${{ needs.setup.outputs.version_number }} | |
| ``` | |
| #### Binary downloads | |
| Download the appropriate binary for your platform from the assets below. | |
| - name: Upload Linux x86_64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-x86_64-linux/sql-schema-x86_64-linux | |
| asset_name: sql-schema-x86_64-linux | |
| asset_content_type: application/octet-stream | |
| - name: Upload Linux aarch64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-aarch64-linux/sql-schema-aarch64-linux | |
| asset_name: sql-schema-aarch64-linux | |
| asset_content_type: application/octet-stream | |
| - name: Upload macOS x86_64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-x86_64-macos/sql-schema-x86_64-macos | |
| asset_name: sql-schema-x86_64-macos | |
| asset_content_type: application/octet-stream | |
| - name: Upload macOS aarch64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-aarch64-macos/sql-schema-aarch64-macos | |
| asset_name: sql-schema-aarch64-macos | |
| asset_content_type: application/octet-stream | |
| - name: Upload Windows x86_64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-x86_64-windows.exe/sql-schema-x86_64-windows.exe | |
| asset_name: sql-schema-x86_64-windows.exe | |
| asset_content_type: application/octet-stream | |
| - name: Upload Windows aarch64 binary | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./binaries/sql-schema-aarch64-windows.exe/sql-schema-aarch64-windows.exe | |
| asset_name: sql-schema-aarch64-windows.exe | |
| asset_content_type: application/octet-stream | |
| publish-crate: | |
| name: Publish to crates.io | |
| needs: [setup, create-release] | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| id-token: write # Required for OIDC token exchange with crates.io | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref }} | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Get Cargo version for checking | |
| run: | | |
| CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2) | |
| echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_ENV | |
| - name: Authenticate with crates.io | |
| uses: rust-lang/crates-io-auth-action@v1 | |
| id: auth | |
| - name: Publish to crates.io | |
| run: | | |
| # Try to publish, but don't fail if the version already exists | |
| OUTPUT=$(cargo publish --verbose 2>&1) && echo "$OUTPUT" || { | |
| EXIT_CODE=$? | |
| echo "$OUTPUT" | |
| # Check if it failed because the version already exists | |
| if echo "$OUTPUT" | grep -q "already exists on crates.io"; then | |
| echo "✅ Version $CARGO_VERSION already published on crates.io, skipping..." | |
| exit 0 | |
| fi | |
| # If it failed for another reason, exit with the original error code | |
| echo "❌ Publishing failed with error code $EXIT_CODE" | |
| exit $EXIT_CODE | |
| } | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} |