| 1 | name: Debian Package Release |
| 2 | |
| 3 | on: |
| 4 | release: |
| 5 | types: [published] |
| 6 | workflow_dispatch: |
| 7 | inputs: |
| 8 | tag: |
| 9 | description: "Release tag (e.g. v0.1.0)" |
| 10 | required: true |
| 11 | |
| 12 | permissions: |
| 13 | contents: write |
| 14 | |
| 15 | env: |
| 16 | PROJECT_NAME: proses |
| 17 | CARGO_TERM_COLOR: always |
| 18 | |
| 19 | jobs: |
| 20 | build-deb: |
| 21 | name: Build .deb (${{ matrix.arch }}) |
| 22 | runs-on: ubuntu-latest |
| 23 | |
| 24 | strategy: |
| 25 | fail-fast: false |
| 26 | matrix: |
| 27 | include: |
| 28 | - arch: amd64 |
| 29 | target: x86_64-unknown-linux-gnu |
| 30 | cross-packages: "" |
| 31 | linker: "" |
| 32 | - arch: arm64 |
| 33 | target: aarch64-unknown-linux-gnu |
| 34 | cross-packages: "gcc-aarch64-linux-gnu" |
| 35 | linker: "aarch64-linux-gnu-gcc" |
| 36 | |
| 37 | steps: |
| 38 | - name: Resolve release tag |
| 39 | id: tag |
| 40 | shell: bash |
| 41 | run: | |
| 42 | if [[ "${{ github.event_name }}" == "release" ]]; then |
| 43 | TAG="${{ github.event.release.tag_name }}" |
| 44 | else |
| 45 | TAG="${{ github.event.inputs.tag }}" |
| 46 | fi |
| 47 | echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 48 | |
| 49 | - name: Checkout |
| 50 | uses: actions/checkout@v6 |
| 51 | with: |
| 52 | ref: ${{ steps.tag.outputs.tag }} |
| 53 | |
| 54 | - name: Install Rust toolchain |
| 55 | uses: dtolnay/rust-toolchain@stable |
| 56 | with: |
| 57 | targets: ${{ matrix.target }} |
| 58 | |
| 59 | - name: Install cross-compilation toolchain |
| 60 | if: matrix.cross-packages != '' |
| 61 | run: | |
| 62 | sudo apt-get update |
| 63 | sudo apt-get install -y ${{ matrix.cross-packages }} |
| 64 | |
| 65 | - name: Install cargo-deb |
| 66 | run: cargo install cargo-deb --locked |
| 67 | |
| 68 | - name: Setup Rust cache |
| 69 | uses: Swatinem/rust-cache@v2 |
| 70 | with: |
| 71 | key: deb-${{ matrix.target }} |
| 72 | |
| 73 | # Configure the cross-linker so Cargo can link arm64 binaries on an |
| 74 | # x86_64 host. This file is only written for cross-compilation jobs; |
| 75 | # native amd64 builds need no extra configuration. |
| 76 | - name: Configure cross-linker |
| 77 | if: matrix.linker != '' |
| 78 | shell: bash |
| 79 | run: | |
| 80 | mkdir -p .cargo |
| 81 | printf '[target.${{ matrix.target }}]\nlinker = "${{ matrix.linker }}"\n' >> .cargo/config.toml |
| 82 | |
| 83 | - name: Verify Cargo.toml version matches tag |
| 84 | shell: bash |
| 85 | run: | |
| 86 | CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 \ |
| 87 | | jq -r '.packages[] | select(.name == "proses") | .version') |
| 88 | TAG_VERSION="${{ steps.tag.outputs.tag }}" |
| 89 | TAG_VERSION="${TAG_VERSION#v}" |
| 90 | |
| 91 | echo "Cargo.toml version : ${CARGO_VERSION}" |
| 92 | echo "Release tag version: ${TAG_VERSION}" |
| 93 | |
| 94 | if [[ "${CARGO_VERSION}" != "${TAG_VERSION}" ]]; then |
| 95 | echo "::error::Version mismatch — bump version in Cargo.toml before releasing." |
| 96 | exit 1 |
| 97 | fi |
| 98 | |
| 99 | # cargo-deb compiles the binary and assembles the .deb in one step. |
| 100 | # For cross-compiled targets it automatically locates the |
| 101 | # target-prefixed strip (e.g. aarch64-linux-gnu-strip) that ships |
| 102 | # with the gcc-<arch>-linux-gnu package installed above. |
| 103 | - name: Build .deb package |
| 104 | shell: bash |
| 105 | run: cargo deb --target ${{ matrix.target }} --locked |
| 106 | |
| 107 | - name: Rename .deb with architecture suffix |
| 108 | id: deb |
| 109 | shell: bash |
| 110 | run: | |
| 111 | DEB_FILE=$(find "target/${{ matrix.target }}/debian" -name '*.deb' -print -quit) |
| 112 | |
| 113 | if [[ -z "${DEB_FILE}" ]]; then |
| 114 | echo "::error::No .deb file found in target/${{ matrix.target }}/debian/" |
| 115 | exit 1 |
| 116 | fi |
| 117 | |
| 118 | echo "path=${DEB_FILE}" >> "$GITHUB_OUTPUT" |
| 119 | echo "name=$(basename "${DEB_FILE}")" >> "$GITHUB_OUTPUT" |
| 120 | |
| 121 | - name: Inspect package |
| 122 | shell: bash |
| 123 | run: dpkg-deb --info "${{ steps.deb.outputs.path }}" |
| 124 | |
| 125 | - name: Upload artifact |
| 126 | uses: actions/upload-artifact@v4 |
| 127 | with: |
| 128 | name: deb-${{ matrix.arch }} |
| 129 | path: ${{ steps.deb.outputs.path }} |
| 130 | |
| 131 | - name: Attach to GitHub Release |
| 132 | uses: softprops/action-gh-release@v2 |
| 133 | with: |
| 134 | tag_name: ${{ steps.tag.outputs.tag }} |
| 135 | files: ${{ steps.deb.outputs.path }} |