|
| 1 | +name: Snapshot |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - CI |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +permissions: |
| 11 | + actions: read |
| 12 | + contents: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: snapshot |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + publish: |
| 20 | + name: Publish snapshot |
| 21 | + if: >- |
| 22 | + github.event.workflow_run.conclusion == 'success' && |
| 23 | + github.event.workflow_run.event == 'push' && |
| 24 | + github.event.workflow_run.head_branch == 'trunk' |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout tested commit |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Download build artifacts |
| 34 | + uses: actions/download-artifact@v4 |
| 35 | + with: |
| 36 | + name: release-artifacts |
| 37 | + path: out/release |
| 38 | + run-id: ${{ github.event.workflow_run.id }} |
| 39 | + github-token: ${{ github.token }} |
| 40 | + |
| 41 | + - name: Publish snapshot prerelease |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ github.token }} |
| 44 | + SNAPSHOT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 45 | + SNAPSHOT_RUN_URL: ${{ github.event.workflow_run.html_url }} |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | +
|
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 51 | + git tag -f snapshot "$SNAPSHOT_SHA" |
| 52 | + git push --force origin refs/tags/snapshot |
| 53 | +
|
| 54 | + cat > release-notes.md <<EOF |
| 55 | + Snapshot build for \`$SNAPSHOT_SHA\`. |
| 56 | +
|
| 57 | + CI run: $SNAPSHOT_RUN_URL |
| 58 | + EOF |
| 59 | +
|
| 60 | + if gh release view snapshot >/dev/null 2>&1; then |
| 61 | + gh release edit snapshot \ |
| 62 | + --title snapshot \ |
| 63 | + --notes-file release-notes.md \ |
| 64 | + --prerelease \ |
| 65 | + --latest=false |
| 66 | + else |
| 67 | + gh release create snapshot \ |
| 68 | + --title snapshot \ |
| 69 | + --notes-file release-notes.md \ |
| 70 | + --prerelease \ |
| 71 | + --latest=false \ |
| 72 | + --target "$SNAPSHOT_SHA" |
| 73 | + fi |
| 74 | +
|
| 75 | + gh release view snapshot --json assets --jq '.assets[].name' | |
| 76 | + xargs -r -n 1 gh release delete-asset snapshot -y |
| 77 | +
|
| 78 | + gh release upload snapshot out/release/* --clobber |
0 commit comments