From 8eb69b77f24512194fba3eedbb9432051a41f708 Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 11:12:12 -0500 Subject: [PATCH 1/6] Added test coverage tracking to the PR workflow --- .github/workflows/run-tests.yml | 11 +++++++++-- .gitignore | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a8db2d4..1554494 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,5 +33,12 @@ jobs: with: mongodb-version: '8.0' - - name: Run tests - run: go test ./... \ No newline at end of file + - name: Run Test + run: | + go test -v ./... -covermode=count -coverprofile=coverage.out + go tool cover -func=coverage.out -o=coverage.out + + - name: Go Coverage Badge + uses: tj-actions/coverage-badge-go@v2 + with: + filename: coverage.out \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2260f01..5f48a2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .vscode __debug* dist/ +cover.out +cover.html \ No newline at end of file From 4888c547067fc1888781940f84a1f545a0fad881 Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 11:15:19 -0500 Subject: [PATCH 2/6] Added test coverage badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d95a7b..f921b41 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # webtrack - Real-time webpage value tracker in Go -![tests](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml/badge.svg) ![build](https://github.com/igor-sikachyna/webtrack/actions/workflows/create-release.yml/badge.svg) +![tests](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml/badge.svg) ![build](https://github.com/igor-sikachyna/webtrack/actions/workflows/create-release.yml/badge.svg) [![coverage](https://img.shields.io/badge/Coverage-100.0%25-brightgreen)](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml) Application written in Go to collect the information from webpages or API endpoints and to store it in MongoDB From 66bd4674fc62dd1b972e048940cf7654b0628fa2 Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 11:47:34 -0500 Subject: [PATCH 3/6] Change badge generation action --- .github/workflows/run-tests.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1554494..9285cc0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -35,10 +35,11 @@ jobs: - name: Run Test run: | - go test -v ./... -covermode=count -coverprofile=coverage.out - go tool cover -func=coverage.out -o=coverage.out + go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./... - - name: Go Coverage Badge - uses: tj-actions/coverage-badge-go@v2 + - name: Check test coverage + uses: vladopajic/go-test-coverage@v2 with: - filename: coverage.out \ No newline at end of file + profile: cover.out + git-token: ${{ github.ref_name == 'feature/test-coverage' && secrets.GITHUB_TOKEN || '' }} + git-branch: badges \ No newline at end of file From 7329401cacf5e3360ad34f75771e4c215186b396 Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 11:50:56 -0500 Subject: [PATCH 4/6] Try without branch detection --- .github/workflows/run-tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9285cc0..d78fa21 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,6 +33,9 @@ jobs: with: mongodb-version: '8.0' + - name: Print env + run: echo ${{ github.ref_name }} + - name: Run Test run: | go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./... @@ -41,5 +44,5 @@ jobs: uses: vladopajic/go-test-coverage@v2 with: profile: cover.out - git-token: ${{ github.ref_name == 'feature/test-coverage' && secrets.GITHUB_TOKEN || '' }} + git-token: ${{ secrets.GITHUB_TOKEN }} git-branch: badges \ No newline at end of file From 504acf3ee6c7f98a67d2bdb45cfbc60a7f08ba32 Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 12:00:21 -0500 Subject: [PATCH 5/6] Update coverage badge path --- .github/workflows/run-tests.yml | 7 +++++-- README.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d78fa21..206b503 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -34,7 +34,9 @@ jobs: mongodb-version: '8.0' - name: Print env - run: echo ${{ github.ref_name }} + run: | + echo ${{ github.ref_name }} + echo ${{ github.head_ref }} - name: Run Test run: | @@ -45,4 +47,5 @@ jobs: with: profile: cover.out git-token: ${{ secrets.GITHUB_TOKEN }} - git-branch: badges \ No newline at end of file + git-branch: badges + git-file-name: .badges/${{ github.head_ref || github.ref_name }}/coverage.svg \ No newline at end of file diff --git a/README.md b/README.md index f921b41..2dc4f5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # webtrack - Real-time webpage value tracker in Go -![tests](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml/badge.svg) ![build](https://github.com/igor-sikachyna/webtrack/actions/workflows/create-release.yml/badge.svg) [![coverage](https://img.shields.io/badge/Coverage-100.0%25-brightgreen)](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml) +![tests](https://github.com/igor-sikachyna/webtrack/actions/workflows/run-tests.yml/badge.svg) ![build](https://github.com/igor-sikachyna/webtrack/actions/workflows/create-release.yml/badge.svg) ![coverage](https://raw.githubusercontent.com/igor-sikachyna/webtrack/badges/.badges/feature/test-coverage/coverage.svg) Application written in Go to collect the information from webpages or API endpoints and to store it in MongoDB From 502d911ebbe5e41aece972f68e07bca262536c8f Mon Sep 17 00:00:00 2001 From: Ihor Sikachyna Date: Tue, 3 Dec 2024 12:02:57 -0500 Subject: [PATCH 6/6] Remove debug print --- .github/workflows/run-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 206b503..e1e3f7f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,11 +33,6 @@ jobs: with: mongodb-version: '8.0' - - name: Print env - run: | - echo ${{ github.ref_name }} - echo ${{ github.head_ref }} - - name: Run Test run: | go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...