-
Notifications
You must be signed in to change notification settings - Fork 17
224 lines (198 loc) · 6.81 KB
/
tests.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
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
name: Tests
on:
- push
- pull_request
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt install shellcheck
- name: Lint
run: |
make check-lint
- name: Ensure go.mod is up to date
run: |
set -euxo pipefail
# The Launchpad build pipeline will run `go mod tidy`.
#
# Consequently a rebuild could produce a `-dirty` version string if
# any of our dependencies have changed.
#
# While annoying, it is actually a nice feature, because we do want
# to make concious choices about updates to our dependencies.
#
# Check whether a `go mod tidy` would cause go.mod to change and fail
# if it does.
assert_git_status() {
local files="go.mod go.sum"
if [ -n "$(git status --porcelain=v2 $files)" ]; then
echo "files NOT in sync with git: $files"
git status $files
exit 1
else
echo "files in sync with git: $files"
fi
}
cd microovn
assert_git_status
go mod tidy -v -x
assert_git_status
build:
name: build
needs:
- lint
runs-on: ubuntu-latest
env:
MICROOVN_SNAP: microovn.snap
# The `base_ref` will only be set for PR and contain the name of the
# target branch. The `ref_name` will be correct for the final push
# check after a PR is merged.
#
# This setup may lead to failures on push to arbitrarily named branches
# on a fork, but that is a price worth paying.
#
# Contributors can raise a draft PR to get accurate results.
POSSIBLE_TARGET_BRANCH: "${{ github.base_ref || github.ref_name }}"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Clear FORWARD firewall rules
run: |
# Docker can inject rules causing firewall conflicts
sudo iptables -P FORWARD ACCEPT || true
sudo ip6tables -P FORWARD ACCEPT || true
sudo iptables -F FORWARD || true
sudo ip6tables -F FORWARD || true
- name: Install dependencies
run: |
sudo snap refresh
sudo snap set lxd daemon.group=adm
sudo lxd init --auto
test $POSSIBLE_TARGET_BRANCH = main && \
export SNAPCRAFT_CHANNEL=latest/edge
sudo snap install snapcraft \
--channel "${SNAPCRAFT_CHANNEL:-latest/stable}" \
--classic
- name: Build snap
run: |
# Build snap with coverage support
sed -i 's/MICROOVN_COVERAGE=.*/MICROOVN_COVERAGE="yes"/g' microovn/build-aux/environment
make $MICROOVN_SNAP
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: snaps
path: ${{ env.MICROOVN_SNAP }}
retention-days: 5
metadata:
name: Generate matrix
needs:
- build
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate matrix
id: generate-matrix
run: |
MATRIX_JSON="{\"test-file\": ["
TEST_FILES=( $(cd tests; ls -1 *.bats) )
for (( i=0 ; i < "${#TEST_FILES[@]}"; i++ )); do
if [ $i -gt 0 ]; then
MATRIX_JSON+=","
fi
MATRIX_JSON+="\"${TEST_FILES[$i]}\""
done
MATRIX_JSON+="]}"
echo matrix=${MATRIX_JSON} | tee -a ${GITHUB_OUTPUT}
system-tests:
name: System tests
needs:
- metadata
runs-on: ubuntu-latest
env:
MICROOVN_SNAP_PATH: ${{ github.workspace }}/microovn.snap
MICROOVN_SNAP_CHANNEL: 22.03/stable
strategy:
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Download built snap
uses: actions/download-artifact@v4
with:
name: snaps
- name: Clear FORWARD firewall rules
run: |
# Docker can inject rules causing firewall conflicts
sudo iptables -P FORWARD ACCEPT || true
sudo ip6tables -P FORWARD ACCEPT || true
sudo iptables -F FORWARD || true
sudo ip6tables -F FORWARD || true
- name: Install dependencies
run: |
sudo snap refresh
sudo snap set lxd daemon.group=adm
sudo lxd init --auto
snap list
- name: Run system tests
run: MICROOVN_COVERAGE_ENABLED=yes make tests/${{ matrix.test-file }}
- name: Upload test coverage
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.test-file }}_coverage
path: ${{ github.workspace }}/.coverage
include-hidden-files: true
retention-days: 1
generate-coverage:
name: Generate coverage profile
needs:
- metadata
- system-tests
# 'ubuntu-latest' currently resolves to '22.04' [0] and since we require "Go >=1.20"
# for coverage tools, we need to use explicit 'ubuntu-24.04' image name.
# [0] https://github.com/actions/runner-images/issues/10636
runs-on: ubuntu-24.04
env:
COVERAGE_DIR: ${{ github.workspace }}/.coverage
COVERAGE_MERGED: ${{ github.workspace }}/.coverage/_merged
COVERAGE_MERGED_PROFILE: ${{ github.workspace }}/.coverage/_merged/profile.out
steps:
- name: Install dependencies
run: |
sudo apt update
sudo apt install -yqq golang
go install github.com/boumenot/[email protected]
- name: Checkout code
uses: actions/checkout@v4
- name: Download test coverage data
uses: actions/download-artifact@v4
with:
path: ${{ env.COVERAGE_DIR }}
pattern: "*_coverage"
- name: Merge test coverage data
run: |
mkdir -p "$COVERAGE_MERGED"
coverage_inputs=$(find "$COVERAGE_DIR" -type d -name coverage | tr '\n' ',' | sed 's/,$//g')
go tool covdata merge -i="$coverage_inputs" -o="$COVERAGE_MERGED"
go tool covdata textfmt -i="$COVERAGE_MERGED" -o="$COVERAGE_MERGED_PROFILE"
- name: Generate cobertura.xml
run: |
cd microovn/
$HOME/go/bin/gocover-cobertura < "$COVERAGE_MERGED_PROFILE" > "$COVERAGE_DIR/cobertura.xml"
- name: Upload cobertura.xml
uses: actions/upload-artifact@v4
with:
name: cobertura.xml
path: ${{ env.COVERAGE_DIR }}/cobertura.xml
include-hidden-files: true