From f641069c8f9dada1cfb2b1b5fc324f668f42be86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Thu, 8 May 2025 11:57:45 +0200 Subject: [PATCH 1/4] souce action --- ...action-test.yml => action-docker-test.yml} | 4 +- .github/workflows/action-source-test.yml | 108 ++++++++++ action.yml | 42 ++-- action/action.yml | 193 ++++++++++++++++++ main_config.go | 2 +- 5 files changed, 325 insertions(+), 24 deletions(-) rename .github/workflows/{action-test.yml => action-docker-test.yml} (97%) create mode 100644 .github/workflows/action-source-test.yml create mode 100644 action/action.yml diff --git a/.github/workflows/action-test.yml b/.github/workflows/action-docker-test.yml similarity index 97% rename from .github/workflows/action-test.yml rename to .github/workflows/action-docker-test.yml index 5fc8ae0..fbdedc2 100644 --- a/.github/workflows/action-test.yml +++ b/.github/workflows/action-docker-test.yml @@ -1,4 +1,4 @@ -name: action-test +name: action-test (docker version) on: [push] jobs: build-dev-image: @@ -65,7 +65,7 @@ jobs: config: ./.github/workflows/testdata/zero.yml - name: "check: test output values" - if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' }} + if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' || steps.test-1.outputs.report == '' }} run: echo "Previous step should have output values" && exit 1 ## Test 2 diff --git a/.github/workflows/action-source-test.yml b/.github/workflows/action-source-test.yml new file mode 100644 index 0000000..351fa2e --- /dev/null +++ b/.github/workflows/action-source-test.yml @@ -0,0 +1,108 @@ +name: action-test (source version) +on: [push] +jobs: + test: + name: test + runs-on: ubuntu-latest + + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: generate test coverage + run: go test ./... -coverprofile=./cover.out -covermode=atomic + + ## Test 1 + + - name: "test: total coverage 0% (config)" + uses: ./action/. + id: test-1 + with: + version: ${{ github.sha }} + config: ./.github/workflows/testdata/zero.yml + + - name: "check: test output values" + if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' || steps.test-1.outputs.report == '' }} + run: echo "Previous step should have output values" && exit 1 + + ## Test 2 + + - name: "test: total coverage 100% (config)" + uses: ./action/. + id: test-2 + continue-on-error: true + with: + version: ${{ github.sha }} + config: ./.github/workflows/testdata/total100.yml + + - name: "check: test should have failed" + if: steps.test-2.outcome != 'failure' + run: echo "Previous step should have failed" && exit 1 + + - name: "check: test output values" + if: ${{ steps.test-2.outputs.total-coverage == '' || steps.test-2.outputs.badge-text == '' || steps.test-2.outputs.badge-color == '' }} + run: echo "Previous step should have output values" && exit 1 + + ## Test 3 + + - name: "test: total coverage 0% (inputs)" + uses: ./action/. + id: test-3 + with: + version: ${{ github.sha }} + profile: cover.out + threshold-file: 0 + threshold-package: 0 + threshold-total: 0 + + ## Test 4 + + - name: "test: total coverage 100% (inputs)" + uses: ./action/. + id: test-4 + continue-on-error: true + with: + version: ${{ github.sha }} + profile: cover.out + threshold-file: 0 + threshold-package: 0 + threshold-total: 100 + + - name: "check: test should have failed" + if: steps.test-4.outcome != 'failure' + run: echo "Previous step should have failed" && exit 1 + + ## Test 5 + + - name: "test: override config" + uses: ./action/. + id: test-5 + with: + version: ${{ github.sha }} + config: ./.github/workflows/testdata/total100.yml + threshold-file: 0 + threshold-package: 0 + threshold-total: 0 + + ## Test 6 + + - name: "test: debug output" + uses: ./action/. + id: test-6 + continue-on-error: true + with: + version: ${{ github.sha }} + profile: unexistant-profile.out + debug: true + threshold-file: 0 + threshold-package: 0 + threshold-total: 100 + + - name: "check: test should have failed" + if: steps.test-6.outcome != 'failure' + run: echo "Previous step should have failed" && exit 1 \ No newline at end of file diff --git a/action.yml b/action.yml index 33677a5..abfd514 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,10 @@ name: go-test-coverage author: vladopajic description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold. +branding: + icon: 'code' + color: 'blue' + inputs: # Config config: @@ -138,31 +142,27 @@ outputs: runs: using: docker # VERSION: when changing version update version in other places - image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.1 + image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.3 args: - - --config=${{ inputs.config || '''''' }} - - --profile=${{ inputs.profile || '''''' }} - - --source-dir=${{ inputs.source-dir || '''''' }} + - --config=${{ inputs.config || '***' }} + - --profile=${{ inputs.profile || '***' }} + - --source-dir=${{ inputs.source-dir || '***' }} - --debug=${{ inputs.debug }} - --github-action-output=true - --threshold-file=${{ inputs.threshold-file }} - --threshold-package=${{ inputs.threshold-package }} - --threshold-total=${{ inputs.threshold-total }} - - --breakdown-file-name=${{ inputs.breakdown-file-name || '''''' }} - - --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '''''' }} - - --badge-file-name=${{ inputs.badge-file-name || '''''' }} - - --cdn-key=${{ inputs.cdn-key || '''''' }} - - --cdn-secret=${{ inputs.cdn-secret || '''''' }} - - --cdn-region=${{ inputs.cdn-region || '''''' }} - - --cdn-endpoint=${{ inputs.cdn-endpoint || '''''' }} - - --cdn-file-name=${{ inputs.cdn-file-name || '''''' }} - - --cdn-bucket-name=${{ inputs.cdn-bucket-name || '''''' }} + - --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} + - --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} + - --badge-file-name=${{ inputs.badge-file-name || '***' }} + - --cdn-key=${{ inputs.cdn-key || '***' }} + - --cdn-secret=${{ inputs.cdn-secret || '***' }} + - --cdn-region=${{ inputs.cdn-region || '***' }} + - --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} + - --cdn-file-name=${{ inputs.cdn-file-name || '***' }} + - --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} - --cdn-force-path-style=${{ inputs.cdn-force-path-style }} - - --git-token=${{ inputs.git-token || '''''' }} - - --git-branch=${{ inputs.git-branch || '''''' }} - - --git-repository=${{ inputs.git-repository || ''''''}} - - --git-file-name=${{ inputs.git-file-name || '''''' }} - -branding: - icon: 'code' - color: 'blue' \ No newline at end of file + - --git-token=${{ inputs.git-token || '***' }} + - --git-branch=${{ inputs.git-branch || '***' }} + - --git-repository=${{ inputs.git-repository || '***'}} + - --git-file-name=${{ inputs.git-file-name || '***' }} \ No newline at end of file diff --git a/action/action.yml b/action/action.yml new file mode 100644 index 0000000..0375645 --- /dev/null +++ b/action/action.yml @@ -0,0 +1,193 @@ +name: go-test-coverage (as source) +author: vladopajic +description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold. +branding: + icon: 'code' + color: 'blue' + +inputs: + # Config + config: + description: Path to the configuration file (.testcoverage.yml), which defines test coverage settings and thresholds. + required: false + default: "" + type: string + source-dir: + description: Sets relative path to source files. + required: false + default: "" + type: string + debug: + description: Prints additional debugging output when running action. + required: false + default: false + type: boolean + + # Individual properties + profile: + description: Path to the coverage profile file. Overrides value from configuration. + required: false + default: "" + type: string + # DEPRECATED + local-prefix: + description: DEPRECATED! not used anymore. + required: false + default: "" + type: string + threshold-file: + description: Minimum coverage percentage required for individual files. Overrides value from configuration. + required: false + default: -1 + type: number + threshold-package: + description: Minimum coverage percentage required for each package. Overrides value from configuration. + required: false + default: -1 + type: number + threshold-total: + description: Minimum overall project coverage percentage required. Overrides value from configuration. + required: false + default: -1 + type: number + + breakdown-file-name: + description: File name of go-test-coverage breakdown file, which can be used to analyze coverage difference. Overrides value from configuration. + required: false + default: "" + type: string + + diff-base-breakdown-file-name: + description: File name of go-test-coverage breakdown file used to calculate coverage difference from current (head). + required: false + default: "" + type: string + + # Badge (as file) + badge-file-name: + description: If specified, a coverage badge will be generated and saved to the given file path. + required: false + default: "" + type: string + + # Badge (on CDN) + cdn-secret: + description: API secret key for CDN. If specified, the badge will be uploaded to the CDN. + required: false + default: "" + type: string + cdn-key: + description: API key for CDN access. + required: false + default: "" + type: string + cdn-region: + description: Specifies the CDN region for the badge upload. + required: false + default: "" + type: string + cdn-endpoint: + description: URL endpoint for CDN where the badge will be uploaded. + required: false + default: "" + type: string + cdn-file-name: + description: Filename (including path) for storing the badge on the CDN. + required: false + default: "" + type: string + cdn-bucket-name: + description: Name of the CDN bucket where the badge will be saved. + required: false + default: "" + type: string + cdn-force-path-style: + description: Forces path-style URL access in the CDN. + required: false + default: false + type: boolean + + # Badge (on Git) + git-token: + description: GitHub token for authorization. If provided, the badge will be uploaded to the specified GitHub repository. + required: false + default: "" + type: string + git-repository: + description: Target GitHub repository in {owner}/{repository} format where the badge will be stored. + required: false + default: ${{ github.repository }} + type: string + git-branch: + description: Repository branch where the badge file will be saved. + required: false + default: "" + type: string + git-file-name: + description: File name (including path) for storing the badge in the specified repository. + required: false + default: .badges/${{ github.ref_name }}/coverage.svg + type: string + + version: + # VERSION: when changing version update version in other places + description: Version of go-test-coverage source to run + required: false + default: v2.14.3 + type: string + +outputs: + report: + description: JSON-encoded string containing the detailed test coverage report. + value: ${{steps.coverage.outputs.report}} + total-coverage: + description: Integer value in the range [0-100], representing the overall project test coverage percentage. + value: ${{steps.coverage.outputs.total-coverage}} + badge-color: + description: Color hex code for the badge (e.g., `#44cc11`), representing the coverage status. + value: ${{steps.coverage.outputs.badge-color}} + badge-text: + description: Deprecated! Text label for the badge. + value: ${{steps.coverage.outputs.badge-text}} + +runs: + using: composite + steps: + - name: check if go is installed + shell: bash + run: | + if command -v go >/dev/null 2>&1; then + echo "Go is installed" + go version + else + echo "Go is NOT installed. Please install Go before running this action." + exit 1 + fi + + - name: run go-test-coverage + id: coverage + shell: bash + run: | + go run github.com/vladopajic/go-test-coverage/v2@${{ inputs.version }} \ + --config=${{ inputs.config || '***' }} \ + --profile=${{ inputs.profile || '***' }} \ + --source-dir=${{ inputs.source-dir || '***' }} \ + --debug=${{ inputs.debug }} \ + --github-action-output=true \ + --threshold-file=${{ inputs.threshold-file }} \ + --threshold-package=${{ inputs.threshold-package }} \ + --threshold-total=${{ inputs.threshold-total }} \ + --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} \ + --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} \ + --badge-file-name=${{ inputs.badge-file-name || '***' }} \ + --cdn-key=${{ inputs.cdn-key || '***' }} \ + --cdn-secret=${{ inputs.cdn-secret || '***' }} \ + --cdn-region=${{ inputs.cdn-region || '***' }} \ + --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} \ + --cdn-file-name=${{ inputs.cdn-file-name || '***' }} \ + --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} \ + --cdn-force-path-style=${{ inputs.cdn-force-path-style }} \ + --git-token=${{ inputs.git-token || '***' }} \ + --git-branch=${{ inputs.git-branch || '***' }} \ + --git-repository=${{ inputs.git-repository || '***'}} \ + --git-file-name=${{ inputs.git-file-name || '***' }} \ No newline at end of file diff --git a/main_config.go b/main_config.go index c1b5707..fd2061a 100644 --- a/main_config.go +++ b/main_config.go @@ -12,7 +12,7 @@ import ( const ( // default value of string variables passed by CI - ciDefaultString = `''` + ciDefaultString = `***` // default value of int variables passed by CI ciDefaultInt = -1 ) From 7bd2078a792533f17f72b2728664744c4bd2aaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Thu, 5 Jun 2025 12:56:35 +0200 Subject: [PATCH 2/4] nit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b4288b5..dbe6987 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # GO_VERSION: automatically update to most recent via dependabot -FROM golang:1.24.3 as builder +FROM golang:1.24.3 AS builder WORKDIR /workspace COPY go.mod go.mod From b47276ec8bbed8fa802bf802e5284f2dc9cca224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Thu, 5 Jun 2025 13:10:03 +0200 Subject: [PATCH 3/4] update --- action.yml | 2 +- action/{ => source}/action.yml | 2 +- main.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename action/{ => source}/action.yml (98%) diff --git a/action.yml b/action.yml index abfd514..0188e8e 100644 --- a/action.yml +++ b/action.yml @@ -141,7 +141,7 @@ outputs: runs: using: docker - # VERSION: when changing version update version in other places + # TOOL_VERSION: when changing version update version in other places image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.3 args: - --config=${{ inputs.config || '***' }} diff --git a/action/action.yml b/action/source/action.yml similarity index 98% rename from action/action.yml rename to action/source/action.yml index 0375645..6065580 100644 --- a/action/action.yml +++ b/action/source/action.yml @@ -130,9 +130,9 @@ inputs: type: string version: - # VERSION: when changing version update version in other places description: Version of go-test-coverage source to run required: false + # TOOL_VERSION: when changing version update version in other places default: v2.14.3 type: string diff --git a/main.go b/main.go index fbade5f..db720bc 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( ) const ( - Version = "v2.14.3" // VERSION: when changing version update version in other places + Version = "v2.14.3" // TOOL_VERSION: when changing version update version in other places Name = "go-test-coverage" ) From 5e54a43e3d663f47d796f3fccc273fdc828d649c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Thu, 5 Jun 2025 13:11:40 +0200 Subject: [PATCH 4/4] test --- .github/workflows/action-source-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/action-source-test.yml b/.github/workflows/action-source-test.yml index 351fa2e..0c8e4a3 100644 --- a/.github/workflows/action-source-test.yml +++ b/.github/workflows/action-source-test.yml @@ -20,7 +20,7 @@ jobs: ## Test 1 - name: "test: total coverage 0% (config)" - uses: ./action/. + uses: ./action/source/. id: test-1 with: version: ${{ github.sha }} @@ -33,7 +33,7 @@ jobs: ## Test 2 - name: "test: total coverage 100% (config)" - uses: ./action/. + uses: ./action/source/. id: test-2 continue-on-error: true with: @@ -51,7 +51,7 @@ jobs: ## Test 3 - name: "test: total coverage 0% (inputs)" - uses: ./action/. + uses: ./action/source/. id: test-3 with: version: ${{ github.sha }} @@ -63,7 +63,7 @@ jobs: ## Test 4 - name: "test: total coverage 100% (inputs)" - uses: ./action/. + uses: ./action/source/. id: test-4 continue-on-error: true with: @@ -80,7 +80,7 @@ jobs: ## Test 5 - name: "test: override config" - uses: ./action/. + uses: ./action/source/. id: test-5 with: version: ${{ github.sha }} @@ -92,7 +92,7 @@ jobs: ## Test 6 - name: "test: debug output" - uses: ./action/. + uses: ./action/source/. id: test-6 continue-on-error: true with: