-
-
Notifications
You must be signed in to change notification settings - Fork 637
replace Imgur with GitHub Release Assets for screenshot hosting #3573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| name: Publish PR Screenshot | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Test"] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| publish: | ||
| if: > | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.repository == 'AppImage/appimage.github.io' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| pull-requests: write | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Extract PR number from event | ||
| id: extract-pr | ||
| shell: bash | ||
| run: | | ||
| PR_NUMBER=$(jq -r '.workflow_run.pull_requests[0].number // empty' "$GITHUB_EVENT_PATH") | ||
| echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV | ||
| echo "PR_NUMBER=${PR_NUMBER}" | ||
| echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT | ||
| - name: Download screenshot artifacts | ||
| uses: dawidd6/action-download-artifact@v2 | ||
| with: | ||
| run_id: ${{ github.event.workflow_run.id }} | ||
| name: pr-screenshots | ||
| path: ./out | ||
| if_no_artifact_found: ignore | ||
|
|
||
| - name: Prepare files | ||
| id: prep | ||
| shell: bash | ||
| run: | | ||
| set -e | ||
| mkdir -p upload | ||
| : > upload/list.txt | ||
| SHORT="${HEAD_SHA::8}" | ||
| COUNT=0 | ||
| FALLBACK="run-${{ github.event.workflow_run.id }}" | ||
| for f in out/*.png; do | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. screenshots are now extracted directly to out/ |
||
| [ -f "$f" ] || continue | ||
| base="$(basename "$f")" | ||
| appname="${base%.png}" # Remove .png extension to get app name | ||
| # Produce deterministic upload name with app name | ||
| PN="${PR_NUMBER:-$FALLBACK}" | ||
| name="pr-${PN}-${SHORT}-${appname}.png" | ||
| cp "$f" "upload/${name}" | ||
| echo "${name}" >> upload/list.txt | ||
| COUNT=$((COUNT+1)) | ||
| done | ||
| echo "COUNT=${COUNT}" >> $GITHUB_ENV | ||
| echo "count=${COUNT}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Ensure release exists (published) | ||
| shell: bash | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. publish release (not draft) so that URLs render as inline images in PR comments, not just clickable links |
||
| run: | | ||
| gh release view ci-screenshots >/dev/null 2>&1 || \ | ||
| gh release create ci-screenshots -t "CI Screenshots" -n "Automated screenshots from PRs" --prerelease | ||
| gh release edit ci-screenshots --draft=false | ||
|
|
||
| - name: Upload assets | ||
| if: ${{ steps.prep.outputs.count != '0' }} | ||
| shell: bash | ||
| run: | | ||
| while IFS= read -r name; do | ||
| gh release upload ci-screenshots "upload/${name}" --clobber | ||
| done < upload/list.txt | ||
|
|
||
| - name: Comment on PR with images | ||
| if: ${{ steps.prep.outputs.count != '0' && steps.extract-pr.outputs.pr_number != '' }} | ||
| shell: bash | ||
| run: | | ||
| repo="${{ github.repository }}" | ||
| { | ||
| echo "Automated screenshot(s) for PR #${PR_NUMBER} (commit ${HEAD_SHA}):" | ||
| echo "" | ||
| while IFS= read -r name; do | ||
| url="https://github.com/${repo}/releases/download/ci-screenshots/${name}" | ||
| echo "" | ||
| echo "" | ||
| done < upload/list.txt | ||
| } > comment.txt | ||
| gh api "repos/${repo}/issues/${PR_NUMBER}/comments" -F body=@comment.txt | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents workflow execution in forks - ensures releases and PR comments
are only created in the upstream repository.