-
-
Notifications
You must be signed in to change notification settings - Fork 512
155 lines (139 loc) · 6.22 KB
/
ci-test-go.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
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
name: Run tests for a Go project
run-name: "${{ inputs.project-directory }} ${{ inputs.go-version }} ${{ inputs.platform }}"
on:
workflow_call:
inputs:
go-version:
required: true
type: string
description: "The version of Go to use for the test."
platform:
required: true
type: string
description: "The platform to run the test on."
fail-fast:
required: false
type: boolean
default: true
description: "Fail the workflow if any of the jobs fail."
project-directory:
required: true
type: string
default: "."
description: "The directory where the Go project is located."
rootless-docker:
required: false
type: boolean
default: false
description: "Run the test with rootless docker."
run-tests:
required: false
type: boolean
default: true
description: "Run the tests under conditions controlled by the caller workflow."
ryuk-disabled:
required: false
type: boolean
default: false
description: "Disable the ryuk container for the test."
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
test-go-project:
name: "${{ inputs.project-directory }}/${{ inputs.platform }}/${{ inputs.go-version }}"
runs-on: ${{ inputs.platform }}
continue-on-error: ${{ !inputs.fail-fast }}
env:
TESTCONTAINERS_RYUK_DISABLED: "${{ inputs.ryuk-disabled }}"
RYUK_CONNECTION_TIMEOUT: "${{ inputs.project-directory == 'modules/compose' && '5m' || '60s' }}"
RYUK_RECONNECTION_TIMEOUT: "${{ inputs.project-directory == 'modules/compose' && '30s' || '10s' }}"
steps:
- name: Setup rootless Docker
if: ${{ inputs.rootless-docker }}
uses: docker/setup-docker-action@01efb57f882e3b1a22e7cf3501dbe51287b0ecb4 # v4
with:
rootless: true
- name: Check out code into the Go module directory
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Set up Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version: '${{ inputs.go-version }}'
cache-dependency-path: '${{ inputs.project-directory }}/go.sum'
id: go
- name: golangci-lint
if: ${{ inputs.platform == 'ubuntu-latest' }}
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.61.0
# Optional: working directory, useful for monorepos
working-directory: ${{ inputs.project-directory }}
# Optional: golangci-lint command line arguments.
args: --verbose
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
skip-cache: true
- name: generate
if: ${{ inputs.platform == 'ubuntu-latest' }}
working-directory: ./${{ inputs.project-directory }}
shell: bash
run: |
make generate
git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]]
- name: modVerify
working-directory: ./${{ inputs.project-directory }}
run: go mod verify
- name: modTidy
if: ${{ inputs.platform == 'ubuntu-latest' }}
working-directory: ./${{ inputs.project-directory }}
shell: bash
run: |
make tidy
git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]]
- name: ensure compilation
working-directory: ./${{ inputs.project-directory }}
run: go build
- name: Install dependencies
shell: bash
run: |
SCRIPT_PATH="./.github/scripts/${{ inputs.project-directory }}/install-dependencies.sh"
if [ -f "$SCRIPT_PATH" ]; then
$SCRIPT_PATH
else
echo "No dependencies script found at $SCRIPT_PATH - skipping installation"
fi
- name: go test
# only run tests on linux, there are a number of things that won't allow the tests to run on anything else
# many (maybe, all?) images used can only be build on Linux, they don't have Windows in their manifest, and
# we can't put Windows Server in "Linux Mode" in GitHub actions
# another, host mode is only available on Linux, and we have tests around that, do we skip them?
if: ${{ inputs.run-tests }}
working-directory: ./${{ inputs.project-directory }}
timeout-minutes: 30
run: make test-unit
- name: Set sonar artifact name
# For the core library, where the project directory is '.', we'll use "core" as artifact name.
# For the modules, we'll remove the slashes, keeping the name of the module
if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && inputs.platform == 'ubuntu-latest' && inputs.run-tests && !inputs.rootless-docker && !inputs.ryuk-disabled }}
run: |
echo "ARTIFACT_NAME=$(basename ${{ inputs.project-directory == '.' && 'core' || inputs.project-directory }})-${{ inputs.go-version }}-${{ inputs.platform }}" >> $GITHUB_ENV
- name: Upload SonarCloud files
if: ${{ github.ref_name == 'main' && github.repository_owner == 'testcontainers' && inputs.platform == 'ubuntu-latest' && inputs.run-tests && !inputs.rootless-docker && !inputs.ryuk-disabled }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: sonarcloud-${{ env.ARTIFACT_NAME }}
path: |
./sonar-project.properties
${{ inputs.project-directory }}/TEST-unit.xml
${{ inputs.project-directory }}/coverage.out
- name: Run checker
run: |
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
with:
paths: "**/${{ inputs.project-directory }}/TEST-unit*.xml"
if: always()