From 6c020cc1f9d74696f14ee1fa42234ea44ba7afc5 Mon Sep 17 00:00:00 2001 From: Kostiantyn <32730812+kkovaletp@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:25:38 +0200 Subject: [PATCH] Enhance Codecov integration (#1136) * Define sub-projects and set coverage threshold for failure in the `codecov.yml`; make both test execution engines to generate also JUnit reports; upload these JUnit reports to Codecov for analysis * Fix UI Vite config and add more details to the API is-generated-code script * Add API JUnit report file to `.gitignore` * Fix the copy issue by mounting the volume * put the exact report name to the `docker cp` command * Added `set -euxo pipeline` to the `test_api_coverage.sh` script; try to fix the missing report issue by setting immutable flag and report directoty * Revert `chattr` and `set` commands, as they cause errors * debug * put the filename of the JUnit report to upload * `set -euxo pipefail` in `scripts/test_api_coverage.sh` --------- Co-authored-by: Konstantin Koval --- .github/workflows/tests.yml | 18 ++++++++++++++++++ .gitignore | 1 + codecov.yml | 18 ++++++++++++++++++ scripts/test_all.sh | 8 ++++---- scripts/test_api_coverage.sh | 6 +++--- scripts/test_is_generated_code_in_sync.sh | 2 ++ ui/package.json | 2 +- ui/vite.config.js | 4 ++++ 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 537805d5..d0fb252c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -76,6 +76,7 @@ jobs: photoview/api \ /app/scripts/test_all.sh docker cp test:/app/api/coverage.txt ./api/ + docker cp test:/app/api/test-api-coverage-report.xml ./api/ - name: Upload coverage uses: codecov/codecov-action@v5 @@ -84,6 +85,14 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: api-${{ matrix.database }} + - name: Upload test execution results + uses: codecov/test-results-action@v1 + if: ${{ steps.test.conclusion == 'success' || steps.test.conclusion == 'failure' }} + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: api-${{ matrix.database }} + files: ./api/test-api-coverage-report.xml + test-ui: name: Test UI runs-on: ubuntu-latest @@ -113,6 +122,7 @@ jobs: run: | docker run --name test photoview/ui npm run test:ci docker cp test:/app/ui/coverage ./ui/ + docker cp test:/app/ui/junit-report.xml ./ui/ - name: Upload coverage uses: codecov/codecov-action@v5 @@ -121,6 +131,14 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: ui + - name: Upload test execution results + uses: codecov/test-results-action@v1 + if: ${{ steps.test.conclusion == 'success' || steps.test.conclusion == 'failure' }} + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: ui + directory: ./ui + - name: Run ESLint working-directory: ui run: | diff --git a/.gitignore b/.gitignore index 949ea112..a3ecfa14 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ node_modules/ # testing /ui/coverage /api/coverage.txt +/api/test-*-report.xml # building .cache/ diff --git a/codecov.yml b/codecov.yml index 991f1fd2..7610ff32 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,21 @@ ignore: - "api/**/generated.go" - "ui/src/**/__generated__" +coverage: + status: + project: + default: + target: auto + threshold: 5 + ui: + target: auto + threshold: 5 + flags: + - ui + api: + target: auto + threshold: 5 + flags: + - api-sqlite + - api-postgres + - api-mysql diff --git a/scripts/test_all.sh b/scripts/test_all.sh index 7270bc43..7320f72f 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -1,10 +1,10 @@ #!/bin/sh set -eu -for test in $(dirname $0)/test_* -do - if [ "${test}" != "${test%%/scripts/test_all.sh}" ] - then +go install github.com/jstemmer/go-junit-report@latest + +for test in $(dirname $0)/test_*; do + if [ "${test}" != "${test%%/scripts/test_all.sh}" ]; then continue fi diff --git a/scripts/test_api_coverage.sh b/scripts/test_api_coverage.sh index 8dbf8780..e925770e 100755 --- a/scripts/test_api_coverage.sh +++ b/scripts/test_api_coverage.sh @@ -1,5 +1,5 @@ -#!/bin/sh -set -eu +#!/bin/bash +set -euxo pipefail cd $(dirname $0)/../api -go test ./... -v -database -filesystem -p 1 -coverprofile=coverage.txt -covermode=atomic +go test ./... -v -database -filesystem -p 1 -coverprofile=coverage.txt -covermode=atomic 2>&1 | tee >(go-junit-report >test-api-coverage-report.xml) diff --git a/scripts/test_is_generated_code_in_sync.sh b/scripts/test_is_generated_code_in_sync.sh index f040b3c5..ca785c57 100755 --- a/scripts/test_is_generated_code_in_sync.sh +++ b/scripts/test_is_generated_code_in_sync.sh @@ -5,6 +5,8 @@ cd $(dirname $0)/../api go generate ./... if [ "$(git status -s 2>/dev/null | head -1)" != "" ]; then echo '--- FAIL: The generated API code is out of sync with the recent changes. Please run `go generate ./...` under `./api` to regenerate it and commit it to this branch.' + echo 'These are the changes:' + git status -s exit 1 fi diff --git a/ui/package.json b/ui/package.json index 2b330ac4..9b40431d 100644 --- a/ui/package.json +++ b/ui/package.json @@ -15,7 +15,7 @@ "lint": "eslint ./src --max-warnings 0 --config .eslintrc.js", "lint:ci": "eslint ./src --config .eslintrc.js --no-color --fix-dry-run > eslint-report.txt", "test": "vitest", - "test:ci": "CI=true vitest --reporter verbose --run --coverage", + "test:ci": "CI=true vitest --reporter=junit --reporter=verbose --run --coverage", "genSchemaTypes": "apollo client:codegen --target=typescript --globalTypesFile=src/__generated__/globalTypes.ts --passthroughCustomScalars && prettier --write */**/__generated__/*.ts", "extractTranslations": "i18next -c i18next-parser.config.js", "prepare": "(cd .. && ./ui/node_modules/.bin/husky install)" diff --git a/ui/vite.config.js b/ui/vite.config.js index 7dbc5532..bc499d29 100644 --- a/ui/vite.config.js +++ b/ui/vite.config.js @@ -18,6 +18,10 @@ export default defineConfig({ globals: true, environment: 'jsdom', setupFiles: './testing/setupTests.ts', + reporters: ['verbose', 'junit'], + outputFile: { + junit: './junit-report.xml', + }, coverage: { reporter: ['text', 'json', 'html'], },