Skip to content

Commit f641069

Browse files
committed
souce action
1 parent dd70f04 commit f641069

File tree

5 files changed

+325
-24
lines changed

5 files changed

+325
-24
lines changed

.github/workflows/action-test.yml renamed to .github/workflows/action-docker-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: action-test
1+
name: action-test (docker version)
22
on: [push]
33
jobs:
44
build-dev-image:
@@ -65,7 +65,7 @@ jobs:
6565
config: ./.github/workflows/testdata/zero.yml
6666

6767
- name: "check: test output values"
68-
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' }}
68+
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' || steps.test-1.outputs.report == '' }}
6969
run: echo "Previous step should have output values" && exit 1
7070

7171
## Test 2
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: action-test (source version)
2+
on: [push]
3+
jobs:
4+
test:
5+
name: test
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: checkout
10+
uses: actions/checkout@v4
11+
12+
- name: setup go
13+
uses: actions/setup-go@v5
14+
with:
15+
go-version-file: go.mod
16+
17+
- name: generate test coverage
18+
run: go test ./... -coverprofile=./cover.out -covermode=atomic
19+
20+
## Test 1
21+
22+
- name: "test: total coverage 0% (config)"
23+
uses: ./action/.
24+
id: test-1
25+
with:
26+
version: ${{ github.sha }}
27+
config: ./.github/workflows/testdata/zero.yml
28+
29+
- name: "check: test output values"
30+
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' || steps.test-1.outputs.report == '' }}
31+
run: echo "Previous step should have output values" && exit 1
32+
33+
## Test 2
34+
35+
- name: "test: total coverage 100% (config)"
36+
uses: ./action/.
37+
id: test-2
38+
continue-on-error: true
39+
with:
40+
version: ${{ github.sha }}
41+
config: ./.github/workflows/testdata/total100.yml
42+
43+
- name: "check: test should have failed"
44+
if: steps.test-2.outcome != 'failure'
45+
run: echo "Previous step should have failed" && exit 1
46+
47+
- name: "check: test output values"
48+
if: ${{ steps.test-2.outputs.total-coverage == '' || steps.test-2.outputs.badge-text == '' || steps.test-2.outputs.badge-color == '' }}
49+
run: echo "Previous step should have output values" && exit 1
50+
51+
## Test 3
52+
53+
- name: "test: total coverage 0% (inputs)"
54+
uses: ./action/.
55+
id: test-3
56+
with:
57+
version: ${{ github.sha }}
58+
profile: cover.out
59+
threshold-file: 0
60+
threshold-package: 0
61+
threshold-total: 0
62+
63+
## Test 4
64+
65+
- name: "test: total coverage 100% (inputs)"
66+
uses: ./action/.
67+
id: test-4
68+
continue-on-error: true
69+
with:
70+
version: ${{ github.sha }}
71+
profile: cover.out
72+
threshold-file: 0
73+
threshold-package: 0
74+
threshold-total: 100
75+
76+
- name: "check: test should have failed"
77+
if: steps.test-4.outcome != 'failure'
78+
run: echo "Previous step should have failed" && exit 1
79+
80+
## Test 5
81+
82+
- name: "test: override config"
83+
uses: ./action/.
84+
id: test-5
85+
with:
86+
version: ${{ github.sha }}
87+
config: ./.github/workflows/testdata/total100.yml
88+
threshold-file: 0
89+
threshold-package: 0
90+
threshold-total: 0
91+
92+
## Test 6
93+
94+
- name: "test: debug output"
95+
uses: ./action/.
96+
id: test-6
97+
continue-on-error: true
98+
with:
99+
version: ${{ github.sha }}
100+
profile: unexistant-profile.out
101+
debug: true
102+
threshold-file: 0
103+
threshold-package: 0
104+
threshold-total: 100
105+
106+
- name: "check: test should have failed"
107+
if: steps.test-6.outcome != 'failure'
108+
run: echo "Previous step should have failed" && exit 1

