|
| 1 | +name: Deterministic Docker Builds |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + # for now don't run on every change |
| 7 | + # - 'crates/**' |
| 8 | + - 'docker/hashi/**' |
| 9 | + - 'docker/hashi-screener/**' |
| 10 | + - 'Cargo.toml' |
| 11 | + - 'Cargo.lock' |
| 12 | + - '.github/workflows/deterministic-build.yml' |
| 13 | + workflow_dispatch: |
| 14 | + schedule: [cron: "20 3 * * *"] |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + image: [hashi, hashi-screener] |
| 25 | + os: [ubuntu-latest, ubuntu-22.04] |
| 26 | + runs-on: ${{ matrix.os }} |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Build ${{ matrix.image }} image |
| 32 | + env: |
| 33 | + GIT_REVISION: ${{ github.sha }} |
| 34 | + IMAGE_NAME: ${{ matrix.image }} |
| 35 | + run: bash docker/${{ matrix.image }}/build.sh --no-cache |
| 36 | + |
| 37 | + - name: Compute sha256 |
| 38 | + id: hash |
| 39 | + run: | |
| 40 | + BIN="out/${{ matrix.image }}" |
| 41 | + HASH=$(sha256sum "${BIN}" | awk '{print $1}') |
| 42 | + echo "sha256=${HASH}" >> "$GITHUB_OUTPUT" |
| 43 | + echo "${HASH} ${{ matrix.image }}" > "out/${{ matrix.image }}.sha256" |
| 44 | +
|
| 45 | + - name: Upload sha256 |
| 46 | + uses: actions/upload-artifact@v4 |
| 47 | + with: |
| 48 | + name: ${{ matrix.image }}-${{ matrix.os }}-sha256 |
| 49 | + path: out/${{ matrix.image }}.sha256 |
| 50 | + |
| 51 | + - name: Upload binary |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: ${{ matrix.image }}-${{ matrix.os }}-binary |
| 55 | + path: out/${{ matrix.image }} |
| 56 | + |
| 57 | + verify: |
| 58 | + needs: build |
| 59 | + runs-on: ubuntu-latest |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + image: [hashi, hashi-screener] |
| 64 | + steps: |
| 65 | + - name: Download ubuntu-latest hash |
| 66 | + uses: actions/download-artifact@v4 |
| 67 | + with: |
| 68 | + name: ${{ matrix.image }}-ubuntu-latest-sha256 |
| 69 | + path: hash-latest |
| 70 | + |
| 71 | + - name: Download ubuntu-22.04 hash |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + name: ${{ matrix.image }}-ubuntu-22.04-sha256 |
| 75 | + path: hash-22 |
| 76 | + |
| 77 | + - name: Compare hashes |
| 78 | + id: compare |
| 79 | + run: | |
| 80 | + LATEST=$(awk '{print $1}' "hash-latest/${{ matrix.image }}.sha256") |
| 81 | + OLDER=$(awk '{print $1}' "hash-22/${{ matrix.image }}.sha256") |
| 82 | + echo "latest=${LATEST}" >> "$GITHUB_OUTPUT" |
| 83 | + echo "older=${OLDER}" >> "$GITHUB_OUTPUT" |
| 84 | + if [ "${LATEST}" = "${OLDER}" ]; then |
| 85 | + echo "match=true" >> "$GITHUB_OUTPUT" |
| 86 | + else |
| 87 | + echo "match=false" >> "$GITHUB_OUTPUT" |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Write summary |
| 91 | + run: | |
| 92 | + { |
| 93 | + echo "## ${{ matrix.image }} reproducibility" |
| 94 | + echo "" |
| 95 | + echo "| Runner | SHA-256 |" |
| 96 | + echo "|--------|---------|" |
| 97 | + echo "| ubuntu-latest | \`${{ steps.compare.outputs.latest }}\` |" |
| 98 | + echo "| ubuntu-22.04 | \`${{ steps.compare.outputs.older }}\` |" |
| 99 | + echo "" |
| 100 | + echo "**Result**: ${{ steps.compare.outputs.match == 'true' && 'Reproducible' || 'MISMATCH' }}" |
| 101 | + } >> "$GITHUB_STEP_SUMMARY" |
| 102 | +
|
| 103 | + - name: Fail if hashes differ |
| 104 | + if: steps.compare.outputs.match != 'true' |
| 105 | + run: | |
| 106 | + echo "${{ matrix.image }} binary hashes differ across runners!" |
| 107 | + exit 1 |
0 commit comments