diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58faabaa6d..688d43ae54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,9 @@ jobs: name: Unit Tests runs-on: ubuntu-24.04 needs: vars + permissions: + checks: write + pull-requests: write steps: - name: Checkout Repository uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 @@ -90,7 +93,9 @@ jobs: .github/.cache/buster-for-unit-tests - name: Run Tests - run: make unit-test + run: | + go test ./cmd/... ./internal/... -race -shuffle=on -coverprofile=coverage.out -covermode=atomic -json | go run github.com/ctrf-io/go-ctrf-json-reporter/cmd/go-ctrf-json-reporter@latest -output ctrf-report.json + go tool cover -html=coverage.out -o cover.html - name: Upload coverage reports to Codecov uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 @@ -104,10 +109,21 @@ jobs: path: ${{ github.workspace }}/cover.html if: always() + - name: Publish CTRF Detailed Test Summary Results + run: | + npx github-actions-ctrf summary ctrf-report.json + npx github-actions-ctrf failed ctrf-report.json --pr-comment --on-fail-only --annotate + env: + GITHUB_TOKEN: ${{ secrets.NGINX_PAT }} + if: always() + njs-unit-tests: name: NJS Unit Tests runs-on: ubuntu-24.04 needs: vars + permissions: + checks: write + pull-requests: write steps: - name: Checkout Repository uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 @@ -125,6 +141,12 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} + - name: Test Report + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + files: ${{ github.workspace }}/internal/mode/static/nginx/modules/njs-unit-tests.xml + if: always() + binary: name: Build Binary runs-on: ubuntu-24.04 diff --git a/.gitignore b/.gitignore index 3615727c6d..b730e0aed4 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,7 @@ internal/mode/static/nginx/modules/coverage # temporary files used for manifest generation config/base/deploy.yaml config/base/deploy.yaml.bak + +# test reports +ctrf-report.json +njs-unit-tests.xml diff --git a/internal/mode/static/nginx/modules/package.json b/internal/mode/static/nginx/modules/package.json index 1fc2f65398..81f8b686d3 100644 --- a/internal/mode/static/nginx/modules/package.json +++ b/internal/mode/static/nginx/modules/package.json @@ -6,7 +6,7 @@ "scripts": { "format": "prettier -w src/ test/", "lint": "prettier -c src/ test/", - "test": "vitest run --coverage", + "test": "vitest run --coverage --config test/vitest.config.ts", "clean": "rm -rf node_modules coverage" }, "devDependencies": { diff --git a/internal/mode/static/nginx/modules/test/vitest.config.ts b/internal/mode/static/nginx/modules/test/vitest.config.ts index b951a942f7..ed26bb90b2 100644 --- a/internal/mode/static/nginx/modules/test/vitest.config.ts +++ b/internal/mode/static/nginx/modules/test/vitest.config.ts @@ -2,6 +2,8 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { + reporters: ['verbose', 'junit'], + outputFile: './njs-unit-tests.xml', coverage: { reporter: ['text', 'json', 'html'], },