-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (151 loc) · 4.81 KB
/
Copy pathgoTest.yml
File metadata and controls
155 lines (151 loc) · 4.81 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
on:
workflow_call:
inputs:
runs-on:
required: false
type: string
default: ubuntu-latest
goprivate:
required: false
type: string
default: go.step.sm/,github.com/smallstep/
gotestsum-version:
required: false
type: string
default: "1.12.3"
only-latest-golang:
required: false
type: boolean
default: true
os-dependencies:
required: false
type: string
run-codecov:
required: false
type: boolean
default: true
setup-bats:
required: false
type: boolean
default: false
test-command:
required: false
type: string
default: "gotestsum -- -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./..."
secrets:
SSH_PRIVATE_KEY:
required: false
PAT:
required: false
CODECOV_TOKEN:
required: false
permissions:
contents: read
jobs:
set-go-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-output.outputs.matrix }}
steps:
- name: Set go-matrix latest version
id: set-matrix-latest
if: inputs.only-latest-golang
run: |
echo 'matrix={"include":[{"go":"\"stable\""}]}' >> "${GITHUB_ENV}"
- name: Set default go-matrix
id: set-matrix-default
if: inputs.only-latest-golang == false
run: |
echo 'matrix={"include":[{"go":"\"stable\""},{"go":"\"oldstable\""}]}' >> "${GITHUB_ENV}"
- id: set-output
run: |
echo "matrix=${{ env.matrix }}" >> "${GITHUB_OUTPUT}"
test:
needs: set-go-matrix
runs-on: ${{ inputs.runs-on }}
env:
GOPRIVATE: ${{ inputs.goprivate }}
strategy:
matrix: ${{ fromJson(needs.set-go-matrix.outputs.matrix) }}
steps:
- name: Install Dependencies
if: inputs.os-dependencies != ''
shell: bash
env:
OS_DEPS: ${{ inputs.os-dependencies }}
run: |
case "${RUNNER_OS}" in
Linux)
sudo apt-get update
# shellcheck disable=SC2086
sudo apt-get install -y ${OS_DEPS}
;;
macOS)
# shellcheck disable=SC2086
brew install ${OS_DEPS}
;;
Windows)
# shellcheck disable=SC2086
choco install -y ${OS_DEPS}
;;
*)
echo "unsupported RUNNER_OS=${RUNNER_OS}" >&2
exit 1
;;
esac
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
submodules: true
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Reconfigure for Git go.step.sm
if: env.PAT != ''
env:
PAT: ${{ secrets.PAT }}
run: |
git config --global url.https://${{ secrets.PAT }}@github.com/.insteadOf git+ssh://git@github.com
git config --global url.git@github.com:.insteadOf https://github.com/
- name: Setup Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version: ${{ matrix.go }}
check-latest: true
cache: true
cache-dependency-path: "**/go.sum"
- name: Setup SSH key for private dependencies
uses: webfactory/ssh-agent@e83874834305fe9a4a2997156cb26c5de65a8555 # v0.10.0
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
if: env.SSH_PRIVATE_KEY != ''
with:
ssh-private-key: |
${{ secrets.SSH_PRIVATE_KEY }}
- name: Install gotestsum
shell: bash
env:
GOTESTSUM_VERSION: ${{ inputs.gotestsum-version }}
run: go install "gotest.tools/gotestsum@v${GOTESTSUM_VERSION}"
- name: Setup BATS
if: inputs.setup-bats
uses: mig4/setup-bats@af9a00deb21b5d795cabfeaa8d9060410377686d # v1.2.0
with:
bats-version: 1.9.0
- name: Run Test Suite
shell: bash
env:
TEST_CMD: ${{ inputs.test-command }}
GOTESTSUM_JSONFILE: gotestsum.json
run: eval "${TEST_CMD}"
- name: Annotate Test Suite Results
if: ${{ (success() || failure()) && hashFiles('gotestsum.json') != '' }}
uses: guyarb/golang-test-annotations@96fc379b171c49932041d6c789e73331a7bdeec1 # v0.9.0
with:
test-results: gotestsum.json
- name: Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: inputs.run-codecov && matrix.go == 'stable'
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out # optional
name: codecov-umbrella # optional
fail_ci_if_error: false # optional (default = false)