Skip to content

Commit 3a0620a

Browse files
klardotshalexmv
authored andcommitted
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.
1 parent 5f2e895 commit 3a0620a

File tree

5 files changed

+90
-35
lines changed

5 files changed

+90
-35
lines changed

.github/workflows/production-suite.yml

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
# the top explain how to build and upload these images.
4848
# Ubuntu 20.04 ships with Python 3.8.10.
4949
container: zulip/ci:focal
50+
5051
steps:
5152
- name: Add required permissions
5253
run: |
@@ -103,11 +104,22 @@ jobs:
103104
path: /tmp/production-build
104105
retention-days: 14
105106

106-
- name: Report status
107-
if: failure()
108-
env:
109-
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }}
110-
run: tools/ci/send-failure-message
107+
- name: Generate failure report string
108+
id: failure_report_string
109+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
110+
run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
111+
112+
- name: Report status to CZO
113+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
114+
uses: zulip/github-actions-zulip/send-message@v1
115+
with:
116+
api-key: ${{ secrets.ZULIP_BOT_KEY }}
117+
118+
organization-url: "https://chat.zulip.org"
119+
to: "automated testing"
120+
topic: ${{ steps.failure_report_string.outputs.topic }}
121+
type: "stream"
122+
content: ${{ steps.failure_report_string.outputs.content }}
111123

112124
production_install:
113125
# This job installs the server release tarball built above on a
@@ -160,7 +172,7 @@ jobs:
160172
chmod +x /tmp/production-pgroonga
161173
chmod +x /tmp/production-install
162174
chmod +x /tmp/production-verify
163-
chmod +x /tmp/send-failure-message
175+
chmod +x /tmp/generate-failure-message
164176
165177
- name: Create cache directories
166178
run: |
@@ -197,11 +209,22 @@ jobs:
197209
if: ${{ matrix.os == 'focal' }}
198210
run: sudo /tmp/production-verify ${{ matrix.extra-args }}
199211

200-
- name: Report status
201-
if: failure()
202-
env:
203-
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }}
204-
run: /tmp/send-failure-message
212+
- name: Generate failure report string
213+
id: failure_report_string
214+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
215+
run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
216+
217+
- name: Report status to CZO
218+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
219+
uses: zulip/github-actions-zulip/send-message@v1
220+
with:
221+
api-key: ${{ secrets.ZULIP_BOT_KEY }}
222+
223+
organization-url: "https://chat.zulip.org"
224+
to: "automated testing"
225+
topic: ${{ steps.failure_report_string.outputs.topic }}
226+
type: "stream"
227+
content: ${{ steps.failure_report_string.outputs.content }}
205228

206229
production_upgrade:
207230
# The production upgrade job starts with a container with a
@@ -254,7 +277,7 @@ jobs:
254277
# of the tarball uploaded by the upload artifact fix those.
255278
chmod +x /tmp/production-upgrade
256279
chmod +x /tmp/production-verify
257-
chmod +x /tmp/send-failure-message
280+
chmod +x /tmp/generate-failure-message
258281
259282
- name: Create cache directories
260283
run: |
@@ -271,8 +294,19 @@ jobs:
271294
# - name: Verify install
272295
# run: sudo /tmp/production-verify
273296

274-
- name: Report status
275-
if: failure()
276-
env:
277-
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }}
278-
run: /tmp/send-failure-message
297+
- name: Generate failure report string
298+
id: failure_report_string
299+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
300+
run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
301+
302+
- name: Report status to CZO
303+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
304+
uses: zulip/github-actions-zulip/send-message@v1
305+
with:
306+
api-key: ${{ secrets.ZULIP_BOT_KEY }}
307+
308+
organization-url: "https://chat.zulip.org"
309+
to: "automated testing"
310+
topic: ${{ steps.failure_report_string.outputs.topic }}
311+
type: "stream"
312+
content: ${{ steps.failure_report_string.outputs.content }}

.github/workflows/zulip-ci.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,19 @@ jobs:
233233
- name: Check development database build
234234
run: ./tools/ci/setup-backend
235235

236-
- name: Report status
237-
if: failure()
238-
env:
239-
ZULIP_BOT_KEY: ${{ secrets.ZULIP_BOT_KEY }}
240-
run: tools/ci/send-failure-message
236+
- name: Generate failure report string
237+
id: failure_report_string
238+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
239+
run: tools/ci/generate-failure-message >> $GITHUB_OUTPUT
240+
241+
- name: Report status to CZO
242+
if: ${{ failure() && github.repository == 'zulip/zulip' }}
243+
uses: zulip/github-actions-zulip/send-message@v1
244+
with:
245+
api-key: ${{ secrets.ZULIP_BOT_KEY }}
246+
247+
organization-url: "https://chat.zulip.org"
248+
to: "automated testing"
249+
topic: ${{ steps.failure_report_string.outputs.topic }}
250+
type: "stream"
251+
content: ${{ steps.failure_report_string.outputs.content }}

tools/ci/generate-failure-message

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
5+
6+
def get_build_url_from_environment() -> str:
7+
server = os.environ["GITHUB_SERVER_URL"]
8+
repo = os.environ["GITHUB_REPOSITORY"]
9+
run_id = os.environ["GITHUB_RUN_ID"]
10+
return f"{server}/{repo}/actions/runs/{run_id}"
11+
12+
13+
if __name__ == "__main__":
14+
branch = os.environ.get("GITHUB_REF", "unknown branch").split("/")[-1]
15+
topic = f"{branch} failing"
16+
build_url = get_build_url_from_environment()
17+
github_actor = os.environ.get("GITHUB_ACTOR", "unknown user")
18+
content = f"[Build]({build_url}) triggered by {github_actor} on branch `{branch}` has failed."
19+
20+
# Output in the key-value pair format GitHub Actions outputs are expected
21+
# to be in.
22+
print(f"topic={topic}\ncontent={content}")

tools/ci/production-build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ cp -a \
3939
tools/ci/production-upgrade \
4040
tools/ci/production-pgroonga \
4141
tools/ci/production-upgrade-pg \
42-
tools/ci/send-failure-message \
42+
tools/ci/generate-failure-message \
4343
package.json yarn.lock \
4444
/tmp/production-build
4545

tools/ci/send-failure-message

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)