Merge pull request #18 from MickeyPvX/chore/tidy-up #8
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: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # Triggers on tags like v1.0.0, v1.1.0, etc. | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| validate-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Validate tag matches Cargo.toml version | |
| run: | | |
| # Extract version from Cargo.toml | |
| CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') | |
| # Extract version from git tag (remove 'v' prefix) | |
| TAG_VERSION=${GITHUB_REF_NAME#v} | |
| echo "Cargo.toml version: $CARGO_VERSION" | |
| echo "Git tag version: $TAG_VERSION" | |
| if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then | |
| echo "❌ Version mismatch!" | |
| echo "Cargo.toml version: $CARGO_VERSION" | |
| echo "Git tag version: $TAG_VERSION" | |
| exit 1 | |
| fi | |
| echo "✅ Versions match!" | |
| create-release: | |
| needs: validate-version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_id: ${{ steps.create_release.outputs.result }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const { data } = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: context.ref.replace('refs/tags/', ''), | |
| name: `Release ${context.ref.replace('refs/tags/', '')}`, | |
| body: `## Changes in ${context.ref.replace('refs/tags/', '')} | |
| See [CHANGELOG.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/${context.ref.replace('refs/tags/', '')}/CHANGELOG.md) for details. | |
| ## Installation | |
| Download the appropriate binary for your platform below, or build from source: | |
| \`\`\`bash | |
| cargo install --git https://github.com/${context.repo.owner}/${context.repo.repo} --tag ${context.ref.replace('refs/tags/', '')} | |
| \`\`\``, | |
| draft: false, | |
| prerelease: false | |
| }); | |
| return data.id; | |
| build-and-upload: | |
| needs: create-release | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: espn-ffl-linux-x86_64 | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| name: espn-ffl-macos-x86_64 | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| name: espn-ffl-macos-aarch64 | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| name: espn-ffl-windows-x86_64.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Cache cargo dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Build binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Prepare binary (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| cp target/${{ matrix.target }}/release/espn-ffl ${{ matrix.name }} | |
| chmod +x ${{ matrix.name }} | |
| - name: Prepare binary (Windows) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| cp target/${{ matrix.target }}/release/espn-ffl.exe ${{ matrix.name }} | |
| - name: Upload binary | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| await github.rest.repos.uploadReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: ${{ needs.create-release.outputs.release_id }}, | |
| name: '${{ matrix.name }}', | |
| data: fs.readFileSync('${{ matrix.name }}') | |
| }); |