-
Notifications
You must be signed in to change notification settings - Fork 2
102 lines (94 loc) · 3.49 KB
/
go-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
# Copyright 2023 The Authors (see AUTHORS file)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: 'go-test'
on:
workflow_call:
inputs:
runs-on:
description: 'The GitHub runner on which to execute. This must be a valid JSON but can represent a string, array of strings, or object.'
type: 'string'
default: '"ubuntu-latest"'
go_version:
description: 'The version of Go to install and use.'
type: 'string'
go_version_file:
description: 'Path to the go.mod file to extract a version.'
type: 'string'
default: 'go.mod'
go_packages:
description: 'List of go packages to test.'
type: 'string'
default: './...'
go_test_timeout:
description: 'Timeout for Go tests.'
type: 'string'
default: '10m'
env:
description: 'JSON-stringified environment variables for tests.'
type: 'string'
default: '{}'
directory:
description: 'Directory to the root of the Go module.'
type: 'string'
default: '.'
jobs:
# test runs the Go test files. It checks out the source code and configures
# the Go runtime. It also generates a coverage report and puts the coverage
# report as a job summary.
#
# By default, it tests all packages, but that can be customized by setting
# "go_packages".
#
# Do not change this job name. Job names are used as identifiers in status
# checks, and changing this name will cause status checks to fail.
test:
runs-on: ${{ fromJSON(inputs.runs-on) }} # yamllint disable-line
steps:
- name: 'Configure environment variables'
if: |-
${{ inputs.env != '{}' }}
# Use bash shell here to make it work with Windows host runner.
shell: 'bash'
run: |-
jq -r "to_entries | map(\"\(.key)=\(.value|tostring)\") | .[]" <<< '${{ inputs.env }}' >> "${GITHUB_ENV}"
- name: 'Checkout'
uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
- name: 'Setup Go'
uses: 'actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b' # ratchet:actions/setup-go@v5
with:
go-version: '${{ inputs.go_version }}'
go-version-file: '${{ inputs.go_version_file }}'
- name: 'Test'
shell: 'bash'
working-directory: '${{ inputs.directory }}'
run: |-
go test \
-count=1 \
-coverprofile=./coverage.out \
-race \
-shuffle=on \
-timeout='${{ inputs.go_test_timeout }}' \
${{ inputs.go_packages }}
- name: 'Coverage'
shell: 'bash'
working-directory: '${{ inputs.directory }}'
run: |-
OUTPUT="$(go tool cover -func=./coverage.out)"
TOTAL="$(echo "${OUTPUT}" | awk 'END{print $NF}')"
tee -a "${GITHUB_STEP_SUMMARY}" > /dev/null <<EOF
## Coverage: ${TOTAL}
\`\`\`text
${OUTPUT}
\`\`\`
EOF