action.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: go-test-coverage
22
author: vladopajic
33
description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold.
4+
branding:
5+
icon: 'code'
6+
color: 'blue'
7+
48
inputs:
59
# Config
610
config:
@@ -138,31 +142,27 @@ outputs:
138142
runs:
139143
using: docker
140144
# VERSION: when changing version update version in other places
141-
image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.1
145+
image: docker://ghcr.io/vladopajic/go-test-coverage:v2.14.3
142146
args:
143-
- --config=${{ inputs.config || '''''' }}
144-
- --profile=${{ inputs.profile || '''''' }}
145-
- --source-dir=${{ inputs.source-dir || '''''' }}
147+
- --config=${{ inputs.config || '***' }}
148+
- --profile=${{ inputs.profile || '***' }}
149+
- --source-dir=${{ inputs.source-dir || '***' }}
146150
- --debug=${{ inputs.debug }}
147151
- --github-action-output=true
148152
- --threshold-file=${{ inputs.threshold-file }}
149153
- --threshold-package=${{ inputs.threshold-package }}
150154
- --threshold-total=${{ inputs.threshold-total }}
151-
- --breakdown-file-name=${{ inputs.breakdown-file-name || '''''' }}
152-
- --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '''''' }}
153-
- --badge-file-name=${{ inputs.badge-file-name || '''''' }}
154-
- --cdn-key=${{ inputs.cdn-key || '''''' }}
155-
- --cdn-secret=${{ inputs.cdn-secret || '''''' }}
156-
- --cdn-region=${{ inputs.cdn-region || '''''' }}
157-
- --cdn-endpoint=${{ inputs.cdn-endpoint || '''''' }}
158-
- --cdn-file-name=${{ inputs.cdn-file-name || '''''' }}
159-
- --cdn-bucket-name=${{ inputs.cdn-bucket-name || '''''' }}
155+
- --breakdown-file-name=${{ inputs.breakdown-file-name || '***' }}
156+
- --diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }}
157+
- --badge-file-name=${{ inputs.badge-file-name || '***' }}
158+
- --cdn-key=${{ inputs.cdn-key || '***' }}
159+
- --cdn-secret=${{ inputs.cdn-secret || '***' }}
160+
- --cdn-region=${{ inputs.cdn-region || '***' }}
161+
- --cdn-endpoint=${{ inputs.cdn-endpoint || '***' }}
162+
- --cdn-file-name=${{ inputs.cdn-file-name || '***' }}
163+
- --cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }}
160164
- --cdn-force-path-style=${{ inputs.cdn-force-path-style }}
161-
- --git-token=${{ inputs.git-token || '''''' }}
162-
- --git-branch=${{ inputs.git-branch || '''''' }}
163-
- --git-repository=${{ inputs.git-repository || ''''''}}
164-
- --git-file-name=${{ inputs.git-file-name || '''''' }}
165-
166-
branding:
167-
icon: 'code'
168-
color: 'blue'
165+
- --git-token=${{ inputs.git-token || '***' }}
166+
- --git-branch=${{ inputs.git-branch || '***' }}
167+
- --git-repository=${{ inputs.git-repository || '***'}}
168+
- --git-file-name=${{ inputs.git-file-name || '***' }}

