Skip to content

Commit

Permalink
Github Actions - Link Artifacts in PR comments; alternaive: PIN
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdCopter committed Feb 22, 2024
1 parent 24e13c5 commit 6c9a8fb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ jobs:
name: ${{ env.ARTIFACT_NAME }}
path: obj/*.hex

- name: Output artifact ID
run: |
echo 'Artifact ID is ${{ steps.artifact-upload.outputs.artifact-id }}'
echo 'Artifact URL is ${{ steps.artifact-upload.outputs.artifact-url }}'
artifacts:
if: github.event_name == 'pull_request'
needs: build
Expand All @@ -151,31 +146,13 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: false
steps:
# Hide existing/outdated artifacts links
- name: Hide artifacts links from comments.
uses: int128/hide-comment-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
authors: "github-actions"
contains: "Compiled HEX from this Pull-Request. WARNING: No warranty or guarantee of any kind. Test/Fly at your own risk!"
continue-on-error: true

# Add artifacts links
- name: Add artifacts link
uses: beni69/artifact-link@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

# Add artifacts links
- name: Add artifacts link too
uses: peter-evans/create-or-update-comment@v4
with:
body: |
Compiled HEX from this Pull-Request. WARNING: No warranty or guarantee of any kind. Test/Fly at your own risk!
${{ steps.artifact-upload.outputs.artifact-url }}
continue-on-error: true

releases:
if: startsWith(github.ref, 'refs/tags/')
needs: build
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/pin-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Pin artifacts
on:
workflow_run:
workflows: ["Build EmuFlight"]
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' }}
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

0 comments on commit 6c9a8fb

Please sign in to comment.