diff --git a/.ci/complement_package.gotpl b/.ci/complement_package.gotpl new file mode 100644 index 00000000..2dd5e5e0 --- /dev/null +++ b/.ci/complement_package.gotpl @@ -0,0 +1,91 @@ +{{- /*gotype: github.com/haveyoudebuggedit/gotestfmt/parser.Package*/ -}} +{{- /* +This template contains the format for an individual package. GitHub actions does not currently support nested groups so +we are creating a stylized header for each package. + +This template is based on https://github.com/haveyoudebuggedit/gotestfmt/blob/f179b0e462a9dcf7101515d87eec4e4d7e58b92a/.gotestfmt/github/package.gotpl +which is under the Unlicense licence. +*/ -}} +{{- $settings := .Settings -}} +{{- if and (or (not $settings.HideSuccessfulPackages) (ne .Result "PASS")) (or (not $settings.HideEmptyPackages) (ne .Result "SKIP") (ne (len .TestCases) 0)) -}} + {{- if eq .Result "PASS" -}} + {{ "\033" }}[0;32m + {{- else if eq .Result "SKIP" -}} + {{ "\033" }}[0;33m + {{- else -}} + {{ "\033" }}[0;31m + {{- end -}} + 📦 {{ .Name }}{{- "\033" }}[0m + {{- with .Coverage -}} + {{- "\033" -}}[0;37m ({{ . }}% coverage){{- "\033" -}}[0m + {{- end -}} + {{- "\n" -}} + {{- with .Reason -}} + {{- " " -}}🛑 {{ . -}}{{- "\n" -}} + {{- end -}} + {{- with .Output -}} + {{- . -}}{{- "\n" -}} + {{- end -}} + {{- with .TestCases -}} + {{- /* Passing tests are first */ -}} + {{- range . -}} + {{- if eq .Result "PASS" -}} + ::group::{{ "\033" }}[0;32m✅{{ " " }}{{- .Name -}} + {{- "\033" -}}[0;37m ({{if $settings.ShowTestStatus}}{{.Result}}; {{end}}{{ .Duration -}} + {{- with .Coverage -}} + , coverage: {{ . }}% + {{- end -}}) + {{- "\033" -}}[0m + {{- "\n" -}} + + {{- with .Output -}} + {{- formatTestOutput . $settings -}} + {{- "\n" -}} + {{- end -}} + + ::endgroup::{{- "\n" -}} + {{- end -}} + {{- end -}} + + {{- /* Then skipped tests are second */ -}} + {{- range . -}} + {{- if eq .Result "SKIP" -}} + ::group::{{ "\033" }}[0;33m🚧{{ " " }}{{- .Name -}} + {{- "\033" -}}[0;37m ({{if $settings.ShowTestStatus}}{{.Result}}; {{end}}{{ .Duration -}} + {{- with .Coverage -}} + , coverage: {{ . }}% + {{- end -}}) + {{- "\033" -}}[0m + {{- "\n" -}} + + {{- with .Output -}} + {{- formatTestOutput . $settings -}} + {{- "\n" -}} + {{- end -}} + + ::endgroup::{{- "\n" -}} + {{- end -}} + {{- end -}} + + {{- /* and failing tests are last */ -}} + {{- range . -}} + {{- if and (ne .Result "PASS") (ne .Result "SKIP") -}} + ::group::{{ "\033" }}[0;31m❌{{ " " }}{{- .Name -}} + {{- "\033" -}}[0;37m ({{if $settings.ShowTestStatus}}{{.Result}}; {{end}}{{ .Duration -}} + {{- with .Coverage -}} + , coverage: {{ . }}% + {{- end -}}) + {{- "\033" -}}[0m + {{- "\n" -}} + + {{- with .Output -}} + {{- formatTestOutput . $settings -}} + {{- "\n" -}} + {{- end -}} + + ::endgroup::{{- "\n" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- "\n" -}} +{{- end -}} diff --git a/.ci/scripts/gotestfmt b/.ci/scripts/gotestfmt new file mode 100755 index 00000000..83e0ec63 --- /dev/null +++ b/.ci/scripts/gotestfmt @@ -0,0 +1,21 @@ +#!/bin/bash +# +# wraps `gotestfmt`, hiding output from successful packages unless +# all tests passed. + +set -o pipefail +set -e + +# tee the test results to a log, whilst also piping them into gotestfmt, +# telling it to hide successful results, so that we can clearly see +# unsuccessful results. +tee complement.log | gotestfmt -hide successful-packages + +# gotestfmt will exit non-zero if there were any failures, so if we got to this +# point, we must have had a successful result. +echo "All tests successful; showing all test results" + +# Pipe the test results back through gotestfmt, showing all results. +# The log file consists of JSON lines giving the test results, interspersed +# with regular stdout lines (including reports of downloaded packages). +grep '^{"Time":' complement.log | gotestfmt diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 417689e4..057dd7bd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,7 +25,7 @@ jobs: sudo apt-get update && sudo apt-get install -y libolm3 libolm-dev - name: "Run internal Complement tests" run: | - go test ./internal/... + go test ./internal/... - name: "Run Homerunner tests" # use a simple static dendrite image to sanity check homerunner works run: | mkdir -p homeserver @@ -71,12 +71,14 @@ jobs: run: | sudo apt-get update && sudo apt-get install -y libolm3 libolm-dev go get -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest + mkdir .gotestfmt/github -p + cp .ci/complement_package.gotpl .gotestfmt/github/package.gotpl - name: "Checkout corresponding ${{ matrix.homeserver }} branch" shell: bash run: | mkdir -p homeserver - + # Attempt to use the version of the homeserver which best matches the # current build. # @@ -84,7 +86,7 @@ jobs: # similarly named branch (GITHUB_HEAD_REF for pull requests, # otherwise GITHUB_REF). # 2. otherwise, use the default homeserver branch ("HEAD") - + for BRANCH_NAME in "$GITHUB_HEAD_REF" "${GITHUB_REF#refs/heads/}" "HEAD"; do # Skip empty branch names, merge commits, and our default branch. # (If we are on complement's default branch, we want to fall through to the HS's default branch @@ -119,7 +121,7 @@ jobs: - run: | set -o pipefail && - ${{ matrix.env }} go test -v -json -tags "${{ matrix.tags }}" -timeout "${{ matrix.timeout }}" ./tests/... 2>&1 | gotestfmt + ${{ matrix.env }} go test -v -json -tags "${{ matrix.tags }}" -timeout "${{ matrix.timeout }}" ./tests/... | .ci/scripts/gotestfmt shell: bash # required for pipefail to be A Thing. pipefail is required to stop gotestfmt swallowing non-zero exit codes name: Run Complement Tests env: