.github/workflows/pr_image_links.yml #15
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
--- | |
# Use the latest published version of the cirrus-ci_retrospective container | |
# to determine the execution context of _this_ workflow run. If it is a | |
# pull request, post the artifact URLs so it is easy to download and test. | |
on: | |
check_suite: # ALWAYS triggered from the default branch | |
# Ref: https://help.github.com/en/actions/reference/events-that-trigger-workflows#check-suite-event-check_suite | |
types: | |
- completed | |
jobs: | |
comment_image_id: | |
# Do not execute for other github applications, only works with cirrus-ci | |
if: github.event.check_suite.app.name == 'Cirrus CI' | |
runs-on: ubuntu-latest | |
env: | |
# This is the last component of the gist URL | |
# i.e. https://gist.github.com/<user>/<id> | |
built_images_gist_id: f505b6fb78db279855862e035629f8aa | |
steps: | |
- name: Execute latest upstream cirrus-ci_retrospective | |
uses: docker://quay.io/libpod/cirrus-ci_retrospective:latest | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
# Writes $GITHUB_WORKSPACE/cirrus-ci_retrospective.json | |
- name: Debug cirrus-ci_retrospective JSON | |
run: jq --indent 4 --color-output . $GITHUB_WORKSPACE/cirrus-ci_retrospective.json | |
- name: Load JSON into github workflow output variables | |
id: retro | |
run: | | |
ccirjson=$GITHUB_WORKSPACE/cirrus-ci_retrospective.json | |
prn=$(jq --raw-output \ | |
'.[] | select(.name == "Total Success") | .build.pullRequest' \ | |
"$ccirjson") | |
bid=$(jq --raw-output \ | |
'.[] | select(.name == "Total Success") | .build.id' \ | |
"$ccirjson") | |
status=$(jq --raw-output \ | |
'.[] | select(.name == "Total Success") | .status' \ | |
"$ccirjson") | |
if [[ -n "$prn" ]] && \ | |
[[ "$prn" != "null" ]] && \ | |
[[ $prn -gt 0 ]] && \ | |
[[ "$status" == "COMPLETED" ]] | |
then | |
printf "prn=%s\n" "$prn" >> $GITHUB_OUTPUT | |
printf "bid=%s\n" "$bid" >> $GITHUB_OUTPUT | |
printf "is_pr=%s\n" "true" >> $GITHUB_OUTPUT | |
else | |
printf "prn=%s\n" "0" >> $GITHUB_OUTPUT | |
printf "bid=%s\n" "0" >> $GITHUB_OUTPUT | |
printf "is_pr=%s\n" "false" >> $GITHUB_OUTPUT | |
fi | |
- if: steps.retro.outputs.is_pr == 'true' | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- if: steps.retro.outputs.is_pr == 'true' | |
name: Print Artifacts output | |
id: artifact_output | |
run: ./contrib/cirrus/print-artifacts-urls.sh "${{ steps.retro.outputs.bid }}" | |
- if: steps.retro.outputs.is_pr == 'true' | |
name: Send GitHub PR comment | |
uses: thollander/actions-comment-pull-request@v3 | |
with: | |
pr-number: ${{ steps.retro.outputs.prn }} | |
# the tag causes it to replace the comment | |
comment-tag: artifacts | |
mode: recreate | |
message: ${{ steps.artifact_output.outputs.stdout }} |