Skip to content

.github/workflows/cirrus_status.yml #128

.github/workflows/cirrus_status.yml

.github/workflows/cirrus_status.yml #128

Workflow file for this run

---
# Use the latest published version of the cirrus-ci_retrospective container
# to determine the execution context of _this_ workflow run.
# Inspect the cirrus status so we can post comments on PRs for build to allow
# easy access to image downloads.
# For CI runs on the branches send an email notification when the build failed.
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:
cirrus_notification:
# 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
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")
branch=$(jq --raw-output \
'.[] | select(.name == "Total Success") | .build.branch' \
"$ccirjson")
if [[ -n "$prn" ]] && \
[[ "$prn" != "null" ]] && \
[[ $prn -gt 0 ]]
then
printf "prn=%s\n" "$prn" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "true" >> $GITHUB_OUTPUT
else
printf "prn=%s\n" "0" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "false" >> $GITHUB_OUTPUT
fi
printf "bid=%s\n" "$bid" >> $GITHUB_OUTPUT
printf "status=%s\n" "$status" >> $GITHUB_OUTPUT
printf "branch=%s\n" "$branch" >> $GITHUB_OUTPUT
- if: steps.retro.outputs.is_pr == 'true' && steps.retro.outputs.status == 'COMPLETED'
uses: actions/checkout@v4
with:
persist-credentials: false
- if: steps.retro.outputs.is_pr == 'true' && steps.retro.outputs.status == 'COMPLETED'
name: Print Artifacts output
id: artifact_output
run: |
echo 'comment<<EOF' >> $GITHUB_OUTPUT
./contrib/cirrus/print-artifacts-urls.sh "${{ steps.retro.outputs.bid }}" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- if: steps.retro.outputs.is_pr == 'true' && steps.retro.outputs.status == 'COMPLETED'
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.comment }}"
# Send mail on build failures that do not happen on PRs so we know if something fails.
- if: steps.retro.outputs.is_pr == 'false' && steps.retro.outputs.status != 'COMPLETED'
name: Email on build failures for branches
# Ref: https://github.com/dawidd6/action-send-mail
uses: dawidd6/action-send-mail@v3.12.0
with:
server_address: ${{secrets.ACTION_MAIL_SERVER}}
server_port: 465
username: ${{secrets.ACTION_MAIL_USERNAME}}
password: ${{secrets.ACTION_MAIL_PASSWORD}}
subject: Cirrus-CI build failures on ${{github.repository}}
to: "podman-monitor@lists.podman.io"
from: ${{secrets.ACTION_MAIL_SENDER}}
body: "podman-machine-os build failed on branch ${{ steps.retro.outputs.branch }}: https://cirrus-ci.com/build/${{ steps.retro.outputs.bid }}"