action/action.yml

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
name: go-test-coverage (as source)
2+
author: vladopajic
3+
description: go-test-coverage is a tool designed to report issues when test coverage falls below a specified threshold.
4+
branding:
5+
icon: 'code'
6+
color: 'blue'
7+
8+
inputs:
9+
# Config
10+
config:
11+
description: Path to the configuration file (.testcoverage.yml), which defines test coverage settings and thresholds.
12+
required: false
13+
default: ""
14+
type: string
15+
source-dir:
16+
description: Sets relative path to source files.
17+
required: false
18+
default: ""
19+
type: string
20+
debug:
21+
description: Prints additional debugging output when running action.
22+
required: false
23+
default: false
24+
type: boolean
25+
26+
# Individual properties
27+
profile:
28+
description: Path to the coverage profile file. Overrides value from configuration.
29+
required: false
30+
default: ""
31+
type: string
32+
# DEPRECATED
33+
local-prefix:
34+
description: DEPRECATED! not used anymore.
35+
required: false
36+
default: ""
37+
type: string
38+
threshold-file:
39+
description: Minimum coverage percentage required for individual files. Overrides value from configuration.
40+
required: false
41+
default: -1
42+
type: number
43+
threshold-package:
44+
description: Minimum coverage percentage required for each package. Overrides value from configuration.
45+
required: false
46+
default: -1
47+
type: number
48+
threshold-total:
49+
description: Minimum overall project coverage percentage required. Overrides value from configuration.
50+
required: false
51+
default: -1
52+
type: number
53+
54+
breakdown-file-name:
55+
description: File name of go-test-coverage breakdown file, which can be used to analyze coverage difference. Overrides value from configuration.
56+
required: false
57+
default: ""
58+
type: string
59+
60+
diff-base-breakdown-file-name:
61+
description: File name of go-test-coverage breakdown file used to calculate coverage difference from current (head).
62+
required: false
63+
default: ""
64+
type: string
65+
66+
# Badge (as file)
67+
badge-file-name:
68+
description: If specified, a coverage badge will be generated and saved to the given file path.
69+
required: false
70+
default: ""
71+
type: string
72+
73+
# Badge (on CDN)
74+
cdn-secret:
75+
description: API secret key for CDN. If specified, the badge will be uploaded to the CDN.
76+
required: false
77+
default: ""
78+
type: string
79+
cdn-key:
80+
description: API key for CDN access.
81+
required: false
82+
default: ""
83+
type: string
84+
cdn-region:
85+
description: Specifies the CDN region for the badge upload.
86+
required: false
87+
default: ""
88+
type: string
89+
cdn-endpoint:
90+
description: URL endpoint for CDN where the badge will be uploaded.
91+
required: false
92+
default: ""
93+
type: string
94+
cdn-file-name:
95+
description: Filename (including path) for storing the badge on the CDN.
96+
required: false
97+
default: ""
98+
type: string
99+
cdn-bucket-name:
100+
description: Name of the CDN bucket where the badge will be saved.
101+
required: false
102+
default: ""
103+
type: string
104+
cdn-force-path-style:
105+
description: Forces path-style URL access in the CDN.
106+
required: false
107+
default: false
108+
type: boolean
109+
110+
# Badge (on Git)
111+
git-token:
112+
description: GitHub token for authorization. If provided, the badge will be uploaded to the specified GitHub repository.
113+
required: false
114+
default: ""
115+
type: string
116+
git-repository:
117+
description: Target GitHub repository in {owner}/{repository} format where the badge will be stored.
118+
required: false
119+
default: ${{ github.repository }}
120+
type: string
121+
git-branch:
122+
description: Repository branch where the badge file will be saved.
123+
required: false
124+
default: ""
125+
type: string
126+
git-file-name:
127+
description: File name (including path) for storing the badge in the specified repository.
128+
required: false
129+
default: .badges/${{ github.ref_name }}/coverage.svg
130+
type: string
131+
132+
version:
133+
# VERSION: when changing version update version in other places
134+
description: Version of go-test-coverage source to run
135+
required: false
136+
default: v2.14.3
137+
type: string
138+
139+
outputs:
140+
report:
141+
description: JSON-encoded string containing the detailed test coverage report.
142+
value: ${{steps.coverage.outputs.report}}
143+
total-coverage:
144+
description: Integer value in the range [0-100], representing the overall project test coverage percentage.
145+
value: ${{steps.coverage.outputs.total-coverage}}
146+
badge-color:
147+
description: Color hex code for the badge (e.g., `#44cc11`), representing the coverage status.
148+
value: ${{steps.coverage.outputs.badge-color}}
149+
badge-text:
150+
description: Deprecated! Text label for the badge.
151+
value: ${{steps.coverage.outputs.badge-text}}
152+
153+
runs:
154+
using: composite
155+
steps:
156+
- name: check if go is installed
157+
shell: bash
158+
run: |
159+
if command -v go >/dev/null 2>&1; then
160+
echo "Go is installed"
161+
go version
162+
else
163+
echo "Go is NOT installed. Please install Go before running this action."
164+
exit 1
165+
fi
166+
167+
- name: run go-test-coverage
168+
id: coverage
169+
shell: bash
170+
run: |
171+
go run github.com/vladopajic/go-test-coverage/v2@${{ inputs.version }} \
172+
--config=${{ inputs.config || '***' }} \
173+
--profile=${{ inputs.profile || '***' }} \
174+
--source-dir=${{ inputs.source-dir || '***' }} \
175+
--debug=${{ inputs.debug }} \
176+
--github-action-output=true \
177+
--threshold-file=${{ inputs.threshold-file }} \
178+
--threshold-package=${{ inputs.threshold-package }} \
179+
--threshold-total=${{ inputs.threshold-total }} \
180+
--breakdown-file-name=${{ inputs.breakdown-file-name || '***' }} \
181+
--diff-base-breakdown-file-name=${{ inputs.diff-base-breakdown-file-name || '***' }} \
182+
--badge-file-name=${{ inputs.badge-file-name || '***' }} \
183+
--cdn-key=${{ inputs.cdn-key || '***' }} \
184+
--cdn-secret=${{ inputs.cdn-secret || '***' }} \
185+
--cdn-region=${{ inputs.cdn-region || '***' }} \
186+
--cdn-endpoint=${{ inputs.cdn-endpoint || '***' }} \
187+
--cdn-file-name=${{ inputs.cdn-file-name || '***' }} \
188+
--cdn-bucket-name=${{ inputs.cdn-bucket-name || '***' }} \
189+
--cdn-force-path-style=${{ inputs.cdn-force-path-style }} \
190+
--git-token=${{ inputs.git-token || '***' }} \
191+
--git-branch=${{ inputs.git-branch || '***' }} \
192+
--git-repository=${{ inputs.git-repository || '***'}} \
193+
--git-file-name=${{ inputs.git-file-name || '***' }}

main_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const (
1414
// default value of string variables passed by CI
15-
ciDefaultString = `''`
15+
ciDefaultString = `***`
1616
// default value of int variables passed by CI
1717
ciDefaultInt = -1
1818
)

0 commit comments

Comments
 (0)