Skip to content

Commit 3a0fa0f

Browse files
authored
build: modify workflows for new CI slack bot (#1277)
* build: modify workflows for new CI slack bot
1 parent b2b2ddd commit 3a0fa0f

File tree

6 files changed

+148
-147
lines changed

6 files changed

+148
-147
lines changed

.github/parse-tests.js

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

.github/workflows/pr.yml

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
on: pull_request
22
name: pull_request
3+
34
jobs:
45
staticcheck:
56
runs-on: ubuntu-latest
@@ -36,11 +37,10 @@ jobs:
3637
args: -v --timeout=5m
3738

3839
test:
40+
needs: staticcheck
3941
runs-on: ubuntu-latest-128
4042
permissions:
4143
pull-requests: write
42-
outputs:
43-
failures: ${{ steps.generate-job-summary.outputs.failures }}
4444
steps:
4545
- name: checkout code
4646
uses: actions/checkout@v4
@@ -75,62 +75,18 @@ jobs:
7575
go test -json -v -p 4 -tags=prover_checks ./examples/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
7676
go test -json -v -run=NONE -fuzz=FuzzIntcomp -fuzztime=30s ./internal/backend/ioutils 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
7777
78-
- name: Generate job summary
79-
id: generate-job-summary
80-
if: ${{ always() }}
81-
run: |
82-
if [ -s /tmp/gotest.log ]; then
83-
cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY
84-
echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT
85-
else
86-
echo "## Success ✅" > $GITHUB_STEP_SUMMARY
87-
echo "failures=" > $GITHUB_OUTPUT
88-
fi
8978
90-
slack-workflow-status-failed:
91-
if: failure()
92-
name: post workflow status to slack
79+
slack-notifications:
80+
if: always()
81+
uses: ./.github/workflows/slack-notifications.yml
9382
needs:
94-
- staticcheck
9583
- test
96-
runs-on: ubuntu-latest
97-
steps:
98-
- name: Notify slack -- workflow failed
99-
id: slack
100-
uses: slackapi/[email protected]
101-
with:
102-
payload: |
103-
{
104-
"actor": "${{ github.actor }}",
105-
"repo": "${{ github.repository }}",
106-
"status": "FAIL",
107-
"title": "${{ github.event.pull_request.title }}",
108-
"pr": "${{ github.event.pull_request.head.ref }}",
109-
"failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/",
110-
"message": "${{ needs.test.outputs.failures }}"
111-
}
112-
env:
113-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
114-
115-
slack-workflow-status-success:
116-
if: success()
117-
name: post workflow status to slack
118-
needs:
11984
- staticcheck
120-
- test
121-
runs-on: ubuntu-latest
122-
steps:
123-
- name: Notify slack -- workflow succeeded
124-
id: slack
125-
uses: slackapi/[email protected]
126-
with:
127-
payload: |
128-
{
129-
"actor": "${{ github.actor }}",
130-
"repo": "${{ github.repository }}",
131-
"status": "SUCCESS",
132-
"title": "${{ github.event.pull_request.title }}",
133-
"pr": "${{ github.event.pull_request.head.ref }}"
134-
}
135-
env:
136-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_SUCCESS }}
85+
secrets:
86+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
87+
with:
88+
status: ${{ needs.staticcheck.result }}${{ needs.test.result }}
89+
actor: ${{ github.actor }}
90+
repository: ${{ github.repository }}
91+
branch: ${{ github.event.pull_request.head.ref }}
92+
run_id: ${{ github.run_id }}

