From 35334b360fe08d1f0302dcb82b4a56f196966466 Mon Sep 17 00:00:00 2001 From: Felipe Publio Date: Mon, 27 Jan 2025 09:59:12 -0300 Subject: [PATCH 1/4] feat: add GitHub Actions workflow for running unit tests and coverage --- .github/workflows/unit-tests.yml | 34 ++++++++++++++++++++++++++++++++ Makefile | 19 ++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/unit-tests.yml create mode 100644 Makefile diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..c167a95 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,34 @@ +name: Unit Tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + name: Run Unit Tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Install dependencies + run: go mod download + + - name: Run Unit Tests + run: | + go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + go tool cover -func=coverage.txt > coverage.out + + - name: Comment coverage + if: github.event_name == 'pull_request' + uses: k1LoW/octocov-action@v0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f280e0d --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: test test-coverage test-race test-all + +# Run all tests +test: + go test ./... + +# Run tests with coverage +test-coverage: + go test -coverprofile=coverage.txt -covermode=atomic ./... + go tool cover -func=coverage.txt + +# Run tests with race detection +test-race: + go test -race ./... + +# Run all tests with coverage and race detection +test-all: + go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + go tool cover -func=coverage.txt From df6c0b58885460ef9452117711578e3935e56870 Mon Sep 17 00:00:00 2001 From: Felipe Publio Date: Mon, 27 Jan 2025 10:01:54 -0300 Subject: [PATCH 2/4] feat: enhance GitHub Actions workflow for coverage reporting and add configuration for Octocov --- .github/workflows/unit-tests.yml | 6 +++--- .octocov.yml | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .octocov.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c167a95..28fee3f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -24,11 +24,11 @@ jobs: - name: Run Unit Tests run: | + mkdir -p .octocov go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - go tool cover -func=coverage.txt > coverage.out - name: Comment coverage if: github.event_name == 'pull_request' uses: k1LoW/octocov-action@v0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + with: + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.octocov.yml b/.octocov.yml new file mode 100644 index 0000000..35d81a5 --- /dev/null +++ b/.octocov.yml @@ -0,0 +1,12 @@ + +coverage: + paths: + - coverage.txt + display-style: table + acceptable: 70 + badge: + path: docs/coverage.svg + +diff: + datastores: + - local://.octocov/coverage.json \ No newline at end of file From 79a778f7cef13a469ce5f903b1842c181ee075c4 Mon Sep 17 00:00:00 2001 From: Felipe Publio Date: Mon, 27 Jan 2025 10:06:51 -0300 Subject: [PATCH 3/4] fix: update unit tests workflow to fetch full history and simplify test command --- .github/workflows/unit-tests.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 28fee3f..7e12e3c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v4 @@ -25,10 +27,4 @@ jobs: - name: Run Unit Tests run: | mkdir -p .octocov - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Comment coverage - if: github.event_name == 'pull_request' - uses: k1LoW/octocov-action@v0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + go test -v -race ./... \ No newline at end of file From 6b30661701ab810ef5484524f20f9927c3864d2c Mon Sep 17 00:00:00 2001 From: Felipe Publio Date: Mon, 27 Jan 2025 10:09:12 -0300 Subject: [PATCH 4/4] chore: update GitHub Actions to use latest versions of checkout and setup-go --- .github/workflows/unit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 7e12e3c..adf08f1 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -12,12 +12,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.23'