|
| 1 | +name: Package (Docker + .deb) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + paths: |
| 7 | + - 'release-manager/**' |
| 8 | + - 'mina-bench-upload/**' |
| 9 | + - 'buildkite-cache-manager/**' |
| 10 | + - 'packaging/**' |
| 11 | + - '.github/workflows/package.yml' |
| 12 | + tags: |
| 13 | + - 'v*' |
| 14 | + pull_request: |
| 15 | + branches: [ main ] |
| 16 | + paths: |
| 17 | + - 'release-manager/**' |
| 18 | + - 'mina-bench-upload/**' |
| 19 | + - 'buildkite-cache-manager/**' |
| 20 | + - 'packaging/**' |
| 21 | + - '.github/workflows/package.yml' |
| 22 | + |
| 23 | +env: |
| 24 | + REGISTRY: ghcr.io |
| 25 | + IMAGE_NAME: ${{ github.repository_owner }}/mina-release-toolkit |
| 26 | + |
| 27 | +concurrency: |
| 28 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 29 | + cancel-in-progress: true |
| 30 | + |
| 31 | +jobs: |
| 32 | + # --------------------------------------------------------------------------- |
| 33 | + # Docker image. Builds on every PR (for sanity); only pushes to GHCR on |
| 34 | + # main / develop / tag. |
| 35 | + # --------------------------------------------------------------------------- |
| 36 | + docker: |
| 37 | + name: Docker image |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + contents: read |
| 41 | + packages: write |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + submodules: recursive |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@v3 |
| 50 | + |
| 51 | + - name: Compute image tags |
| 52 | + id: tags |
| 53 | + uses: docker/metadata-action@v5 |
| 54 | + with: |
| 55 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 56 | + tags: | |
| 57 | + type=ref,event=branch |
| 58 | + type=ref,event=pr |
| 59 | + type=semver,pattern={{version}} |
| 60 | + type=semver,pattern={{major}}.{{minor}} |
| 61 | + type=raw,value=latest,enable={{is_default_branch}} |
| 62 | +
|
| 63 | + - name: Log in to GHCR |
| 64 | + if: github.event_name != 'pull_request' |
| 65 | + uses: docker/login-action@v3 |
| 66 | + with: |
| 67 | + registry: ${{ env.REGISTRY }} |
| 68 | + username: ${{ github.actor }} |
| 69 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Build (and push on non-PR) |
| 72 | + uses: docker/build-push-action@v5 |
| 73 | + with: |
| 74 | + context: . |
| 75 | + file: packaging/Dockerfile |
| 76 | + push: ${{ github.event_name != 'pull_request' }} |
| 77 | + tags: ${{ steps.tags.outputs.tags }} |
| 78 | + labels: ${{ steps.tags.outputs.labels }} |
| 79 | + cache-from: type=gha |
| 80 | + cache-to: type=gha,mode=max |
| 81 | + |
| 82 | + # --------------------------------------------------------------------------- |
| 83 | + # Debian package. Builds the four Rust binaries natively, then invokes |
| 84 | + # deb-toolkit to assemble them into a single .deb. Uploads as a workflow |
| 85 | + # artifact always; attaches to GitHub Release on tag push. |
| 86 | + # --------------------------------------------------------------------------- |
| 87 | + deb: |
| 88 | + name: Debian package |
| 89 | + runs-on: ubuntu-latest |
| 90 | + permissions: |
| 91 | + contents: write # for attaching to releases |
| 92 | + steps: |
| 93 | + - name: Checkout |
| 94 | + uses: actions/checkout@v4 |
| 95 | + with: |
| 96 | + submodules: recursive |
| 97 | + |
| 98 | + - name: Install Rust |
| 99 | + uses: dtolnay/rust-toolchain@stable |
| 100 | + |
| 101 | + - name: Cache cargo |
| 102 | + uses: Swatinem/rust-cache@v2 |
| 103 | + with: |
| 104 | + key: package-deb |
| 105 | + |
| 106 | + - name: Install Debian build tools |
| 107 | + run: | |
| 108 | + sudo apt-get update |
| 109 | + sudo apt-get install -y --no-install-recommends \ |
| 110 | + fakeroot dpkg-dev build-essential pkg-config libssl-dev |
| 111 | +
|
| 112 | + - name: Compute version |
| 113 | + id: ver |
| 114 | + run: | |
| 115 | + if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then |
| 116 | + # Strip the leading `v` from the tag (`v1.2.3` → `1.2.3`). |
| 117 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 118 | + else |
| 119 | + # For untagged builds: 0.0.0+<short-sha> so the artifact |
| 120 | + # still has a valid Debian version string. |
| 121 | + VERSION="0.0.0+$(git rev-parse --short HEAD)" |
| 122 | + fi |
| 123 | + echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" |
| 124 | +
|
| 125 | + - name: Build all four binaries |
| 126 | + # The three in-tree crates ship a committed Cargo.lock and |
| 127 | + # build with `--locked`. The deb-toolkit submodule's upstream |
| 128 | + # gitignores its lock so we let cargo resolve fresh for that |
| 129 | + # one — `--locked` would fail with "cannot create the lock |
| 130 | + # file because --locked was passed". |
| 131 | + run: | |
| 132 | + (cd release-manager && cargo build --release --locked) |
| 133 | + (cd mina-bench-upload && cargo build --release --locked) |
| 134 | + (cd buildkite-cache-manager && cargo build --release --locked) |
| 135 | + (cd deb-toolkit && cargo build --release) |
| 136 | +
|
| 137 | + - name: Assemble .deb via deb-toolkit |
| 138 | + run: packaging/build-deb.sh "${{ steps.ver.outputs.version }}" ./out |
| 139 | + |
| 140 | + - name: Verify the produced .deb |
| 141 | + run: | |
| 142 | + ls -la ./out |
| 143 | + dpkg-deb --info ./out/mina-release-toolkit_${{ steps.ver.outputs.version }}_amd64.deb |
| 144 | + dpkg-deb -c ./out/mina-release-toolkit_${{ steps.ver.outputs.version }}_amd64.deb |
| 145 | +
|
| 146 | + - name: Upload as workflow artifact |
| 147 | + uses: actions/upload-artifact@v4 |
| 148 | + with: |
| 149 | + name: mina-release-toolkit_${{ steps.ver.outputs.version }}_amd64.deb |
| 150 | + path: out/mina-release-toolkit_${{ steps.ver.outputs.version }}_amd64.deb |
| 151 | + if-no-files-found: error |
| 152 | + |
| 153 | + - name: Attach to GitHub Release (tag push only) |
| 154 | + if: startsWith(github.ref, 'refs/tags/v') |
| 155 | + uses: softprops/action-gh-release@v2 |
| 156 | + with: |
| 157 | + files: out/mina-release-toolkit_${{ steps.ver.outputs.version }}_amd64.deb |
0 commit comments