.github/workflows/push.yml

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
branches:
44
- 'master'
55
name: push_master
6+
67
jobs:
78
staticcheck:
89
runs-on: ubuntu-latest
@@ -81,51 +82,18 @@ jobs:
8182
go test -v -p 4 -timeout=50m -tags=release_checks -short -race ./test/...
8283
go test -v -run=NONE -fuzz=FuzzIntcomp -fuzztime=30s ./internal/backend/ioutils
8384
84-
85-
slack-workflow-status-failed:
86-
if: failure()
87-
name: post workflow status to slack
88-
needs:
89-
- staticcheck
90-
- test
91-
runs-on: ubuntu-latest
92-
steps:
93-
- name: Notify slack -- workflow failed
94-
id: slack
95-
uses: slackapi/[email protected]
96-
with:
97-
payload: |
98-
{
99-
"actor": "${{ github.actor }}",
100-
"repo": "${{ github.repository }}",
101-
"status": "FAIL",
102-
"title": "push to master ⚠",
103-
"pr": "",
104-
"failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/",
105-
"message": ""
106-
}
107-
env:
108-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
10985
110-
slack-workflow-status-success:
111-
if: success()
112-
name: post workflow status to slack
86+
slack-notifications:
87+
if: always()
88+
uses: ./.github/workflows/slack-notifications.yml
11389
needs:
114-
- staticcheck
11590
- test
116-
runs-on: ubuntu-latest
117-
steps:
118-
- name: Notify slack -- workflow succeeded
119-
id: slack
120-
uses: slackapi/[email protected]
121-
with:
122-
payload: |
123-
{
124-
"actor": "${{ github.actor }}",
125-
"repo": "${{ github.repository }}",
126-
"status": "SUCCESS",
127-
"title": "push to master ✅",
128-
"pr": ""
129-
}
130-
env:
131-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_SUCCESS }}
91+
- staticcheck
92+
secrets:
93+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
94+
with:
95+
status: ${{ needs.staticcheck.result }}${{ needs.test.result }}
96+
actor: ${{ github.actor }}
97+
repository: ${{ github.repository }}
98+
branch: "master"
99+
run_id: ${{ github.run_id }}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# .github/workflows/slack-notifications.yml
2+
name: Slack Notifications
3+
4+
on:
5+
workflow_call:
6+
secrets:
7+
SLACK_BOT_TOKEN:
8+
required: true
9+
inputs:
10+
status:
11+
description: 'The status of the workflow (successsuccess or failure)'
12+
required: true
13+
type: string
14+
actor:
15+
description: 'The GitHub actor'
16+
required: true
17+
type: string
18+
repository:
19+
description: 'The GitHub repository'
20+
required: true
21+
type: string
22+
branch:
23+
description: 'The branch name'
24+
required: true
25+
type: string
26+
run_id:
27+
description: 'The workflow run ID'
28+
required: true
29+
type: string
30+
31+
jobs:
32+
notify_slack:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Post to Slack
36+
run: |
37+
if [ "${{ inputs.status }}" == "successsuccess" ]; then
38+
payload=$(jq -n --arg repository "${{ inputs.repository }}" --arg branch "${{ inputs.branch }}" --arg actor "${{ inputs.actor }}" --arg run_id "${{ inputs.run_id }}" '{
39+
"channel": "team-gnark-build",
40+
"text": "GitHub Action build result: success",
41+
"blocks": [
42+
{
43+
"type": "section",
44+
"text": {
45+
"type": "mrkdwn",
46+
"text": ":large_green_circle: *All checks have passed:* *\($branch)* :white_check_mark:"
47+
},
48+
},
49+
{
50+
"type": "context",
51+
"elements": [
52+
{
53+
"type": "mrkdwn",
54+
"text": "\($repository) -- \($actor) -- <https://github.com/\($repository)/actions/runs/\($run_id)|View details>"
55+
}
56+
]
57+
}
58+
]
59+
}')
60+
else
61+
payload=$(jq -n --arg repository "${{ inputs.repository }}" --arg branch "${{ inputs.branch }}" --arg actor "${{ inputs.actor }}" --arg run_id "${{ inputs.run_id }}" '{
62+
"channel": "team-gnark-build",
63+
"text": "GitHub Action build result: failure",
64+
"blocks": [
65+
{
66+
"type": "section",
67+
"text": {
68+
"type": "mrkdwn",
69+
"text": ":red_circle: *Failed run:* *\($branch)*"
70+
},
71+
},
72+
{
73+
"type": "context",
74+
"elements": [
75+
{
76+
"type": "mrkdwn",
77+
"text": "\($repository) -- \($actor) -- <https://github.com/\($repository)/actions/runs/\($run_id)|View details>"
78+
}
79+
]
80+
}
81+
]
82+
}')
83+
fi
84+
response=$(curl -s -X POST -H 'Content-type: application/json; charset=utf-8' --data "$payload" https://slack.com/api/chat.postMessage -H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" )
85+
shell: bash

.gotestfmt/downloads.gotpl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,35 @@ This template contains the format for a package download.
55
{{- $settings := .Settings -}}
66
{{- if or .Packages .Reason -}}
77
{{- if or (not .Settings.HideSuccessfulDownloads) .Failed -}}
8+
::group::
89
{{- if .Failed -}}
9-
10+
{{ "\033" }}[0;31m
1011
{{- else -}}
11-
📥
12+
{{ "\033" }}[0;34m📥
1213
{{- end -}}
13-
{{ " " }} Dependency downloads
14-
{{ "\n" -}}
14+
{{ " " }}Dependency downloads
15+
{{- "\033" }}[0m{{ "\n" -}}
1516

1617
{{- range .Packages -}}
1718
{{- if or (not $settings.HideSuccessfulDownloads) .Failed -}}
1819
{{- " " -}}
1920
{{- if .Failed -}}
20-
21+
{{ "\033" }}[0;31m
2122
{{- else -}}
2223
📦
2324
{{- end -}}
2425
{{- " " -}}
2526
{{- .Package }} {{ .Version -}}
27+
{{- "\033" }}[0m
2628
{{- "\n" -}}
2729
{{ with .Reason -}}
2830
{{- " " -}}{{ . -}}{{ "\n" -}}
2931
{{- end -}}
3032
{{- end -}}
3133
{{- end -}}
3234
{{- with .Reason -}}
33-
{{- " " -}}🛑 {{ . }}{{ "\n" -}}
35+
{{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}}
3436
{{- end -}}
37+
::endgroup::
3538
{{- end -}}
36-
{{- end -}}
39+
{{- end -}}

.gotestfmt/package.gotpl

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
{{- /*gotype: github.com/gotesttools/gotestfmt/v2/parser.Package*/ -}}
2-
2+
{{- /*
3+
This template contains the format for an individual package. GitHub actions does not currently support nested groups so
4+
we are creating a stylized header for each package.
5+
*/ -}}
36
{{- $settings := .Settings -}}
47
{{- if and (or (not $settings.HideSuccessfulPackages) (ne .Result "PASS")) (or (not $settings.HideEmptyPackages) (ne .Result "SKIP") (ne (len .TestCases) 0)) -}}
5-
📦 `{{ .Name }}`
8+
{{- if eq .Result "PASS" -}}
9+
{{ "\033" }}[0;32m
10+
{{- else if eq .Result "SKIP" -}}
11+
{{ "\033" }}[0;33m
12+
{{- else -}}
13+
{{ "\033" }}[0;31m
14+
{{- end -}}
15+
📦 {{ .Name }}{{- "\033" }}[0m
616
{{- with .Coverage -}}
7-
({{ . }}% coverage)
17+
{{- "\033" -}}[0;37m ({{ . }}% coverage){{- "\033" -}}[0m
818
{{- end -}}
919
{{- "\n" -}}
1020
{{- with .Reason -}}
1121
{{- " " -}}🛑 {{ . -}}{{- "\n" -}}
1222
{{- end -}}
1323
{{- with .Output -}}
14-
```{{- "\n" -}}
1524
{{- . -}}{{- "\n" -}}
16-
```{{- "\n" -}}
1725
{{- end -}}
1826
{{- with .TestCases -}}
1927
{{- range . -}}
2028
{{- if or (not $settings.HideSuccessfulTests) (ne .Result "PASS") -}}
29+
::group::
2130
{{- if eq .Result "PASS" -}}
22-
31+
{{ "\033" }}[0;32m
2332
{{- else if eq .Result "SKIP" -}}
24-
🚧
33+
{{ "\033" }}[0;33m🚧
2534
{{- else -}}
26-
35+
{{ "\033" }}[0;31m
2736
{{- end -}}
28-
{{ " " }}`{{- .Name -}}` {{ .Duration -}}
37+
{{ " " }}{{- .Name -}}
38+
{{- "\033" -}}[0;37m ({{if $settings.ShowTestStatus}}{{.Result}}; {{end}}{{ .Duration -}}
39+
{{- with .Coverage -}}
40+
, coverage: {{ . }}%
41+
{{- end -}})
42+
{{- "\033" -}}[0m
2943
{{- "\n" -}}
3044

3145
{{- with .Output -}}
32-
```{{- "\n" -}}
33-
{{- formatTestOutput . $settings -}}{{- "\n" -}}
34-
```{{- "\n" -}}
46+
{{- formatTestOutput . $settings -}}
47+
{{- "\n" -}}
3548
{{- end -}}
3649

37-
{{- "\n" -}}
50+
::endgroup::{{- "\n" -}}
3851
{{- end -}}
3952
{{- end -}}
4053
{{- end -}}
4154
{{- "\n" -}}
42-
{{- end -}}
55+
{{- end -}}

0 commit comments

Comments
 (0)