Skip to content

Commit 6c9a8fb

Browse files
committed
Github Actions - Link Artifacts in PR comments; alternaive: PIN
1 parent 24e13c5 commit 6c9a8fb

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ jobs:
138138
name: ${{ env.ARTIFACT_NAME }}
139139
path: obj/*.hex
140140

141-
- name: Output artifact ID
142-
run: |
143-
echo 'Artifact ID is ${{ steps.artifact-upload.outputs.artifact-id }}'
144-
echo 'Artifact URL is ${{ steps.artifact-upload.outputs.artifact-url }}'
145-
146141
artifacts:
147142
if: github.event_name == 'pull_request'
148143
needs: build
@@ -151,31 +146,13 @@ jobs:
151146
runs-on: ubuntu-latest
152147
continue-on-error: false
153148
steps:
154-
# Hide existing/outdated artifacts links
155-
- name: Hide artifacts links from comments.
156-
uses: int128/hide-comment-action@v1
157-
with:
158-
token: ${{ secrets.GITHUB_TOKEN }}
159-
authors: "github-actions"
160-
contains: "Compiled HEX from this Pull-Request. WARNING: No warranty or guarantee of any kind. Test/Fly at your own risk!"
161-
continue-on-error: true
162-
163149
# Add artifacts links
164150
- name: Add artifacts link
165151
uses: beni69/artifact-link@v1
166152
with:
167153
token: ${{ secrets.GITHUB_TOKEN }}
168154
continue-on-error: true
169155

170-
# Add artifacts links
171-
- name: Add artifacts link too
172-
uses: peter-evans/create-or-update-comment@v4
173-
with:
174-
body: |
175-
Compiled HEX from this Pull-Request. WARNING: No warranty or guarantee of any kind. Test/Fly at your own risk!
176-
${{ steps.artifact-upload.outputs.artifact-url }}
177-
continue-on-error: true
178-
179156
releases:
180157
if: startsWith(github.ref, 'refs/tags/')
181158
needs: build
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Pin artifacts
2+
on:
3+
workflow_run:
4+
workflows: ["Build EmuFlight"]
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' }}
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

Comments
 (0)