From 68230377645358dd0d2407d9e618fafb99e1de30 Mon Sep 17 00:00:00 2001 From: Rodolfo Sanchez Date: Sun, 24 Sep 2023 04:53:18 -0500 Subject: [PATCH 1/5] add test workflow Signed-off-by: Rodolfo Sanchez --- .github/workflows/release.yaml | 25 ++++++++++++++++--------- .github/workflows/test.yaml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 57c4b48..334eb5f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,23 +1,22 @@ name: Release CLI on: - push: - branches: - - main - paths: - - 'pkg/**' - - 'cmd/**' - - 'go.*' - - 'main.go' + workflow_run: + workflows: ["Test AoCTL"] + branches: [main] + types: + - completed env: REGISTRY: ghcr.io jobs: - goreleaser: + release: runs-on: ubuntu-latest + permissions: contents: write packages: write + steps: - name: Checkout uses: actions/checkout@v4 @@ -34,6 +33,14 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 + - name: Test + run: go test ./... -cover + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Create new tag run: | tag=$(echo $(git describe --abbrev=0 --tags) | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..e6dcc8f --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,34 @@ +name: Test AoCTL + +on: + pull_request: + branches: + - main + push: + branches: + - main + paths: + - 'pkg/**' + - 'cmd/**' + - 'go.*' + - 'main.go' + +jobs: + test-cli: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + + - name: Test + run: go test ./... -cover + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 142a8f6af260c447f90810cbdd061520d21ed734 Mon Sep 17 00:00:00 2001 From: Rodolfo Sanchez Date: Sun, 24 Sep 2023 04:58:42 -0500 Subject: [PATCH 2/5] add coverprofile to the test output: Signed-off-by: Rodolfo Sanchez --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e6dcc8f..1d1acf6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-go@v4 - name: Test - run: go test ./... -cover + run: go test ./... -cover -coverprofile=coverage.txt - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 From dc77a1ae4d9018f9d8ce9731c83fa5597dfd4163 Mon Sep 17 00:00:00 2001 From: Rodolfo Sanchez Date: Sun, 24 Sep 2023 05:15:41 -0500 Subject: [PATCH 3/5] include empty test files in consideration Signed-off-by: Rodolfo Sanchez --- .github/workflows/test.yaml | 2 +- .gitignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1d1acf6..0b41b72 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-go@v4 - name: Test - run: go test ./... -cover -coverprofile=coverage.txt + run: go test ./pkg/... ./cmd/... -coverpkg=./pkg/...,./cmd/... -coverprofile=coverage.out - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index adfefb3..05d8ee5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode dist/ +coverage* From 9d11ba8cec4a5c5b6a2a8420bc5ad3247990cc5c Mon Sep 17 00:00:00 2001 From: Rodolfo Sanchez Date: Sun, 24 Sep 2023 05:20:17 -0500 Subject: [PATCH 4/5] add GOEXPERIMENT=nocoverageredesign to the job Signed-off-by: Rodolfo Sanchez --- .github/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0b41b72..3b44c3c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,6 +26,8 @@ jobs: uses: actions/setup-go@v4 - name: Test + env: + GOEXPERIMENT: nocoverageredesign run: go test ./pkg/... ./cmd/... -coverpkg=./pkg/...,./cmd/... -coverprofile=coverage.out - name: Upload coverage reports to Codecov From c4e0baf2960217434916ffab0bae872f2801e03f Mon Sep 17 00:00:00 2001 From: Rodolfo Sanchez Date: Sun, 24 Sep 2023 05:35:08 -0500 Subject: [PATCH 5/5] add badge in README Signed-off-by: Rodolfo Sanchez --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6579dce..88ffe3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Advent of Code CLI [![Go Reference](https://pkg.go.dev/badge/github.com/dolfolife/aoctl#section-readme.svg)](https://pkg.go.dev/github.com/dolfolife/aoctl#section-readme) +[![codecov](https://codecov.io/github/dolfolife/aoctl/graph/badge.svg?token=GTFZX1J2WX)](https://codecov.io/github/dolfolife/aoctl) This is a personal project I have to learn more about writing CLI tools in GoLang. The idea behind this project is to help me solve the [Advent of Code](adventofcode.com/) since I have noticed some patterns while solving them.