|
| 1 | +name: Build Debian Packages |
| 2 | +description: Publishes Debian packages for the given git reference |
| 3 | +inputs: |
| 4 | + github_token: |
| 5 | + required: true |
| 6 | + description: GitHub token for authentication. |
| 7 | + gitref: |
| 8 | + required: true |
| 9 | + description: The git ref to build the packages from. |
| 10 | + arch: |
| 11 | + required: true |
| 12 | + description: Machine architecture to build packages for. |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - amd64 |
| 16 | + - arm64 |
| 17 | + crate: |
| 18 | + required: true |
| 19 | + description: Name of binary crate being packaged. |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - miden-node |
| 23 | + - miden-faucet |
| 24 | + - miden-remote-prover |
| 25 | + crate_dir: |
| 26 | + required: true |
| 27 | + description: Name of crate being packaged. |
| 28 | + type: choice |
| 29 | + options: |
| 30 | + - miden-node |
| 31 | + - miden-faucet |
| 32 | + - miden-remote-prover |
| 33 | + service: |
| 34 | + required: true |
| 35 | + description: The service to build the packages for. |
| 36 | + type: choice |
| 37 | + options: |
| 38 | + - miden-node |
| 39 | + - miden-faucet |
| 40 | + - miden-prover |
| 41 | + - miden-prover-proxy |
| 42 | + package: |
| 43 | + required: true |
| 44 | + description: Name of packaging directory. |
| 45 | + type: choice |
| 46 | + options: |
| 47 | + - node |
| 48 | + - faucet |
| 49 | + - prover |
| 50 | + - prover-proxy |
| 51 | + |
| 52 | +runs: |
| 53 | + using: "composite" |
| 54 | + steps: |
| 55 | + - name: Rust cache |
| 56 | + uses: Swatinem/rust-cache@v2 |
| 57 | + with: |
| 58 | + # Only update the cache on push onto the next branch. This strikes a nice balance between |
| 59 | + # cache hits and cache evictions (github has a 10GB cache limit). |
| 60 | + save-if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }} |
| 61 | + |
| 62 | + - name: Rust update |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + rustup update --no-self-update |
| 66 | +
|
| 67 | + - name: Identify target git SHA |
| 68 | + id: git-sha |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + if git show-ref -q --verify "refs/remotes/origin/${{ inputs.gitref }}" 2>/dev/null; then |
| 72 | + echo "sha=$(git show-ref --hash --verify 'refs/remotes/origin/${{ inputs.gitref }}')" >> $GITHUB_OUTPUT |
| 73 | + elif git show-ref -q --verify "refs/tags/${{ inputs.gitref }}" 2>/dev/null; then |
| 74 | + echo "sha=$(git show-ref --hash --verify 'refs/tags/${{ inputs.gitref }}')" >> $GITHUB_OUTPUT |
| 75 | + elif git rev-parse --verify "${{ inputs.gitref }}^{commit}" >/dev/null 2>&1; then |
| 76 | + echo "sha=$(git rev-parse --verify '${{ inputs.gitref }}^{commit}')" >> $GITHUB_OUTPUT |
| 77 | + else |
| 78 | + echo "::error::Unknown git reference type" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Create package directories |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + pkg=${{ inputs.service }} |
| 86 | + mkdir -p \ |
| 87 | + packaging/deb/$pkg/DEBIAN \ |
| 88 | + packaging/deb/$pkg/usr/bin \ |
| 89 | + packaging/deb/$pkg/lib/systemd/system \ |
| 90 | + packaging/deb/$pkg/opt/$pkg \ |
| 91 | + done |
| 92 | +
|
| 93 | + - name: Copy package install scripts |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + svc=${{ inputs.service }} |
| 97 | + pkg=${{ inputs.package }} |
| 98 | + crate=${{ inputs.crate_dir }} |
| 99 | + git show ${{ steps.git-sha.outputs.sha }}:bin/$crate/.env > packaging/deb/$svc/lib/systemd/system/$svc.env |
| 100 | + git show ${{ steps.git-sha.outputs.sha }}:packaging/$pkg/$svc.service > packaging/deb/$svc/lib/systemd/system/$svc.service |
| 101 | + git show ${{ steps.git-sha.outputs.sha }}:packaging/$pkg/postinst > packaging/deb/$svc/DEBIAN/postinst |
| 102 | + git show ${{ steps.git-sha.outputs.sha }}:packaging/$pkg/postrm > packaging/deb/$svc/DEBIAN/postrm |
| 103 | + chmod 0775 packaging/deb/$svc/DEBIAN/postinst |
| 104 | + chmod 0775 packaging/deb/$svc/DEBIAN/postrm |
| 105 | +
|
| 106 | + - name: Create control files |
| 107 | + shell: bash |
| 108 | + run: | |
| 109 | + # Map the architecture to the format required by Debian. |
| 110 | + # i.e. arm64 and amd64 instead of aarch64 and x86_64. |
| 111 | + arch=$(uname -m | sed "s/x86_64/amd64/" | sed "s/aarch64/arm64/") |
| 112 | + # Control file's version field must be x.y.z format so strip the rest. |
| 113 | + version=$(git describe --tags --abbrev=0 | sed 's/[^0-9.]//g' ) |
| 114 | +
|
| 115 | + pkg=${{ inputs.service }} |
| 116 | + cat > packaging/deb/$pkg/DEBIAN/control << EOF |
| 117 | + Package: $pkg |
| 118 | + Version: $version |
| 119 | + Section: base |
| 120 | + Priority: optional |
| 121 | + Architecture: $arch |
| 122 | + Maintainer: Miden <[email protected]> |
| 123 | + Description: $pkg binary package |
| 124 | + Homepage: https://miden.xyz |
| 125 | + Vcs-Git: [email protected]:0xMiden/miden-node.git |
| 126 | + Vcs-Browser: https://github.com/0xMiden/miden-node |
| 127 | + EOF |
| 128 | +
|
| 129 | + - name: Build binaries |
| 130 | + shell: bash |
| 131 | + env: |
| 132 | + repo-url: ${{ github.server_url }}/${{ github.repository }} |
| 133 | + run: | |
| 134 | + cargo install ${{ inputs.crate }} --root . --locked --git ${{ env.repo-url }} --rev ${{ steps.git-sha.outputs.sha }} |
| 135 | +
|
| 136 | + - name: Copy binary files |
| 137 | + shell: bash |
| 138 | + run: | |
| 139 | + pkg=${{ inputs.service }} |
| 140 | + bin=${{ inputs.crate }} |
| 141 | + cp -p ./bin/$bin packaging/deb/$pkg/usr/bin/ |
| 142 | +
|
| 143 | + - name: Build packages |
| 144 | + shell: bash |
| 145 | + run: | |
| 146 | + dpkg-deb --build --root-owner-group packaging/deb/${{ inputs.service }} |
| 147 | +
|
| 148 | + # Save the .deb files, delete the rest. |
| 149 | + mv packaging/deb/*.deb . |
| 150 | + rm -rf packaging |
| 151 | +
|
| 152 | + - name: Package names |
| 153 | + shell: bash |
| 154 | + run: | |
| 155 | + echo "package=${{ inputs.service }}-${{ inputs.gitref }}-${{ inputs.arch }}.deb" >> $GITHUB_ENV |
| 156 | +
|
| 157 | + - name: Rename package files |
| 158 | + shell: bash |
| 159 | + run: | |
| 160 | + mv ${{ inputs.service }}.deb ${{ env.package }} |
| 161 | +
|
| 162 | + - name: shasum packages |
| 163 | + shell: bash |
| 164 | + run: | |
| 165 | + sha256sum ${{ env.package }} > ${{ env.package }}.checksum |
| 166 | +
|
| 167 | + - name: Publish packages |
| 168 | + shell: bash |
| 169 | + env: |
| 170 | + GH_TOKEN: ${{ inputs.github_token }} |
| 171 | + run: | |
| 172 | + gh release upload ${{ inputs.gitref }} \ |
| 173 | + ${{ env.package }} \ |
| 174 | + ${{ env.package }}.checksum \ |
| 175 | + --clobber |
0 commit comments