-
Notifications
You must be signed in to change notification settings - Fork 33
183 lines (170 loc) · 5.86 KB
/
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
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
name: test
"on":
pull_request:
branches: [main]
workflow_call:
secrets:
GCLOUD_PROJECT:
required: true
GCLOUD_SA_KEY:
required: true
repository_dispatch:
types: [test]
env:
KCIDB_IO_URL: kcidb-io@git+https://github.com/kernelci/kcidb-io.git@${{ github.event.client_payload.kcidb_io_ref || 'main' }}
jobs:
check_python:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Check setup.py and requirements.txt are consistent
run: |
# Check both install_requires in setup.py and requirements.txt contain
# the same dependencies
(
set -e -u -o pipefail
unique_requires=$({
sed -n '/install_requires=/,/],/ s/.*"\([^"]\+\)".*/\1/p' setup.py |
sort -u
grep -v '^#' requirements.txt |
sort -u
} | sort | uniq -u)
if [ -n "$unique_requires" ]; then
echo "Requirements not both in setup.py and requirements.txt:" >&2
echo "$unique_requires" >&2
false
fi
)
- name: Install
run: |
python -m pip install --upgrade pip setuptools
sed -i -e "s|kcidb-io@[^\"]*|${KCIDB_IO_URL}|" requirements.txt setup.py
pip3 install --upgrade '.[dev]'
- name: Check python sources with flake8
run: "flake8 kcidb *.py"
env:
KCIDB_HOOKS: "pre-commit"
- name: Check python sources with pylint
run: "pylint kcidb *.py"
env:
KCIDB_HOOKS: "pre-commit"
- name: Test with pytest
run: |
KCIDB_IO_HEAVY_ASSERTS=1 KCIDB_HEAVY_ASSERTS=1 \
pytest --tb=native --durations=0 --durations-min=1
env:
KCIDB_HOOKS: "pre-commit"
check_auxiliary_files:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
python -m pip install --upgrade pip setuptools
sed -i -e "s|kcidb-io@[^\"]*|${KCIDB_IO_URL}|" requirements.txt setup.py
pip3 install --upgrade '.[dev]'
- name: Check YAML files with yamllint
run: find -name '*.yaml' -or -name '*.yml' | xargs yamllint
env:
KCIDB_HOOKS: "pre-commit"
- name: Check test catalog is ordered alphabetically
run: |
test_list=$(
python3 <(
echo "import sys, yaml"
echo "for k in yaml.safe_load(sys.stdin).keys():"
echo " print(k)"
) < tests.yaml
)
export LANG=C
test_list_diff=$(diff -u <(echo "$test_list") \
<(echo "$test_list" | sort)) ||
{
echo "Tests out of alphabetic order." >&2
echo "Change the order as below:" >&2
echo "$test_list_diff" >&2
false
}
env:
KCIDB_HOOKS: "pre-commit"
- name: Validate test catalog
run: kcidb-tests-validate --urls < tests.yaml
check_deployment:
needs: check_python
runs-on: ubuntu-latest
environment: staging
steps:
- name: Check credentials
env:
GCLOUD_PROJECT: ${{ secrets.GCLOUD_PROJECT }}
GCLOUD_SA_KEY: ${{ secrets.GCLOUD_SA_KEY }}
run: |
# Check credentials
CREDENTIALS_PRESENT=true
function check() {
if eval "test -z \"\$$1\""; then
echo "$1 secret is missing." >&2
CREDENTIALS_PRESENT=false
fi
}
check GCLOUD_PROJECT
check GCLOUD_SA_KEY
if "$CREDENTIALS_PRESENT"; then
echo "All required credentials are present, continuing." >&2
else
echo "Required credentials are missing, aborting." >&2
fi
"$CREDENTIALS_PRESENT"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install
run: |
python -m pip install --upgrade pip setuptools
sed -i -e "s|kcidb-io@[^\"]*|${KCIDB_IO_URL}|" requirements.txt setup.py
pip3 install --upgrade '.[dev]'
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2.1.1
with:
project_id: ${{ secrets.GCLOUD_PROJECT }}
credentials_json: ${{ secrets.GCLOUD_SA_KEY }}
create_credentials_file: true
export_environment_variables: true
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2.1.0
- name: Deploy, Test, and Withdraw
run: |
status=0
declare -a args=(
"kernelci-staging" "gh${{ github.run_id }}"
--smtp-mocked --test
)
declare -a env_args=(
"${args[@]}" --heavy-asserts --log-level=DEBUG
)
./cloud deploy "${env_args[@]}" --verbose &&
KCIDB_DEPLOYMENT="This deployment is empty" \
./cloud shell "${env_args[@]}" -- \
pytest --tb=native --verbosity=2 --log-level=DEBUG \
--durations=0 --durations-min=1 ||
status=$((status || $?))
./cloud withdraw "${args[@]}" --verbose || status=$((status || $?))
exit "$status"