-
Notifications
You must be signed in to change notification settings - Fork 22
200 lines (198 loc) · 6.61 KB
/
tests.yaml
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
name: tests
on:
push:
branches:
- "main"
- "feature/*"
- "hotfix/*"
- "release/*"
pull_request:
# Allows triggering the workflow manually from the Actions tab
workflow_dispatch:
inputs:
enable_ssh_access:
type: boolean
description: 'Enable ssh access'
required: false
default: false
jobs:
linters:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: Configure environment
run: |
echo "::group::Begin snap install"
echo "Installing snaps in the background while running apt and pip..."
sudo snap install --no-wait --classic pyright
sudo snap install --no-wait shellcheck
echo "::endgroup::"
echo "::group::pip install"
python -m pip install 'tox>=4'
echo "::endgroup::"
echo "::group::Create virtual environments for linting processes."
tox run -m lint --notest
echo "::endgroup::"
echo "::group::Wait for snap to complete"
snap watch --last=install
echo "::endgroup::"
- name: Enable ssh access
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.enable_ssh_access }}
with:
limit-access-to-actor: true
- name: Run Linters
run: tox run --skip-pkg-install --no-list-dependencies -m lint
unit-tests:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python versions on ${{ matrix.platform }}
uses: actions/setup-python@v4
with:
python-version: |
3.8
3.9
3.10
3.11
3.12-dev
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install 'tox>=4.6'
echo "::endgroup::"
mkdir -p results
- name: Setup Tox environments
run: tox run -m unit-tests --notest
- name: Enable ssh access
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.enable_ssh_access }}
with:
limit-access-to-actor: true
- name: Test with tox
# use `tox` instead of `.tox/.tox/bin/tox` to support Windows
run: tox run --skip-pkg-install --no-list-dependencies --result-json results/tox-${{ matrix.platform }}.json -m unit-tests
env:
PYTEST_ADDOPTS: "--no-header -vv -rN"
- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
directory: ./results/
files: coverage*.xml
- name: Upload test results
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.platform }}
path: results/
integration-tests-linux:
strategy:
matrix:
python: [
{system-version: "3.8", tox-version: "py3.8"},
{system-version: "3.10", tox-version: "py3.10"},
{system-version: "3.11", tox-version: "py3.11"},
{system-version: "3.12-dev", tox-version: "py3.12"},
]
# does not work with canonical/setup-lxd github action (see https://github.com/canonical/craft-providers/issues/271)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.system-version }}
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install 'tox>=4.6'
echo "::endgroup::"
echo "::group::Configure LXD"
sudo groupadd --force --system lxd
sudo usermod --append --groups lxd $USER
sudo snap refresh lxd --channel=latest/stable
sudo snap start lxd
sudo lxd waitready --timeout=30
sudo lxd init --auto
# iptables calls from https://github.com/canonical/setup-lxd/blob/main/action.yml
sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT
sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
echo "::endgroup::"
- name: Setup Tox environments
run: tox run -e integration-${{ matrix.python.tox-version }} --notest
- name: Enable ssh access
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.enable_ssh_access }}
with:
limit-access-to-actor: true
- name: Run integration tests on Linux
env:
CRAFT_PROVIDERS_TESTS_ENABLE_SNAP_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_LXD_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_LXD_UNINSTALL: 1
PYTEST_ADDOPTS: "--no-header -vv -rN"
run: |
sg lxd -c "lxc version"
sg lxd -c ".tox/.tox/bin/tox run --skip-pkg-install --no-list-dependencies -e integration-${{ matrix.python.tox-version }}"
integration-tests-macos:
strategy:
matrix:
python: ["3.11"]
runs-on: macos-latest
steps:
- name: Install Multipass
run: |
brew update
brew install multipass
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install 'tox>=4.6'
echo "::endgroup::"
echo "::group::Configure Multipass"
while ! multipass version
do
sleep 1
done
echo "::endgroup::"
- name: Setup Tox environments
run: tox run -e integration-py${{ matrix.python }} --notest
- name: Enable ssh access
uses: mxschmitt/action-tmate@v3
if: ${{ inputs.enable_ssh_access }}
with:
limit-access-to-actor: true
- name: Run integration tests on MacOS
env:
CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_UNINSTALL: 1
PYTEST_ADDOPTS: "--no-header -vv -rN"
run: |
.tox/.tox/bin/tox run --skip-pkg-install --no-list-dependencies -e integration-py${{ matrix.python }}