Pin artifacts #385
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pin artifacts | |
on: | |
workflow_run: | |
workflows: ["Generate static binaries"] | |
types: ["completed"] | |
jobs: | |
# Make artifacts links more visible for the upstream project | |
pin-artifacts: | |
permissions: | |
statuses: write | |
name: Add artifacts links to commit statuses | |
if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository == 'ocaml-sf/learn-ocaml' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Add artifacts links to commit status | |
run: | | |
set -x | |
workflow_id=${{ github.event.workflow_run.workflow_id }} | |
run_id=${{ github.event.workflow_run.id }} # instead of ${{ github.run_id }} | |
run_number=${{ github.event.workflow_run.run_number }} | |
head_branch=${{ github.event.workflow_run.head_branch }} | |
head_sha=${{ github.event.workflow_run.head_sha }} # instead of ${{ github.event.pull_request.head.sha }} (or ${{ github.sha }}) | |
check_suite_id=${{ github.event.workflow_run.check_suite_id }} | |
set +x | |
curl \ | |
-H "Accept: application/vnd.github+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${run_id}/artifacts" \ | |
| jq '[.artifacts | .[] | {"id": .id, "name": .name, "created_at": .created_at, "expires_at": .expires_at, "archive_download_url": .archive_download_url}] | sort_by(.name)' \ | |
> artifacts.json | |
cat artifacts.json | |
< artifacts.json jq -r ".[] | \ | |
.name + \"§\" + \ | |
( .id | tostring | \"https://github.com/${{ github.repository }}/suites/${check_suite_id}/artifacts/\" + . ) + \"§\" + \ | |
( \"Link to \" + .name + \".zip [\" + ( .created_at | sub(\"T.*\"; \"→\") ) + ( .expires_at | sub(\"T.*\"; \"] (you must be logged)\" ) ) )" \ | |
| while IFS="§" read name url descr; do | |
curl \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ github.token }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/statuses/${head_sha}" \ | |
-d "$( printf '{"state":"%s","target_url":"%s","description":"%s","context":"%s"}' "${{ github.event.workflow_run.conclusion }}" "$url" "$descr" "$name (artifact)" )" | |
done |