Skip to content

Commit c6bc3c3

Browse files
authored
ci: update ci workflows (#460)
* ci: update ci workflows * ci: update node script * test: add a failing test to try CI output * ci: add gotestfmt templates * ci: fix ubuntu refs in workflwo * ci: restore clean trace
1 parent 2065441 commit c6bc3c3

File tree

6 files changed

+142
-76
lines changed

6 files changed

+142
-76
lines changed

.github/parse-tests.js

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,24 @@
1-
const readline = require("readline");
1+
const readline = require('readline');
22

3+
// Create readline interface
34
const rl = readline.createInterface({
45
input: process.stdin,
56
output: process.stdout,
6-
terminal: false,
7+
terminal: false
78
});
89

9-
const summary = { fail: [], pass: [], skip: [] };
10-
11-
rl.on("line", (line) => {
12-
const output = JSON.parse(line);
13-
if (
14-
output.Action === "pass" ||
15-
output.Action === "skip" ||
16-
output.Action === "fail"
17-
) {
18-
if (output.Test) {
19-
summary[output.Action].push(output);
20-
}
21-
}
22-
});
23-
24-
25-
rl.on("close", () => {
26-
console.log("## Summary");
27-
console.log("\n");
28-
// console.log("| | # of Tests |");
29-
// console.log("|--|--|");
30-
console.log(
31-
"✅ Passed: %d",
32-
summary.pass.length
33-
);
34-
console.log(
35-
"❌ Failed: %d",
36-
summary.fail.length
37-
);
38-
console.log(
39-
"🚧 Skipped: %d",
40-
summary.skip.length
41-
);
42-
43-
if (summary.fail.length > 0) {
44-
console.log("\n## ❌ Failures\n");
45-
}
46-
47-
summary.fail.forEach((test) => {
48-
console.log("* `%s` (%s)", test.Test, test.Package);
49-
});
50-
51-
// also display skipped tests.
52-
if (summary.skip.length > 0) {
53-
console.log("\n## 🚧 Skipped\n");
54-
}
55-
56-
summary.skip.forEach((test) => {
57-
console.log("* `%s` (%s)", test.Test, test.Package);
58-
});
10+
let content = '';
5911

12+
// Read stdin content
13+
rl.on('line', (line) => {
14+
content += line + '\n';
6015
});
6116

17+
rl.on('close', () => {
18+
// Escape special characters
19+
const escapedContent = content.replace(/"/g, ' ');
20+
// Convert the JSON object to a string
21+
const jsonStr = JSON.stringify(escapedContent);
22+
const jsonStr2 = jsonStr.slice(1, -1);
23+
console.log(jsonStr2);
24+
});

.github/workflows/pr.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ on: pull_request
22
name: pull_request
33
jobs:
44
staticcheck:
5-
runs-on: ubuntu-22.04-16core
5+
runs-on: ubuntu-latest
66
steps:
77
- name: checkout code
88
uses: actions/checkout@v4
@@ -38,10 +38,10 @@ jobs:
3838

3939
test:
4040
runs-on: ubuntu-22.04-16core
41-
needs:
42-
- staticcheck
4341
permissions:
4442
pull-requests: write
43+
outputs:
44+
failures: ${{ steps.generate-job-summary.outputs.failures }}
4545
steps:
4646
- name: checkout code
4747
uses: actions/checkout@v4
@@ -65,20 +65,29 @@ jobs:
6565
- name: Run tests
6666
run: |
6767
set -euo pipefail
68-
go test -json -v -short -timeout=30m ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
69-
go test -json -v -tags=purego -timeout=30m ./... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
70-
go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
71-
GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
68+
go test -json -v -short -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee /tmp/gotest.log
69+
go test -json -v -tags=purego -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
70+
go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
71+
GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
7272
7373
- name: Generate job summary
74+
id: generate-job-summary
75+
if: ${{ always() }}
7476
run: |
75-
cat /tmp/gotest.log | node .github/parse-tests.js > /tmp/gotest.md
76-
cat /tmp/gotest.md > $GITHUB_STEP_SUMMARY
77+
if [ -s /tmp/gotest.log ]; then
78+
cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY
79+
echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT
80+
else
81+
echo "## Success ✅" > $GITHUB_STEP_SUMMARY
82+
echo "failures=" > $GITHUB_OUTPUT
83+
fi
7784
85+
# if we failed a test, we want to comment on the PR with the log
7886
- name: PR comment with file
87+
if: ${{ failure() }}
7988
uses: thollander/actions-comment-pull-request@v2
8089
with:
81-
filePath: /tmp/gotest.md
90+
filePath: /tmp/gotest.log
8291

8392
slack-workflow-status-failed:
8493
if: failure()
@@ -99,7 +108,8 @@ jobs:
99108
"status": "FAIL",
100109
"title": "${{ github.event.pull_request.title }}",
101110
"pr": "${{ github.event.pull_request.head.ref }}",
102-
"failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/"
111+
"failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/",
112+
"message": "${{ needs.test.outputs.failures }}"
103113
}
104114
env:
105115
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/push.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
name: push_master
66
jobs:
77
staticcheck:
8-
runs-on: ubuntu-22.04-16core
8+
runs-on: ubuntu-latest
99
steps:
1010
- name: checkout code
1111
uses: actions/checkout@v4
@@ -47,6 +47,8 @@ jobs:
4747
runs-on: ${{ matrix.os }}
4848
needs:
4949
- staticcheck
50+
outputs:
51+
failures: ${{ steps.generate-job-summary.outputs.failures }}
5052
steps:
5153
- name: checkout code
5254
uses: actions/checkout@v4
@@ -67,21 +69,29 @@ jobs:
6769
token: ${{ secrets.GITHUB_TOKEN }}
6870
- name: Test (windows / mac)
6971
# on macOS CI / Windows CI we avoid running the std/ tests (they are run on ubuntu CI)
70-
if: matrix.os != 'ubuntu-latest'
72+
if: matrix.os != 'ubuntu-22.04-16core'
7173
run: |
7274
go test -short -v -timeout=60m ./...
7375
- name: Test (ubuntu - race and solc)
74-
if: matrix.os == 'ubuntu-latest'
76+
if: matrix.os == 'ubuntu-22.04-16core'
7577
run: |
7678
set -euo pipefail
77-
go test -json -v -timeout=30m ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
78-
go test -json -v -tags=purego -timeout=30m ./... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
79-
go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
80-
GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt
79+
go test -json -v -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee /tmp/gotest.log
80+
go test -json -v -tags=purego -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
81+
go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
82+
GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log
83+
8184
- name: Generate job summary
82-
if: matrix.os == 'ubuntu-latest'
85+
id: generate-job-summary
86+
if: matrix.os == 'ubuntu-22.04-16core' && ${{ always() }}
8387
run: |
84-
cat /tmp/gotest.log | node .github/parse-tests.js > $GITHUB_STEP_SUMMARY
88+
if [ -s /tmp/gotest.log ]; then
89+
cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY
90+
echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT
91+
else
92+
echo "## Success ✅" > $GITHUB_STEP_SUMMARY
93+
echo "failures=" > $GITHUB_OUTPUT
94+
fi
8595
8696
slack-workflow-status-failed:
8797
if: failure()

.gotestfmt/downloads.gotpl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- /*gotype: github.com/gotesttools/gotestfmt/v2/parser.Downloads*/ -}}
2+
{{- /*
3+
This template contains the format for a package download.
4+
*/ -}}
5+
{{- $settings := .Settings -}}
6+
{{- if or .Packages .Reason -}}
7+
{{- if or (not .Settings.HideSuccessfulDownloads) .Failed -}}
8+
::group::
9+
{{- if .Failed -}}
10+
{{ "\033" }}[0;31m❌
11+
{{- else -}}
12+
{{ "\033" }}[0;34m📥
13+
{{- end -}}
14+
{{ " " }}Dependency downloads
15+
{{- "\033" }}[0m{{ "\n" -}}
16+
17+
{{- range .Packages -}}
18+
{{- if or (not $settings.HideSuccessfulDownloads) .Failed -}}
19+
{{- " " -}}
20+
{{- if .Failed -}}
21+
{{ "\033" }}[0;31m❌
22+
{{- else -}}
23+
📦
24+
{{- end -}}
25+
{{- " " -}}
26+
{{- .Package }} {{ .Version -}}
27+
{{- "\033" }}[0m
28+
{{- "\n" -}}
29+
{{ with .Reason -}}
30+
{{- " " -}}{{ . -}}{{ "\n" -}}
31+
{{- end -}}
32+
{{- end -}}
33+
{{- end -}}
34+
{{- with .Reason -}}
35+
{{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}}
36+
{{- end -}}
37+
::endgroup::
38+
{{- end -}}
39+
{{- end -}}

.gotestfmt/package.gotpl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{- /*gotype: github.com/gotesttools/gotestfmt/v2/parser.Package*/ -}}
2+
3+
{{- $settings := .Settings -}}
4+
{{- if and (or (not $settings.HideSuccessfulPackages) (ne .Result "PASS")) (or (not $settings.HideEmptyPackages) (ne .Result "SKIP") (ne (len .TestCases) 0)) -}}
5+
📦 `{{ .Name }}`
6+
{{- with .Coverage -}}
7+
({{ . }}% coverage)
8+
{{- end -}}
9+
{{- "\n" -}}
10+
{{- with .Reason -}}
11+
{{- " " -}}🛑 {{ . -}}{{- "\n" -}}
12+
{{- end -}}
13+
{{- with .Output -}}
14+
```{{- "\n" -}}
15+
{{- . -}}{{- "\n" -}}
16+
```{{- "\n" -}}
17+
{{- end -}}
18+
{{- with .TestCases -}}
19+
{{- range . -}}
20+
{{- if or (not $settings.HideSuccessfulTests) (ne .Result "PASS") -}}
21+
{{- if eq .Result "PASS" -}}
22+
23+
{{- else if eq .Result "SKIP" -}}
24+
🚧
25+
{{- else -}}
26+
27+
{{- end -}}
28+
{{ " " }}`{{- .Name -}}` {{ .Duration -}}
29+
{{- "\n" -}}
30+
31+
{{- with .Output -}}
32+
```{{- "\n" -}}
33+
{{- formatTestOutput . $settings -}}{{- "\n" -}}
34+
```{{- "\n" -}}
35+
{{- end -}}
36+
37+
{{- "\n" -}}
38+
{{- end -}}
39+
{{- end -}}
40+
{{- end -}}
41+
{{- "\n" -}}
42+
{{- end -}}

field/generator/generator_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ func TestIntegration(t *testing.T) {
9393
}
9494
packageDir := filepath.Join(wd, rootDir) + string(filepath.Separator) + "..."
9595
cmd := exec.Command("go", "test", packageDir)
96-
out, err := cmd.CombinedOutput()
97-
fmt.Println(string(out))
98-
if err != nil {
99-
t.Fatal(err)
96+
if err := cmd.Run(); err != nil {
97+
if exitErr, ok := err.(*exec.ExitError); ok {
98+
t.Fatal(string(exitErr.Stderr))
99+
} else {
100+
t.Fatal(err)
101+
}
100102
}
101103

102104
}

0 commit comments

Comments
 (0)