|
| 1 | +name: Pin artifacts |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Generate static binaries"] |
| 5 | + types: ["completed"] |
| 6 | + |
| 7 | +jobs: |
| 8 | + # Make artifacts links more visible for the upstream project |
| 9 | + pin-artifacts: |
| 10 | + permissions: |
| 11 | + statuses: write |
| 12 | + name: Add artifacts links to commit statuses |
| 13 | + if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository == 'ocaml-sf/learn-ocaml' }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Add artifacts links to commit status |
| 17 | + run: | |
| 18 | + set -x |
| 19 | + workflow_id=${{ github.event.workflow_run.workflow_id }} |
| 20 | + run_id=${{ github.event.workflow_run.id }} # instead of ${{ github.run_id }} |
| 21 | + run_number=${{ github.event.workflow_run.run_number }} |
| 22 | + head_branch=${{ github.event.workflow_run.head_branch }} |
| 23 | + head_sha=${{ github.event.workflow_run.head_sha }} # instead of ${{ github.event.pull_request.head.sha }} (or ${{ github.sha }}) |
| 24 | + check_suite_id=${{ github.event.workflow_run.check_suite_id }} |
| 25 | + set +x |
| 26 | +
|
| 27 | + curl \ |
| 28 | + -H "Accept: application/vnd.github+json" \ |
| 29 | + "https://api.github.com/repos/${{ github.repository }}/actions/runs/${run_id}/artifacts" \ |
| 30 | + | jq '[.artifacts | .[] | {"id": .id, "name": .name, "created_at": .created_at, "expires_at": .expires_at, "archive_download_url": .archive_download_url}] | sort_by(.name)' \ |
| 31 | + > artifacts.json |
| 32 | +
|
| 33 | + cat artifacts.json |
| 34 | +
|
| 35 | + < artifacts.json jq -r ".[] | \ |
| 36 | + .name + \"§\" + \ |
| 37 | + ( .id | tostring | \"https://github.com/${{ github.repository }}/suites/${check_suite_id}/artifacts/\" + . ) + \"§\" + \ |
| 38 | + ( \"Link to \" + .name + \".zip [\" + ( .created_at | sub(\"T.*\"; \"→\") ) + ( .expires_at | sub(\"T.*\"; \"] (you must be logged)\" ) ) )" \ |
| 39 | + | while IFS="§" read name url descr; do |
| 40 | + curl \ |
| 41 | + -X POST \ |
| 42 | + -H "Accept: application/vnd.github+json" \ |
| 43 | + -H "Authorization: Bearer ${{ github.token }}" \ |
| 44 | + "https://api.github.com/repos/${{ github.repository }}/statuses/${head_sha}" \ |
| 45 | + -d "$( printf '{"state":"%s","target_url":"%s","description":"%s","context":"%s"}' "${{ github.event.workflow_run.conclusion }}" "$url" "$descr" "$name (artifact)" )" |
| 46 | + done |
0 commit comments