diff --git a/.github/parse-tests.js b/.github/parse-tests.js index 44a3d88b36..2ae1f55819 100644 --- a/.github/parse-tests.js +++ b/.github/parse-tests.js @@ -1,61 +1,24 @@ -const readline = require("readline"); +const readline = require('readline'); +// Create readline interface const rl = readline.createInterface({ input: process.stdin, output: process.stdout, - terminal: false, + terminal: false }); -const summary = { fail: [], pass: [], skip: [] }; - -rl.on("line", (line) => { - const output = JSON.parse(line); - if ( - output.Action === "pass" || - output.Action === "skip" || - output.Action === "fail" - ) { - if (output.Test) { - summary[output.Action].push(output); - } - } -}); - - -rl.on("close", () => { - console.log("## Summary"); - console.log("\n"); - // console.log("| | # of Tests |"); - // console.log("|--|--|"); - console.log( - "✅ Passed: %d", - summary.pass.length - ); - console.log( - "❌ Failed: %d", - summary.fail.length - ); - console.log( - "🚧 Skipped: %d", - summary.skip.length - ); - - if (summary.fail.length > 0) { - console.log("\n## ❌ Failures\n"); - } - - summary.fail.forEach((test) => { - console.log("* `%s` (%s)", test.Test, test.Package); - }); - - // also display skipped tests. - if (summary.skip.length > 0) { - console.log("\n## 🚧 Skipped\n"); - } - - summary.skip.forEach((test) => { - console.log("* `%s` (%s)", test.Test, test.Package); - }); +let content = ''; +// Read stdin content +rl.on('line', (line) => { + content += line + '\n'; }); +rl.on('close', () => { + // Escape special characters + const escapedContent = content.replace(/"/g, ' '); + // Convert the JSON object to a string + const jsonStr = JSON.stringify(escapedContent); + const jsonStr2 = jsonStr.slice(1, -1); + console.log(jsonStr2); +}); \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c64073248f..b5b6ddeed5 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -2,7 +2,7 @@ on: pull_request name: pull_request jobs: staticcheck: - runs-on: ubuntu-22.04-16core + runs-on: ubuntu-latest steps: - name: checkout code uses: actions/checkout@v4 @@ -38,10 +38,10 @@ jobs: test: runs-on: ubuntu-22.04-16core - needs: - - staticcheck permissions: pull-requests: write + outputs: + failures: ${{ steps.generate-job-summary.outputs.failures }} steps: - name: checkout code uses: actions/checkout@v4 @@ -65,20 +65,29 @@ jobs: - name: Run tests run: | set -euo pipefail - go test -json -v -short -timeout=30m ./... 2>&1 | tee /tmp/gotest.log | gotestfmt - go test -json -v -tags=purego -timeout=30m ./... 2>&1 | tee -a /tmp/gotest.log | gotestfmt - go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt - GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt + go test -json -v -short -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee /tmp/gotest.log + go test -json -v -tags=purego -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log + go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log + GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log - name: Generate job summary + id: generate-job-summary + if: ${{ always() }} run: | - cat /tmp/gotest.log | node .github/parse-tests.js > /tmp/gotest.md - cat /tmp/gotest.md > $GITHUB_STEP_SUMMARY + if [ -s /tmp/gotest.log ]; then + cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY + echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT + else + echo "## Success ✅" > $GITHUB_STEP_SUMMARY + echo "failures=" > $GITHUB_OUTPUT + fi + # if we failed a test, we want to comment on the PR with the log - name: PR comment with file + if: ${{ failure() }} uses: thollander/actions-comment-pull-request@v2 with: - filePath: /tmp/gotest.md + filePath: /tmp/gotest.log slack-workflow-status-failed: if: failure() @@ -99,7 +108,8 @@ jobs: "status": "FAIL", "title": "${{ github.event.pull_request.title }}", "pr": "${{ github.event.pull_request.head.ref }}", - "failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/" + "failed_step_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/", + "message": "${{ needs.test.outputs.failures }}" } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 231f5cdc12..bdffcb910f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -5,7 +5,7 @@ on: name: push_master jobs: staticcheck: - runs-on: ubuntu-22.04-16core + runs-on: ubuntu-latest steps: - name: checkout code uses: actions/checkout@v4 @@ -47,6 +47,8 @@ jobs: runs-on: ${{ matrix.os }} needs: - staticcheck + outputs: + failures: ${{ steps.generate-job-summary.outputs.failures }} steps: - name: checkout code uses: actions/checkout@v4 @@ -67,21 +69,29 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Test (windows / mac) # on macOS CI / Windows CI we avoid running the std/ tests (they are run on ubuntu CI) - if: matrix.os != 'ubuntu-latest' + if: matrix.os != 'ubuntu-22.04-16core' run: | go test -short -v -timeout=60m ./... - name: Test (ubuntu - race and solc) - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-22.04-16core' run: | set -euo pipefail - go test -json -v -timeout=30m ./... 2>&1 | tee /tmp/gotest.log | gotestfmt - go test -json -v -tags=purego -timeout=30m ./... 2>&1 | tee -a /tmp/gotest.log | gotestfmt - go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt - GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | tee -a /tmp/gotest.log | gotestfmt + go test -json -v -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee /tmp/gotest.log + go test -json -v -tags=purego -timeout=30m ./... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log + go test -json -v -race -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log + GOARCH=386 go test -json -short -v -timeout=30m ./ecc/bn254/... 2>&1 | gotestfmt -hide=all | tee -a /tmp/gotest.log + - name: Generate job summary - if: matrix.os == 'ubuntu-latest' + id: generate-job-summary + if: matrix.os == 'ubuntu-22.04-16core' && ${{ always() }} run: | - cat /tmp/gotest.log | node .github/parse-tests.js > $GITHUB_STEP_SUMMARY + if [ -s /tmp/gotest.log ]; then + cat /tmp/gotest.log > $GITHUB_STEP_SUMMARY + echo "failures=$(cat /tmp/gotest.log | node .github/parse-tests.js)" > $GITHUB_OUTPUT + else + echo "## Success ✅" > $GITHUB_STEP_SUMMARY + echo "failures=" > $GITHUB_OUTPUT + fi slack-workflow-status-failed: if: failure() diff --git a/.gotestfmt/downloads.gotpl b/.gotestfmt/downloads.gotpl new file mode 100644 index 0000000000..22f7219520 --- /dev/null +++ b/.gotestfmt/downloads.gotpl @@ -0,0 +1,39 @@ +{{- /*gotype: github.com/gotesttools/gotestfmt/v2/parser.Downloads*/ -}} +{{- /* +This template contains the format for a package download. +*/ -}} +{{- $settings := .Settings -}} +{{- if or .Packages .Reason -}} + {{- if or (not .Settings.HideSuccessfulDownloads) .Failed -}} + ::group:: + {{- if .Failed -}} + {{ "\033" }}[0;31m❌ + {{- else -}} + {{ "\033" }}[0;34m📥 + {{- end -}} + {{ " " }}Dependency downloads + {{- "\033" }}[0m{{ "\n" -}} + + {{- range .Packages -}} + {{- if or (not $settings.HideSuccessfulDownloads) .Failed -}} + {{- " " -}} + {{- if .Failed -}} + {{ "\033" }}[0;31m❌ + {{- else -}} + 📦 + {{- end -}} + {{- " " -}} + {{- .Package }} {{ .Version -}} + {{- "\033" }}[0m + {{- "\n" -}} + {{ with .Reason -}} + {{- " " -}}{{ . -}}{{ "\n" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- with .Reason -}} + {{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}} + {{- end -}} + ::endgroup:: + {{- end -}} +{{- end -}} diff --git a/.gotestfmt/package.gotpl b/.gotestfmt/package.gotpl new file mode 100644 index 0000000000..504949a86b --- /dev/null +++ b/.gotestfmt/package.gotpl @@ -0,0 +1,42 @@ +{{- /*gotype: github.com/gotesttools/gotestfmt/v2/parser.Package*/ -}} + +{{- $settings := .Settings -}} +{{- if and (or (not $settings.HideSuccessfulPackages) (ne .Result "PASS")) (or (not $settings.HideEmptyPackages) (ne .Result "SKIP") (ne (len .TestCases) 0)) -}} + 📦 `{{ .Name }}` + {{- with .Coverage -}} + ({{ . }}% coverage) + {{- end -}} + {{- "\n" -}} + {{- with .Reason -}} + {{- " " -}}🛑 {{ . -}}{{- "\n" -}} + {{- end -}} + {{- with .Output -}} + ```{{- "\n" -}} + {{- . -}}{{- "\n" -}} + ```{{- "\n" -}} + {{- end -}} + {{- with .TestCases -}} + {{- range . -}} + {{- if or (not $settings.HideSuccessfulTests) (ne .Result "PASS") -}} + {{- if eq .Result "PASS" -}} + ✅ + {{- else if eq .Result "SKIP" -}} + 🚧 + {{- else -}} + ❌ + {{- end -}} + {{ " " }}`{{- .Name -}}` {{ .Duration -}} + {{- "\n" -}} + + {{- with .Output -}} + ```{{- "\n" -}} + {{- formatTestOutput . $settings -}}{{- "\n" -}} + ```{{- "\n" -}} + {{- end -}} + + {{- "\n" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- "\n" -}} +{{- end -}} diff --git a/field/generator/generator_test.go b/field/generator/generator_test.go index 8a73997b36..e107a0e85f 100644 --- a/field/generator/generator_test.go +++ b/field/generator/generator_test.go @@ -93,10 +93,12 @@ func TestIntegration(t *testing.T) { } packageDir := filepath.Join(wd, rootDir) + string(filepath.Separator) + "..." cmd := exec.Command("go", "test", packageDir) - out, err := cmd.CombinedOutput() - fmt.Println(string(out)) - if err != nil { - t.Fatal(err) + if err := cmd.Run(); err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { + t.Fatal(string(exitErr.Stderr)) + } else { + t.Fatal(err) + } } }