tools: Reimplement CI failure script without using CircleCI endpoint.

Using curl to POST to the CircleCI workflow endpoint on CZO:

- Doesn't work on zulip/zulip@main (CZO runs a revert)
- Sets a bad example for other orgs
- Robs us of an opportunity to dogfood our own zulip/github-actions-zulip

Refactor the Actions workflows in this repo to report failure states
using the Zulip Action, and reimplement the related helper scripts in
Python, since they'd previously mostly shelled out to Python anyway.
This commit is contained in:
Josh Klar 2022-11-30 20:51:52 -08:00 committed by Alex Vandiver
parent 5f2e895c5e
commit 3a0620a40c
5 changed files with 90 additions and 35 deletions

View File

@ -47,6 +47,7 @@ jobs:
# the top explain how to build and upload these images. # the top explain how to build and upload these images.
# Ubuntu 20.04 ships with Python 3.8.10. # Ubuntu 20.04 ships with Python 3.8.10.
container: zulip/ci:focal container: zulip/ci:focal
steps: steps:
- name: Add required permissions - name: Add required permissions
run: | run: |
@ -103,11 +104,22 @@ jobs:
path: /tmp/production-build path: /tmp/production-build
retention-days: 14 retention-days: 14
- name: Report status - name: Generate failure report string
if: failure() id: failure_report_string
env: if: ${{ failure() && github.repository == 'zulip/zulip' }}
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }} run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
run: tools/ci/send-failure-message
- name: Report status to CZO
if: ${{ failure() && github.repository == 'zulip/zulip' }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_BOT_KEY }}
email: "github-actions-bot@chat.zulip.org"
organization-url: "https://chat.zulip.org"
to: "automated testing"
topic: ${{ steps.failure_report_string.outputs.topic }}
type: "stream"
content: ${{ steps.failure_report_string.outputs.content }}
production_install: production_install:
# This job installs the server release tarball built above on a # This job installs the server release tarball built above on a
@ -160,7 +172,7 @@ jobs:
chmod +x /tmp/production-pgroonga chmod +x /tmp/production-pgroonga
chmod +x /tmp/production-install chmod +x /tmp/production-install
chmod +x /tmp/production-verify chmod +x /tmp/production-verify
chmod +x /tmp/send-failure-message chmod +x /tmp/generate-failure-message
- name: Create cache directories - name: Create cache directories
run: | run: |
@ -197,11 +209,22 @@ jobs:
if: ${{ matrix.os == 'focal' }} if: ${{ matrix.os == 'focal' }}
run: sudo /tmp/production-verify ${{ matrix.extra-args }} run: sudo /tmp/production-verify ${{ matrix.extra-args }}
- name: Report status - name: Generate failure report string
if: failure() id: failure_report_string
env: if: ${{ failure() && github.repository == 'zulip/zulip' }}
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }} run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
run: /tmp/send-failure-message
- name: Report status to CZO
if: ${{ failure() && github.repository == 'zulip/zulip' }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_BOT_KEY }}
email: "github-actions-bot@chat.zulip.org"
organization-url: "https://chat.zulip.org"
to: "automated testing"
topic: ${{ steps.failure_report_string.outputs.topic }}
type: "stream"
content: ${{ steps.failure_report_string.outputs.content }}
production_upgrade: production_upgrade:
# The production upgrade job starts with a container with a # The production upgrade job starts with a container with a
@ -254,7 +277,7 @@ jobs:
# of the tarball uploaded by the upload artifact fix those. # of the tarball uploaded by the upload artifact fix those.
chmod +x /tmp/production-upgrade chmod +x /tmp/production-upgrade
chmod +x /tmp/production-verify chmod +x /tmp/production-verify
chmod +x /tmp/send-failure-message chmod +x /tmp/generate-failure-message
- name: Create cache directories - name: Create cache directories
run: | run: |
@ -271,8 +294,19 @@ jobs:
# - name: Verify install # - name: Verify install
# run: sudo /tmp/production-verify # run: sudo /tmp/production-verify
- name: Report status - name: Generate failure report string
if: failure() id: failure_report_string
env: if: ${{ failure() && github.repository == 'zulip/zulip' }}
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }} run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
run: /tmp/send-failure-message
- name: Report status to CZO
if: ${{ failure() && github.repository == 'zulip/zulip' }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_BOT_KEY }}
email: "github-actions-bot@chat.zulip.org"
organization-url: "https://chat.zulip.org"
to: "automated testing"
topic: ${{ steps.failure_report_string.outputs.topic }}
type: "stream"
content: ${{ steps.failure_report_string.outputs.content }}

View File

@ -233,8 +233,19 @@ jobs:
- name: Check development database build - name: Check development database build
run: ./tools/ci/setup-backend run: ./tools/ci/setup-backend
- name: Report status - name: Generate failure report string
if: failure() id: failure_report_string
env: if: ${{ failure() && github.repository == 'zulip/zulip' }}
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }} run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
run: tools/ci/send-failure-message
- name: Report status to CZO
if: ${{ failure() && github.repository == 'zulip/zulip' }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_BOT_KEY }}
email: "github-actions-bot@chat.zulip.org"
organization-url: "https://chat.zulip.org"
to: "automated testing"
topic: ${{ steps.failure_report_string.outputs.topic }}
type: "stream"
content: ${{ steps.failure_report_string.outputs.content }}

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
import os
def get_build_url_from_environment() -> str:
server = os.environ["GITHUB_SERVER_URL"]
repo = os.environ["GITHUB_REPOSITORY"]
run_id = os.environ["GITHUB_RUN_ID"]
return f"{server}/{repo}/actions/runs/{run_id}"
if __name__ == "__main__":
branch = os.environ.get("GITHUB_REF", "unknown branch").split("/")[-1]
topic = f"{branch} failing"
build_url = get_build_url_from_environment()
github_actor = os.environ.get("GITHUB_ACTOR", "unknown user")
content = f"[Build]({build_url}) triggered by {github_actor} on branch `{branch}` has failed."
# Output in the key-value pair format GitHub Actions outputs are expected
# to be in.
print(f"topic={topic}\ncontent={content}")

View File

@ -39,7 +39,7 @@ cp -a \
tools/ci/production-upgrade \ tools/ci/production-upgrade \
tools/ci/production-pgroonga \ tools/ci/production-pgroonga \
tools/ci/production-upgrade-pg \ tools/ci/production-upgrade-pg \
tools/ci/send-failure-message \ tools/ci/generate-failure-message \
package.json yarn.lock \ package.json yarn.lock \
/tmp/production-build /tmp/production-build

View File

@ -1,12 +0,0 @@
#!/usr/bin/env bash
set -e
set -x
if [[ "$ZULIP_BOT_KEY" != "" && "$GITHUB_REPOSITORY" == "zulip/zulip" ]]; then
BRANCH="$(python3 -c 'import sys; print(sys.argv[1].split("/")[-1])' "$GITHUB_REF")"
URI_ESCAPED_TOPIC="$(python3 -c 'import sys; import urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$BRANCH failing")"
curl -fL -H "Content-Type: application/json" \
-X POST -i 'https://chat.zulip.org/api/v1/external/circleci?api_key='"$ZULIP_BOT_KEY"'&stream=automated%20testing&topic='"$URI_ESCAPED_TOPIC" \
-d '{"payload": { "branch": "'"$BRANCH"'", "reponame": "'"$GITHUB_REPOSITORY"'", "status": "failed", "build_url": "'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'", "username": "'"$GITHUB_ACTOR"'"}}'
fi