-
-
Notifications
You must be signed in to change notification settings - Fork 13
130 lines (109 loc) · 3.59 KB
/
action-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: action-test
on: [push]
jobs:
build-dev-image:
name: build dev image
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and push
uses: docker/build-push-action@v6
with:
push: true
build-args: |
VERSION=dev
tags: |
ghcr.io/vladopajic/go-test-coverage:dev
- uses: actions/delete-package-versions@v5
with:
owner: vladopajic
package-name: go-test-coverage
package-type: container
min-versions-to-keep: 5
delete-only-untagged-versions: true
test:
name: test
runs-on: ubuntu-latest
needs: build-dev-image
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
- name: set action image version to dev
run: |
yq e -i '.runs.image = "docker://ghcr.io/vladopajic/go-test-coverage:dev"' action.yml
image=$(yq '.runs.image' action.yml)
echo "Image: $image"
## Test 1
- name: "test: total coverage 0% (config)"
uses: ./
id: test-1
with:
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 == '' }}
shell: bash
run: echo "Previous step should have output values" && exit 1
## Test 2
- name: "test: total coverage 100% (config)"
uses: ./
id: test-2
continue-on-error: true
with:
config: ./.github/workflows/testdata/total100.yml
- name: "check: test should have failed"
if: steps.test-2.outcome != 'failure'
shell: bash
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 == '' }}
shell: bash
run: echo "Previous step should have output values" && exit 1
## Test 3
- name: "test: total coverage 0% (inputs)"
uses: ./
id: test-3
with:
profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold-file: 0
threshold-package: 0
threshold-total: 0
## Test 4
- name: "test: total coverage 100% (inputs)"
uses: ./
id: test-4
continue-on-error: true
with:
profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold-file: 0
threshold-package: 0
threshold-total: 100
- name: "check: test should have failed"
if: steps.test-4.outcome != 'failure'
shell: bash
run: echo "Previous step should have failed" && exit 1
## Test 5
- name: "test: override config"
uses: ./
id: test-5
with:
config: ./.github/workflows/testdata/total100.yml
threshold-file: 0
threshold-package: 0
threshold-total: 0