Skip to content
28 changes: 12 additions & 16 deletions .github/workflows/discord-posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
if: github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'master'
env:
CHECK_NAME: Internal Tests
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Set up GitHub CLI
Expand All @@ -21,31 +20,28 @@ jobs:
sudo apt-get update
sudo apt-get install -y gh

- name: Fetch Check Run Results
run: |
RESULT="$(gh pr checks "${{github.event.pull_request.html_url}}" --json 'workflow,state' |
jq -r ".[] | select(.workflow==\"${CHECK_NAME}\").state")"

if [ -z "$RESULT" ]; then
RESULT="The check did not run!"
fi

echo "CHECK_RESULT=${RESULT}" >> $GITHUB_ENV

- name: Send Discord notification
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
CHECK_RESULT: ${{ env.CHECK_RESULT }}
MENTION_ON_FAILURE: ${{ secrets.DEV_OPS_ROLE_ID }}
run: |
message="PR merged: [(#${PR_NUMBER}) ${PR_TITLE}](<${PR_URL}>)"
message+=$'\n'
message+="${CHECK_NAME} result: ${CHECK_RESULT}"
# Note that anything besides success is treated as a failure (e.g. if the check did not run at all, or if it is still pending).
if [[ "${CHECK_RESULT}" != "SUCCESS" ]]; then
FAILED_CHECKS="$(
gh pr checks "${{github.event.pull_request.html_url}}" \
--json 'workflow,state,name' |
jq '.[] | select(.state != "SUCCESS")' |
jq -r '"\(.workflow) / \(.name): \(.state)"'
)"
message+=$'\n'
if [[ -z "${FAILED_CHECKS}" ]]; then
message+='All checks passed.'
else
message+="${FAILED_CHECKS}"
message+=$'\n'
# This uses special Discord syntax for pinging a particular role.
# Note the '&' - this is the difference between pinging a *role* and pinging a *person*.
message+=" (cc <@&${MENTION_ON_FAILURE}>)"
Expand Down
Loading