-
Notifications
You must be signed in to change notification settings - Fork 8
289 lines (264 loc) · 11.8 KB
/
test.yml
File metadata and controls
289 lines (264 loc) · 11.8 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
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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Test PR against HA-core
env:
CACHE_VERSION: 3
DEFAULT_PYTHON: "3.14"
VENV: venv
# Do not run on 'push' (as the flow doesn't have access to the labels) - also disabled workflow_dispatch as such
# Workaround could be something like
# - name: Get PR labels
# run: |
# PR_LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels")
# echo "PR Labels: $PR_LABELS"
on:
pull_request:
types:
- opened
- synchronize
- labeled
- unlabeled
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
# Determine cache key once
cache:
runs-on: ubuntu-latest
name: Cache identify
outputs:
cache-key: ${{ steps.set-key.outputs.cache-key }}
python-version: ${{ steps.python.outputs.python-version }}
steps:
- name: Check out committed code
uses: actions/checkout@v6
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Fetch HA pyproject
id: core-version
run: wget -O ha_pyproject.toml "https://raw.githubusercontent.com/home-assistant/core/refs/heads/dev/pyproject.toml"
- name: Core dependencies
id: core-dependencies-1
run: sudo apt-get update
- name: Core dependencies
id: core-dependencies-2
run: sudo apt-get install python3-pip python3-dev python3-venv autoconf libssl-dev libxml2-dev libxslt1-dev libjpeg-dev libffi-dev libudev-dev zlib1g-dev pkg-config libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libswresample-dev libavfilter-dev ffmpeg libgammu-dev build-essential
- name: Compute cache key
id: set-key
run: echo "cache-key=${{ runner.os }}--${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml', 'requirements_test.txt', '.pre-commit-config.yaml', 'ha_pyproject.toml') }}" >> "$GITHUB_OUTPUT"
determine-mode:
name: Determine release or dev mode
runs-on: ubuntu-latest
outputs:
strict_dev: ${{ steps.set_mode.outputs.strict_dev }}
steps:
- name: Determine Branch Test Mode
id: set_mode
run: |
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
echo "strict_dev=true" >> $GITHUB_OUTPUT
else
echo "strict_dev=false" >> $GITHUB_OUTPUT
fi
# Prepare default python version environment
prepare:
runs-on: ubuntu-latest
needs: cache
name: Prepare
steps:
- name: Prepare code checkout and python/prek/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v2
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
clone-core: "true"
# Prepare default python version environment
ha-core-release-prepare:
runs-on: ubuntu-latest
name: Prepare and validate prek (pre-commit)
needs:
- cache
- prepare
steps:
- name: Check out committed code
uses: actions/checkout@v6
- name: Prepare code checkout and python/prek/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v2
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Run all-files prek (pre-commit) excluding testing
run: |
# shellcheck disable=SC1091 # ingesting virtualenv
source venv-${{ needs.cache.outputs.python-version }}/bin/activate
prek run --all-files --show-diff-on-failure
env: # While not problematic, save time on performing the local hooks as they are run from the complete script in the next job
SKIP: local-test-core-prep,local-test-pip-prep,local-testing,local-quality
# Prepare default python version environment
ha-core-testing:
runs-on: ubuntu-latest
name: Setup for HA-core (release/master)
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'true' }} # Allow master failures only if dev is strict
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
outputs:
release_failed: ${{ steps.ha_core_release_tests.outputs.release_failed }}
steps:
- name: Check out committed code
uses: actions/checkout@v6.0.2
- name: Prepare code checkout and python/prek/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v2
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Test through HA-core (master/release) - continue-on-error = ${{ needs.determine-mode.outputs.strict_dev == 'true' }}
id: ha_core_release_tests
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'true' }} # Allow master failures only if dev is strict
run: |
set +e
GITHUB_ACTIONS="" scripts/core-testing.sh
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "::warning::Release HA core incompatibility"
echo "release_failed=true" >> "$GITHUB_OUTPUT"
else
echo "Successfully tested against released HA-core"
echo "release_failed=false" >> "$GITHUB_OUTPUT"
fi
exit $EXIT_CODE
ha-core-dev-testing:
runs-on: ubuntu-latest
name: Setup for HA-core (dev)
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'false' }} # Allow dev failures unless strict
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
outputs:
dev_failed: ${{ steps.ha_core_dev_tests.outputs.dev_failed }}
steps:
- name: Check out committed code
uses: actions/checkout@v6.0.2
- name: Prepare code checkout and python/prek/pre-commit setup
id: cache-reuse
uses: plugwise/gh-actions/prepare-python-and-code@v2
with:
cache-key: ${{ needs.cache.outputs.cache-key }}
fail-on-miss: false # First time create cache (if not already exists)
python-version: ${{ needs.cache.outputs.python-version }}
venv-dir: ${{ env.VENV }}
- name: Test through HA-core (dev) - continue-on-error = ${{ needs.determine-mode.outputs.strict_dev == 'false' }}
id: ha_core_dev_tests
continue-on-error: ${{ needs.determine-mode.outputs.strict_dev == 'false' }} # Allow dev failures unless strict
run: |
set +e
GITHUB_ACTIONS="" BRANCH="dev" scripts/core-testing.sh
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "::warning::Development HA core incompatibility"
echo "dev_failed=true" >> "$GITHUB_OUTPUT"
else
echo "Successfully tested against dev HA-core"
echo "dev_failed=false" >> "$GITHUB_OUTPUT"
fi
exit $EXIT_CODE
final-comment:
runs-on: ubuntu-latest
needs:
- cache
- prepare
- determine-mode
- ha-core-release-prepare
- ha-core-testing
- ha-core-dev-testing
if: always()
steps:
- name: Create combined comment
run: |
# Get the results of the previous scripts
STRICT_DEV="${{ needs.determine-mode.outputs.strict_dev }}"
DEV_TESTS_FAILED="${{ needs.ha-core-dev-testing.outputs.dev_failed }}"
RELEASE_TESTS_FAILED="${{ needs.ha-core-release.outputs.release_failed }}"
FAIL_COUNT=0
# Get the action-bot's latest state
LAST_REVIEW_STATE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews" \
| jq -r '[.[] | select(.user.login=="github-actions[bot]")] | last | .state')
if [[ $DEV_TESTS_FAILED == "true" ]]; then
COMMENT_BODY=":x: **Error while testing for Development HA-core:**\n\n"
else
COMMENT_BODY=":warning: **Warning while testing for RELEASED HA-core:**\n\n"
fi
if [[ $DEV_TESTS_FAILED == "true" ]]; then
if [[ $STRICT_DEV == "true" ]]; then
COMMENT_BODY+=":x: **Error:** Incompatible while testing against dev HA-core and required to pass.\n"
FAIL_COUNT=2
else
COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against dev HA-core.\n"
FAIL_COUNT=1
fi
else
COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against dev HA-core.\n"
fi
if [[ $RELEASE_TESTS_FAILED == "true" ]]; then
if [[ $STRICT_DEV == "false" ]]; then
COMMENT_BODY+=":x: **Error:** Incompatible while testing against released HA-core and required to pass.\n"
FAIL_COUNT=2
else
COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against released HA-core.\n"
FAIL_COUNT=1
fi
else
COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against released HA-core.\n"
fi
# If everything is OK, don't approve - if requested changes before and everything is good now, approve
# to release the 'requested changes' bit
if [[ $FAIL_COUNT -eq 0 ]]; then
if [[ "$LAST_REVIEW_STATE" == "CHANGES_REQUESTED" ]]; then
echo "Lifting previous changes requested — submitting approval."
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"APPROVE\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
else
echo "No prior changes requested — skipping approval."
fi
fi
if [[ $FAIL_COUNT -eq 1 ]]; then
echo "Comment and approve the pull request"
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"APPROVE\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
fi
if [[ $FAIL_COUNT -eq 2 ]]; then
echo "Requesting changes on the pull request"
curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "{\"event\": \"REQUEST_CHANGES\", \"body\": \"$COMMENT_BODY\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
fi