Skip to content

Commit d6e4b38

Browse files
authored
integration test improvements (#9)
1 parent e5a52ef commit d6e4b38

File tree

6 files changed

+51
-36
lines changed

6 files changed

+51
-36
lines changed

.github/workflows/.testcoverage.yml renamed to .github/.testcoverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local-prefix: "github.com/vladopajic/go-test-coverage"
66
threshold:
77
file: 0
88
package: 0
9-
total: 63
9+
total: 65

.github/workflows/integration-test.yml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@ jobs:
1010
steps:
1111
- name: checkout
1212
uses: actions/checkout@v3
13+
1314
- name: setup go
1415
uses: actions/setup-go@v3
1516
with:
1617
go-version-file: go.mod
1718

18-
- name: Set action image version to dev
19+
- name: set action image version to dev
1920
run: |
2021
yq e -i '.runs.image = "docker://ghcr.io/vladopajic/go-test-coverage:dev"' action.yml
2122
image=$(yq '.runs.image' action.yml)
2223
echo "Image: $image"
2324
24-
- name: Setup buildx
25-
uses: docker/setup-buildx-action@v2
26-
27-
- name: Login to GitHub container registry
25+
- name: login to GitHub container registry
2826
uses: docker/login-action@v2
2927
with:
3028
registry: ghcr.io
3129
username: ${{ github.repository_owner }}
3230
password: ${{ secrets.GITHUB_TOKEN }}
3331

34-
- name: Build and push
32+
- name: build and push
3533
uses: docker/build-push-action@v4
3634
with:
3735
push: true
@@ -43,37 +41,55 @@ jobs:
4341
- name: generate test coverage
4442
run: go test ./... -coverprofile=./cover.out -covermode=atomic
4543

46-
- name: Test total coverage 0% (config)
44+
## Test 1
45+
46+
- name: "test: total coverage 0% (config)"
4747
uses: ./
48+
id: test-1
4849
with:
4950
config: ./.github/workflows/testdata/zero.yml
51+
52+
- name: "check: test output values"
53+
if: ${{ steps.test-1.outputs.total-coverage == '' || steps.test-1.outputs.badge-text == '' || steps.test-1.outputs.badge-color == '' }}
54+
shell: bash
55+
run: echo "Previous step should have output values" && exit 1
56+
57+
## Test 2
5058

51-
- name: Test total coverage 100% (config)
59+
- name: "test: total coverage 100% (config)"
5260
uses: ./
53-
id: should-fail-1
61+
id: test-2
5462
continue-on-error: true
5563
with:
5664
config: ./.github/workflows/testdata/total100.yml
5765

58-
- name: Check previous step failed
59-
if: steps.should-fail-1.outcome != 'failure'
66+
- name: "check: test should have failed"
67+
if: steps.test-2.outcome != 'failure'
6068
shell: bash
61-
run: |
62-
echo "Previous step should have failed"
63-
exit 1
69+
run: echo "Previous step should have failed" && exit 1
70+
71+
- name: "check: test output values"
72+
if: ${{ steps.test-2.outputs.total-coverage == '' || steps.test-2.outputs.badge-text == '' || steps.test-2.outputs.badge-color == '' }}
73+
shell: bash
74+
run: echo "Previous step should have output values" && exit 1
6475

65-
- name: Test total coverage 0% (inputs)
76+
## Test 3
77+
78+
- name: "test: total coverage 0% (inputs)"
6679
uses: ./
80+
id: test-3
6781
with:
6882
profile: cover.out
6983
local-prefix: "github.com/vladopajic/go-test-coverage"
7084
threshold-file: 0
7185
threshold-package: 0
7286
threshold-total: 0
7387

74-
- name: Test total coverage 100% (inputs)
88+
## Test 4
89+
90+
- name: "test: total coverage 100% (inputs)"
7591
uses: ./
76-
id: should-fail-2
92+
id: test-4
7793
continue-on-error: true
7894
with:
7995
profile: cover.out
@@ -82,9 +98,7 @@ jobs:
8298
threshold-package: 0
8399
threshold-total: 100
84100

85-
- name: Check previous step failed
86-
if: steps.should-fail-2.outcome != 'failure'
101+
- name: "check: test should have failed"
102+
if: steps.test-4.outcome != 'failure'
87103
shell: bash
88-
run: |
89-
echo "Previous step should have failed"
90-
exit 1
104+
run: echo "Previous step should have failed" && exit 1

.github/workflows/release.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,31 @@ jobs:
1717
with:
1818
go-version-file: go.mod
1919

20-
- name: Set RELEASE_VERSION ENV var
20+
- name: set RELEASE_VERSION ENV var
2121
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
2222

23-
- name: Ensure container version is updated to release version
23+
- name: ensure container version is updated to release version
2424
run: |
2525
image=$(yq '.runs.image' action.yml)
2626
echo "Image: $image"
2727
imageVer=${image:(-6)}
2828
echo "Image version: $imageVer, Release version: ${{ env.RELEASE_VERSION }}"
2929
[[ "$imageVer" == "${{ env.RELEASE_VERSION }}" ]]
3030
31-
- name: Update the major version tag
31+
- name: update the major version tag
3232
id: majorver
3333
uses: actions/[email protected]
3434
with:
3535
source-tag: ${{ env.RELEASE_VERSION }}
3636

37-
- name: Setup buildx
38-
uses: docker/setup-buildx-action@v2
39-
40-
- name: Login to GitHub container registry
37+
- name: login to GitHub container registry
4138
uses: docker/login-action@v2
4239
with:
4340
registry: ghcr.io
4441
username: ${{ github.repository_owner }}
4542
password: ${{ secrets.GITHUB_TOKEN }}
4643

47-
- name: Build and push
44+
- name: build and push
4845
uses: docker/build-push-action@v4
4946
with:
5047
push: true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
id: coverage
2222
uses: vladopajic/go-test-coverage@v2
2323
with:
24-
config: ./.github/workflows/.testcoverage.yml
24+
config: ./.github/.testcoverage.yml
2525
- name: make coverage badge
2626
uses: action-badges/[email protected]
2727
if: contains(github.ref, 'main')

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ inputs:
3333
default: 50
3434
type: number
3535
outputs:
36-
total_coverage:
36+
total-coverage:
3737
description: Holds total coverage value.
38+
badge-text:
39+
description: Holds badge text value.
40+
badge-color:
41+
description: Holds badge color value.
3842
runs:
3943
using: docker
4044
image: docker://ghcr.io/vladopajic/go-test-coverage:v2.0.0

pkg/testcoverage/report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func ReportForGithubAction(w io.Writer, result AnalyzeResult, cfg Config) {
9999

100100
const (
101101
gaOutputFileEnv = "GITHUB_OUTPUT"
102-
gaOutputTotalCoverage = "total_coverage"
103-
gaOutputBadgeColor = "badge_color"
104-
gaOutputBadgeText = "badge_text"
102+
gaOutputTotalCoverage = "total-coverage"
103+
gaOutputBadgeColor = "badge-color"
104+
gaOutputBadgeText = "badge-text"
105105
)
106106

107107
func SetGithubActionOutput(result AnalyzeResult) error {

0 commit comments

Comments
 (0)