|
| 1 | +name: CI-package-amd64-fedora44-clang |
| 2 | +run-name: '${{ github.ref_name }} ${{ github.workflow }} ${{ github.sha }}' |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.ref_name }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + init_release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + checks: write |
| 17 | + # No concurrency group: GitHub's "1 running + 1 pending" rule causes |
| 18 | + # mass cancellations when many workflows share a group. Instead we |
| 19 | + # run all init jobs in parallel and converge via a race-tolerant |
| 20 | + # find-or-create loop; all workers deterministically pick the |
| 21 | + # lowest-id draft matching this SHA+tag. |
| 22 | + outputs: |
| 23 | + release_id: ${{ steps.release.outputs.release_id }} |
| 24 | + release_name: ${{ steps.release.outputs.release_name }} |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + repository: ${{ github.repository }} |
| 30 | + ref: ${{ github.sha }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Find or create draft release |
| 34 | + id: release |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + run: | |
| 38 | + set -euo pipefail |
| 39 | + GIT_DESC=$(git describe --long --abbrev=7 --tags) |
| 40 | + TAG_NAME="${{ github.ref_name }}-head" |
| 41 | + RELEASE_NAME="${TAG_NAME} - ${GIT_DESC}" |
| 42 | + REPO="${{ github.repository }}" |
| 43 | + SHA="${{ github.sha }}" |
| 44 | + echo "Target: $RELEASE_NAME (sha $SHA)" |
| 45 | +
|
| 46 | + # Stagger start to reduce the thundering-herd on first create |
| 47 | + sleep $(( RANDOM % 10 )) |
| 48 | +
|
| 49 | + RELEASE_ID="" |
| 50 | + for attempt in 1 2 3 4 5 6; do |
| 51 | + IDS=$(gh api "repos/${REPO}/releases" --paginate \ |
| 52 | + --jq ".[] | select(.draft==true and .target_commitish==\"${SHA}\" and .tag_name==\"${TAG_NAME}\") | .id" \ |
| 53 | + | sort -n) |
| 54 | + if [ -n "$IDS" ]; then |
| 55 | + RELEASE_ID=$(echo "$IDS" | head -1) |
| 56 | + NDUPES=$(echo "$IDS" | wc -l) |
| 57 | + echo "attempt ${attempt}: found ${NDUPES} draft(s); using lowest id=${RELEASE_ID}" |
| 58 | + break |
| 59 | + fi |
| 60 | + echo "attempt ${attempt}: no matching draft; creating" |
| 61 | + gh api -X POST "repos/${REPO}/releases" \ |
| 62 | + -f tag_name="${TAG_NAME}" \ |
| 63 | + -f name="${RELEASE_NAME}" \ |
| 64 | + -f target_commitish="${SHA}" \ |
| 65 | + -F draft=true -F prerelease=true >/dev/null 2>&1 || true |
| 66 | + sleep $(( (RANDOM % 4) + 2 )) |
| 67 | + done |
| 68 | +
|
| 69 | + if [ -z "$RELEASE_ID" ]; then |
| 70 | + echo "ERROR: could not find or create draft release after retries" >&2 |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + echo "release_id=${RELEASE_ID}" >> "$GITHUB_OUTPUT" |
| 75 | + echo "release_name=${RELEASE_NAME}" >> "$GITHUB_OUTPUT" |
| 76 | +
|
| 77 | + build: |
| 78 | + needs: init_release |
| 79 | + runs-on: ubuntu-24.04 |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + checks: write |
| 83 | + env: |
| 84 | + ARCH: amd64 |
| 85 | + DIST: fedora44 |
| 86 | + MAKE_TARGET: fedora44-clang |
| 87 | + MATRIX: '(amd64,fedora44-clang)' |
| 88 | + BRANCH: ${{ github.ref_name }} |
| 89 | + RELEASE_ID: ${{ needs.init_release.outputs.release_id }} |
| 90 | + |
| 91 | + steps: |
| 92 | + - uses: LouisBrunner/checks-action@6b626ffbad7cc56fd58627f774b9067e6118af23 # v2.0.0 |
| 93 | + id: checks |
| 94 | + if: always() |
| 95 | + with: |
| 96 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + name: '${{ github.workflow }} / ${{ github.job }} ${{ env.MATRIX }}' |
| 98 | + repo: ${{ github.repository }} |
| 99 | + sha: ${{ github.sha }} |
| 100 | + status: 'in_progress' |
| 101 | + details_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' |
| 102 | + |
| 103 | + - name: Checkout repository |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + repository: ${{ github.repository }} |
| 107 | + ref: ${{ github.sha }} |
| 108 | + fetch-depth: 0 |
| 109 | + |
| 110 | + - name: Build package |
| 111 | + run: | |
| 112 | + make ${{ env.MAKE_TARGET }} |
| 113 | +
|
| 114 | + - name: Upload to release |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + run: | |
| 118 | + set -euo pipefail |
| 119 | + shopt -s nullglob |
| 120 | + uploaded=0 |
| 121 | + for f in binaries/*[mb] binaries/*.id-hash; do |
| 122 | + FNAME=$(basename "$f") |
| 123 | + EXISTING=$(gh api "repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \ |
| 124 | + --jq ".[] | select(.name==\"${FNAME}\") | .id" | head -1) |
| 125 | + if [ -n "$EXISTING" ]; then |
| 126 | + echo "Replacing existing asset ${FNAME} (id=${EXISTING})" |
| 127 | + gh api -X DELETE "repos/${{ github.repository }}/releases/assets/${EXISTING}" |
| 128 | + fi |
| 129 | + echo "Uploading ${FNAME}" |
| 130 | + gh api --method POST \ |
| 131 | + "https://uploads.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=${FNAME}" \ |
| 132 | + --header "Content-Type: application/octet-stream" \ |
| 133 | + --input "$f" |
| 134 | + uploaded=$((uploaded+1)) |
| 135 | + done |
| 136 | + if [ "$uploaded" -eq 0 ]; then |
| 137 | + echo "ERROR: no package files matched binaries/*[mb] or binaries/*.id-hash" >&2 |
| 138 | + ls -la binaries/ || true |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + echo "Uploaded $uploaded asset(s) to release id=${RELEASE_ID}" |
| 142 | +
|
| 143 | + - uses: LouisBrunner/checks-action@6b626ffbad7cc56fd58627f774b9067e6118af23 # v2.0.0 |
| 144 | + if: always() |
| 145 | + with: |
| 146 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + check_id: ${{ steps.checks.outputs.check_id }} |
| 148 | + repo: ${{ github.repository }} |
| 149 | + sha: ${{ github.sha }} |
| 150 | + conclusion: ${{ job.status }} |
| 151 | + details_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' |
0 commit comments