-
Notifications
You must be signed in to change notification settings - Fork 13
348 lines (278 loc) · 10.6 KB
/
build.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
name: Build
on:
push:
branches:
- main
pull_request:
schedule:
- cron: "0 0 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CI: 'true'
jobs:
prepare-env:
name: Prepare environment
runs-on: "ubuntu-latest"
outputs:
requires_tests: ${{ env.REQUIRES_TESTS }}
publish_release: ${{ env.PUBLISH_RELEASE }}
release_version: ${{ env.RELEASE_VERSION }}
release_desc: ${{ env.RELEASE_DESC }}
python_version: ${{ env.PYTHON_VERSION }}
python_major: ${{ env.PYTHON_MAJOR }}
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
if: github.event_name != 'schedule'
- name: Get the changed files that would require tests
id: changed-files
uses: "tj-actions/changed-files@v44"
if: github.event_name != 'schedule'
with:
files: |
apps/**
tests/**
.github/workflows/build.yaml
- name: Check if a new release should be published
if: github.event_name == 'push'
env:
GITHUB_EVENT: ${{ toJSON(github.event) }}
GITHUB_TOKEN: ${{ github.token }}
run: |
.github/workflows/scripts/release.py --printenv | tee -a "$GITHUB_ENV"
- name: Identify if testing is required
run: |
echo "REQUIRES_TESTS=${{ github.event_name == 'schedule' || steps.changed-files.outputs.any_changed == 'true' || steps.changed-files.outputs.any_deleted == 'true' || steps.changed-files.outputs.any_modified == 'true' || env.PUBLISH_RELEASE == 'true' }}" | tee -a "$GITHUB_ENV"
- name: Find python version from AppDaemon's Dockerfile
if: env.REQUIRES_TESTS == 'true'
run: |
# Get the python version from the AppDaemon's Dockerfile
# which was used to build the latest AppDaemon's docker
# container
PYTHON_VERSION=$(\
curl -s https://raw.githubusercontent.com/AppDaemon/appdaemon/dev/Dockerfile | \
grep -oP "(?<=PYTHON_RELEASE=)[0-9\.]*" | head -n1)
echo "PYTHON_VERSION=${PYTHON_VERSION}" | tee -a "$GITHUB_ENV"
PYTHON_MAJOR=${PYTHON_VERSION%%.*}
echo "PYTHON_MAJOR=${PYTHON_MAJOR}" | tee -a "$GITHUB_ENV"
# Exit in error if we were unable to find the python version
if [ -z "$PYTHON_VERSION" ] || [ -z "$PYTHON_MAJOR" ]; then
echo >&2 "Error: unable to find Python version from AppDaemon"
exit 1
fi
unit-integration-tests:
name: Unit & integration tests
runs-on: "ubuntu-latest"
needs:
- prepare-env
if: needs.prepare-env.outputs.requires_tests == 'true'
env:
PYTHON_VERSION: ${{ needs.prepare-env.outputs.python_version }}
PYTHON_MAJOR: ${{ needs.prepare-env.outputs.python_major }}
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
- name: Install python
uses: "actions/setup-python@v5"
with:
python-version: '${{ env.PYTHON_VERSION }}'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov pytest-clarity pytest-subtests
pip install -r tests/requirements.txt
- name: Lint code
id: lint_code
run: |
flake8 apps/
continue-on-error: true
- name: Lint tests
id: lint_tests
run: |
flake8 tests/
continue-on-error: true
- name: Run unit & integration tests
id: tests
run: |
set -eo pipefail
pytest --cache-clear --cov=gateway --cov=qolsys --cov=mqtt --cov-report term-missing --junitxml=pytest.xml tests/unit/ tests/integration/ | tee pytest-coverage.txt
continue-on-error: true
- name: Identify bot comments to hide
uses: actions/github-script@v7
if: steps.tests.outcome == 'success' && github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComments = comments.filter(comment => {
return comment.user.type === 'Bot' && comment.body.startsWith('<!-- Pytest Coverage Comment: unit-integration-tests -->')
}).map((comment) => comment.node_id)
if (botComments.length > 0) {
core.exportVariable('BOT_COMMENTS', botComments.join(' '))
console.log('BOT_COMMENTS=' + botComments.join(' '))
}
- name: Minimize comments from previous run
if: steps.tests.outcome == 'success' && github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork && env.BOT_COMMENTS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
QUERY=$(cat <<- EOM
mutation minimizeComment(\$id: ID!) {
minimizeComment(input: { classifier: OUTDATED, subjectId: \$id }) {
clientMutationId
}
}
EOM
)
for commentId in ${{ env.BOT_COMMENTS }}; do
gh api graphql -F id="$commentId" -F query="$QUERY"
echo
done
- name: Post comment of pytest coverage
continue-on-error: true
uses: MishaKav/pytest-coverage-comment@main
if: steps.tests.outcome == 'success' && github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
with:
create-new-comment: true
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
- name: Overall job outcome
run: |
LINT_CODE=$([ '${{ steps.lint_code.outcome }}' == 'success' ] && echo true || echo false)
LINT_TESTS=$([ '${{ steps.lint_tests.outcome }}' == 'success' ] && echo true || echo false)
TESTS=$([ '${{ steps.tests.outcome }}' == 'success' ] && echo true || echo false)
if ! $LINT_CODE; then
echo "Lint of code failed" >&2
fi
if ! $LINT_TESTS; then
echo "Lint of tests failed" >&2
fi
if ! $TESTS; then
echo "Tests failed" >&2
fi
# Exit on error if any failed
if ! $LINT_CODE || ! $LINT_TESTS || ! $TESTS; then
exit 1
fi
exit 0
end-to-end-tests:
name: End-to-end tests
runs-on: "ubuntu-latest"
needs:
- prepare-env
- unit-integration-tests
if: needs.unit-integration-tests.result == 'success'
env:
PYTHON_VERSION: ${{ needs.prepare-env.outputs.python_version }}
PYTHON_MAJOR: ${{ needs.prepare-env.outputs.python_major }}
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
- name: Print docker versions
run: |
docker version
docker compose version
- name: Install python
uses: "actions/setup-python@v5"
with:
python-version: '${{ env.PYTHON_VERSION }}'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-clarity pytest-subtests
pip install -r tests/requirements.txt
pip install -r tests/end-to-end/requirements.txt
- name: Run end-to-end tests
id: tests
run: |
set -eo pipefail
pytest --cache-clear tests/end-to-end/
update_changelog:
name: Update changelog
runs-on: "ubuntu-latest"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-update-changelog
needs:
- prepare-env
- unit-integration-tests
- end-to-end-tests
if: github.event_name == 'push' && needs.prepare-env.outputs.publish_release != 'true' && needs.unit-integration-tests.result != 'failure' && needs.end-to-end-tests.result != 'failure'
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
with:
ref: ${{ github.ref }}
token: ${{ secrets.COMMIT_TOKEN }}
- name: Update changelog for future release
env:
GITHUB_EVENT: ${{ toJSON(github.event) }}
GITHUB_TOKEN: ${{ github.token }}
run: |
.github/workflows/scripts/release.py --update-changelog
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: "info.md"
commit_message: 📒 Update changelog for future release
push_release:
name: Release version
runs-on: ubuntu-latest
needs:
- prepare-env
- unit-integration-tests
- end-to-end-tests
if: github.event_name == 'push' && needs.prepare-env.outputs.publish_release == 'true' && needs.unit-integration-tests.result != 'failure' && needs.end-to-end-tests.result != 'failure'
permissions:
contents: write
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
- name: Release version
uses: ncipollo/release-action@v1
with:
tag: v${{ needs.prepare-env.outputs.release_version }}
name: v${{ needs.prepare-env.outputs.release_version }}
body: ${{ needs.prepare-env.outputs.release_desc }}
commit: main
makeLatest: true
skipIfReleaseExists: true
push_library:
name: Push library to PyPI
runs-on: ubuntu-latest
needs:
- prepare-env
- push_release
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
- name: Install Hatch
uses: pypa/hatch@install
- name: Create version file
env:
VERSION: ${{ needs.prepare-env.outputs.release_version }}
run: |
echo "__version__ = \"${VERSION}\"" | tee build_version.py
- name: Publish to PyPI
run: |
hatch publish
auto-merge:
name: "Auto-merge Dependabot pull requests"
runs-on: ubuntu-latest
needs:
- prepare-env
- unit-integration-tests
- end-to-end-tests
if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' && needs.unit-integration-tests.result != 'failure' && needs.end-to-end-tests.result != 'failure'
steps:
- name: Checkout current commit
uses: "actions/checkout@v4"
- name: Check and auto-merge on minor changes
uses: ahmadnassri/action-dependabot-auto-merge@v2
with:
target: minor
github-token: ${{ secrets.AUTOMERGE_TOKEN }}