|
| 1 | +name: Build DEB for latest Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created] # Only run on latest manual release |
| 6 | + workflow_dispatch: # Enable manual runs to edit existing releases |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + pull_request: |
| 10 | + branches: [main] |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build DEB |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout Code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Rust |
| 22 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 23 | + |
| 24 | + - name: Install Tools |
| 25 | + run: | |
| 26 | + sudo apt-get update |
| 27 | + sudo apt-get install -y build-essential |
| 28 | + cargo install cargo-deb |
| 29 | +
|
| 30 | + - name: Build .deb package |
| 31 | + run: cargo deb |
| 32 | + |
| 33 | + - name: Get latest release tag |
| 34 | + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' |
| 35 | + id: get_tag |
| 36 | + uses: actions/github-script@v7 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const { repo, owner } = context.repo; |
| 40 | + let tag; |
| 41 | + if (github.event_name === 'release') { |
| 42 | + tag = github.event.release.tag_name; |
| 43 | + } else { |
| 44 | + const latest = await github.rest.repos.getLatestRelease({ owner, repo }); |
| 45 | + tag = latest.data.tag_name; |
| 46 | + } |
| 47 | + return tag; |
| 48 | + result-encoding: string |
| 49 | + |
| 50 | + # Avoid building on a non-tagged commit |
| 51 | + - name: Check tag commit matches current commit |
| 52 | + if: github.event_name == 'workflow_dispatch' |
| 53 | + id: verify_commit |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const { repo, owner } = context.repo; |
| 58 | + const tag = '${{ steps.get_tag.result }}'; |
| 59 | + const tagData = await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` }); |
| 60 | + const tagSha = tagData.data.object.sha; |
| 61 | +
|
| 62 | + const headSha = process.env.GITHUB_SHA; |
| 63 | +
|
| 64 | + if (tagSha !== headSha) { |
| 65 | + core.setFailed(`Error: Tag ${tag} points to ${tagSha}, but current commit is ${headSha}`); |
| 66 | + } |
| 67 | +
|
| 68 | + - name: Upload release assets |
| 69 | + # Only run on release or manual dispatch |
| 70 | + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' |
| 71 | + uses: softprops/action-gh-release@v2 |
| 72 | + with: |
| 73 | + tag_name: ${{ steps.get_tag.result }} |
| 74 | + files: | |
| 75 | + target/debian/*.deb |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments