-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (192 loc) · 7.59 KB
/
pre-main.yaml
File metadata and controls
231 lines (192 loc) · 7.59 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Test Incoming Changes
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
env:
REGISTRY: quay.io
REGISTRY_LOCAL: localhost
IMAGE_NAME: testnetworkfunction/test-network-function
IMAGE_TAG: unstable
TNF_CONTAINER_CLIENT: docker
TNF_NON_INTRUSIVE_ONLY: false
TNF_DISABLE_CONFIG_AUTODISCOVER: false
TNF_CONFIG_DIR: /tmp/tnf/config
TNF_OUTPUT_DIR: /tmp/tnf/output
TNF_SRC_URL: 'https://github.com/${{ github.repository }}'
TESTING_CMD_PARAMS: '-n host -i ${REGISTRY_LOCAL}/${IMAGE_NAME}:${IMAGE_TAG} -t ${TNF_CONFIG_DIR} -o ${TNF_OUTPUT_DIR}'
TNF_PARTNER_DIR: '/usr/tnf-partner'
TNF_PARTNER_SRC_DIR: '${TNF_PARTNER_DIR}/src'
TERM: xterm-color
jobs:
lint:
name: Run Linter and Vet
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17.8
- name: Disable default go problem matcher
run: echo "::remove-matcher owner=go::"
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
- name: Rebuild mocks
run: go install github.com/golang/mock/mockgen@v1.6.0 && make mocks
# TODO: golangci-lint team recommends using a GitHub Action to perform golangci-lint responsibilities. However
# there does not appear to be a way to honor our existing .golangci.yml. For now, mimic developer behavior.
- name: Install golangci-lint
run: make install-lint
- name: make lint
run: make lint
- name: make vet
run: make vet
yamllint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
config_data: |
extends: default
rules:
line-length:
level: warning
trailing-spaces:
level: warning
brackets:
level: warning
empty-lines:
level: warning
unit-tests:
name: Run Unit Tests
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17.8
- name: Disable default go problem matcher
run: echo "::remove-matcher owner=go::"
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
- name: Rebuild mocks
run: go install github.com/golang/mock/mockgen@v1.6.0 && make mocks
- name: Run Tests
run: make test
env:
SHELL: /bin/bash
- name: Quality Gate - Test coverage shall be above threshold
env:
TESTCOVERAGE_THRESHOLD: 50
run: |
echo "Quality Gate: checking test coverage is above threshold ..."
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
totalCoverage=`UNIT_TEST='true' go tool cover -func=cover.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "OK"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Failed"
exit 1
fi
smoke-tests:
name: Run Smoke Tests
runs-on: ubuntu-20.04
env:
SHELL: /bin/bash
KUBECONFIG: '/home/runner/.kube/config'
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17.8
- name: Disable default go problem matcher
run: echo "::remove-matcher owner=go::"
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
- name: Execute `make mocks`
run: go install github.com/golang/mock/mockgen@v1.6.0 && make mocks
- name: Install ginkgo
run: go install github.com/onsi/ginkgo/ginkgo@v1.16.5
- name: Execute `make build`
run: make build
# Create a minikube cluster for testing.
- name: Check out `cnf-certification-test-partner`
uses: actions/checkout@v2
with:
repository: test-network-function/cnf-certification-test-partner
path: cnf-certification-test-partner
- name: Start the minikube cluster for `local-test-infra`
uses: ./cnf-certification-test-partner/.github/actions/start-k8s-cluster
with:
working_directory: cnf-certification-test-partner
- name: Create `local-test-infra` OpenShift resources
uses: ./cnf-certification-test-partner/.github/actions/create-local-test-infra-resources
with:
working_directory: cnf-certification-test-partner
# Perform smoke tests.
- name: 'Test: Run test suites'
run: ./run-cnf-suites.sh --focus access-control lifecycle platform observability networking affiliated-certification operator
- name: Upload smoke test results as an artifact
uses: actions/upload-artifact@v2
if: always()
with:
name: smoke-tests
path: |
test-network-function/*.xml
test-network-function/claim.json
test-network-function/claimjson.js
test-network-function/results.html
# Perform smoke tests using a TNF container.
- name: Build the `test-network-function` image
run: |
docker build --no-cache \
-t ${REGISTRY_LOCAL}/${IMAGE_NAME}:${IMAGE_TAG} \
-t ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} \
--build-arg TNF_VERSION=${COMMIT_SHA} \
--build-arg TNF_SRC_URL=${TNF_SRC_URL} .
env:
COMMIT_SHA: ${{ github.sha }}
- name: Create required TNF config files and directories
run: |
mkdir -p $TNF_CONFIG_DIR $TNF_OUTPUT_DIR
cp test-network-function/*.yml $TNF_CONFIG_DIR
shell: bash
- name: 'Test: Run without any TS, just get diagnostic information'
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }}
- name: 'Test: Run generic test suite in a TNF container'
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -f access-control lifecycle platform observability networking affiliated-certification operator
- name: Upload container test results as an artifact
uses: actions/upload-artifact@v2
if: always()
with:
name: smoke-tests-container
path: |
${{ env.TNF_OUTPUT_DIR }}/*.xml
${{ env.TNF_OUTPUT_DIR }}/claim.json
${{ env.TNF_OUTPUT_DIR }}/claimjson.js
${{ env.TNF_OUTPUT_DIR }}/results.html
# Push the new unstable TNF image to Quay.io.
- name: (if on main and upstream) Authenticate against Quay.io
if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'test-network-function' }}
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
# Use a Robot Account to authenticate against Quay.io
# https://docs.quay.io/glossary/robot-accounts.html
username: ${{ secrets.QUAY_ROBOT_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
- name: (if on main and upstream) Push the newly built image to Quay.io
if: ${{ github.ref == 'refs/heads/main' && github.repository_owner == 'test-network-function' }}
run: docker push --all-tags ${REGISTRY}/${IMAGE_NAME}