Implement first-class migration versioning system #27
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: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Pre-install tsx for TypeScript tests | |
| run: npm install -g tsx | |
| - 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 | |
| outputs: | |
| version: ${{ steps.version-check.outputs.current }} | |
| changed: ${{ steps.version-check.outputs.changed }} | |
| tag_exists: ${{ steps.tag-check.outputs.exists }} | |
| 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: Create tag | |
| if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists != 'true' | |
| 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 }}" | |
| build-binaries: | |
| if: needs.release.outputs.changed == 'true' && needs.release.outputs.tag_exists != 'true' | |
| needs: release | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| runs-on: ${{ matrix.os }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools (Linux ARM) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Build | |
| shell: bash | |
| run: | | |
| if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then | |
| export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc | |
| fi | |
| cargo build --release --target ${{ matrix.target }} | |
| - name: Prepare binary (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| cp target/${{ matrix.target }}/release/migrate migrate-${{ matrix.target }} | |
| - name: Prepare binary (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| cp target/${{ matrix.target }}/release/migrate.exe migrate-${{ matrix.target }}.exe | |
| - name: Upload to release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.release.outputs.version }} | |
| files: migrate-${{ matrix.target }}* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |