11# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
22# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33
4- name : Test against HA-core (master/released)
4+ name : Test PR against HA-core
55
66env :
7- CACHE_VERSION : 29
7+ CACHE_VERSION : 30
88 DEFAULT_PYTHON : " 3.13"
99
10+ # Do not run on 'push' (as the flow doesn't have access to the labels) - also disabled workflow_dispatch as such
11+ # Workaround could be something like
12+ # - name: Get PR labels
13+ # run: |
14+ # PR_LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
15+ # "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels")
16+ # echo "PR Labels: $PR_LABELS"
17+
1018on :
11- workflow_dispatch :
12- push :
13- # pull_request:
19+ pull_request :
20+ types :
21+ - opened
22+ - synchronize
23+ - labeled
24+ - unlabeled
1425
1526jobs :
16- # Run pre-commit
27+ shellcheck :
28+ name : Shellcheck
29+ runs-on : ubuntu-latest
30+ steps :
31+ - uses : actions/checkout@v4.2.2
32+ - name : Run ShellCheck
33+ uses : ludeeus/action-shellcheck@master
34+
1735 pre-commit :
1836 name : Validate pre-commit requirements
1937 runs-on : ubuntu-latest
@@ -50,22 +68,33 @@ jobs:
5068 run : |
5169 . venv/bin/activate
5270 pre-commit install-hooks
53- - name : Run full pre-commit
71+ - name : Run all-files pre-commit excluding testing
5472 run : |
5573 . venv/bin/activate
5674 pre-commit run --all-files --show-diff-on-failure
5775 env : # While not problematic, save time on performing the local hooks as they are run from the complete script in the next job
5876 SKIP : local-test-core-prep,local-test-pip-prep,local-testing,local-quality
5977
6078 # Prepare default python version environment
61- ha-core-prepare :
79+ ha-core-release :
6280 runs-on : ubuntu-latest
63- name : Setup for HA-core (release)
81+ name : Setup for HA-core (release/master)
82+ continue-on-error : true
6483 needs :
6584 - pre-commit
85+ outputs :
86+ release_failed : ${{ steps.capture_release.outputs.failed }}
6687 steps :
6788 - name : Check out committed code
6889 uses : actions/checkout@v4.2.2
90+ - name : Determine Branch Test Mode
91+ id : determine_mode
92+ run : |
93+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
94+ echo "STRICT_DEV=true" >> $GITHUB_ENV
95+ else
96+ echo "STRICT_DEV=false" >> $GITHUB_ENV
97+ fi
6998 - name : Set up Python ${{ env.DEFAULT_PYTHON }}
7099 id : python
71100 uses : actions/setup-python@v5.4.0
75104 id : cache-hacore
76105 uses : actions/cache@v4.2.0
77106 env :
78- cache-name : cache-hacore
107+ cache-name : cache-hacore-release
79108 with :
80109 path : ./
81110 key : >-
@@ -88,14 +117,150 @@ jobs:
88117 ${{ env.CACHE_VERSION}}-${{ runner.os }}-base-hacore
89118 ${{ env.CACHE_VERSION}}-${{ runner.os }}
90119 ${{ env.CACHE_VERSION}}
91- - name : Test through HA-core (master/release)
120+ - name : Test through HA-core (master/release) - continue-on-error = ${{ env.STRICT_DEV == 'false' }}
121+ id : ha_core_release_tests
122+ continue-on-error : ${{ env.STRICT_DEV == 'true' }} # Allow master failures only if dev is strict
92123 run : |
93- GITHUB_ACTIONS="" BRANCH="master" scripts/core-testing.sh
124+ echo "true" > result.txt
125+ GITHUB_ACTIONS="" scripts/core-testing.sh
126+ if [ $? -ne 0 ]; then
127+ echo "::warning::Release HA core incompatibility"
128+ echo "true" > result.txt
129+ else
130+ echo "Successfully tested against released HA-core"
131+ echo "false" > result.txt
132+ fi
133+ - name : Set output explicitly
134+ id : capture_release
135+ if : always()
136+ run : |
137+ FAILED=$(cat result.txt)
138+ echo "failed=$FAILED" >> "$GITHUB_OUTPUT"
94139
95- shellcheck :
96- name : Shellcheck
140+ ha-core-dev :
97141 runs-on : ubuntu-latest
142+ name : Setup for HA-core (dev)
143+ continue-on-error : true
144+ needs :
145+ - pre-commit
146+ outputs :
147+ dev_failed : ${{ steps.capture_dev.outputs.failed }}
98148 steps :
99- - uses : actions/checkout@v4.2.2
100- - name : Run ShellCheck
101- uses : ludeeus/action-shellcheck@master
149+ - name : Check out committed code
150+ uses : actions/checkout@v4.2.2
151+ - name : Determine Branch Test Mode
152+ id : determine_mode
153+ run : |
154+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
155+ echo "STRICT_DEV=true" >> $GITHUB_ENV
156+ else
157+ echo "STRICT_DEV=false" >> $GITHUB_ENV
158+ fi
159+ - name : Set up Python ${{ env.DEFAULT_PYTHON }}
160+ id : python
161+ uses : actions/setup-python@v5.4.0
162+ with :
163+ python-version : ${{ env.DEFAULT_PYTHON }}
164+ - name : Restore base HA-core Python ${{ env.DEFAULT_PYTHON }} environment
165+ id : cache-hacore
166+ uses : actions/cache@v4.2.0
167+ env :
168+ cache-name : cache-hacore-dev
169+ with :
170+ path : ./
171+ key : >-
172+ ${{ env.CACHE_VERSION}}-${{ runner.os }}-base-hacore-${{
173+ steps.python.outputs.python-version }}-${{
174+ hashFiles('./custom_components/plugwise/manifest.json') }}-${{
175+ hashFiles('./ha-core/.git/plugwise-tracking') }}
176+ restore-keys : |
177+ ${{ env.CACHE_VERSION}}-${{ runner.os }}-base-hacore-${{ steps.python.outputs.python-version }}-
178+ ${{ env.CACHE_VERSION}}-${{ runner.os }}-base-hacore
179+ ${{ env.CACHE_VERSION}}-${{ runner.os }}
180+ ${{ env.CACHE_VERSION}}
181+ - name : Test through HA-core (dev) - continue-on-error = ${{ env.STRICT_DEV == 'false' }}
182+ id : ha_core_dev_tests
183+ continue-on-error : ${{ env.STRICT_DEV == 'false' }} # Allow dev failures unless strict
184+ run : |
185+ echo "true" > result.txt
186+ GITHUB_ACTIONS="" BRANCH="dev" scripts/core-testing.sh
187+ if [ $? -ne 0 ]; then
188+ echo "::warning::Development HA core incompatibility"
189+ echo "true" > result.txt
190+ else
191+ echo "Successfully tested against dev HA-core"
192+ echo "false" > result.txt
193+ fi
194+ - name : Set output explicitly
195+ id : capture_dev
196+ if : always()
197+ run : |
198+ FAILED=$(cat result.txt)
199+ echo "failed=$FAILED" >> "$GITHUB_OUTPUT"
200+
201+ final-comment :
202+ runs-on : ubuntu-latest
203+ needs : [ha-core-release, ha-core-dev]
204+ steps :
205+ - name : Determine Branch Test Mode
206+ id : determine_mode
207+ run : |
208+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
209+ echo "STRICT_DEV=true" >> $GITHUB_ENV
210+ else
211+ echo "STRICT_DEV=false" >> $GITHUB_ENV
212+ fi
213+ - name : Create combined comment
214+ run : |
215+ # Get the results of the previous scripts
216+ STRICT_DEV=$STRICT_DEV
217+ DEV_TESTS_FAILED=${{ needs.ha-core-dev.outputs.dev_failed }}
218+ RELEASE_TESTS_FAILED=${{ needs.ha-core-release.outputs.release_failed }}
219+ FAIL_COUNT=0
220+
221+ if [[ $DEV_TESTS_FAILED == "true" ]]; then
222+ COMMENT_BODY=":x: **Error while testing for Development HA-core:**\n\n"
223+ else
224+ COMMENT_BODY=":warning: **Warning while testing for RELEASED HA-core:**\n\n"
225+ fi
226+
227+ if [[ $DEV_TESTS_FAILED == "true" ]]; then
228+ if [[ $STRICT_DEV == "true" ]]; then
229+ COMMENT_BODY+=":x: **Error:** Incompatible while testing against dev HA-core and required to pass.\n"
230+ FAIL_COUNT=2
231+ else
232+ COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against dev HA-core.\n"
233+ FAIL_COUNT=1
234+ fi
235+ else
236+ COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against dev HA-core.\n"
237+ fi
238+
239+ if [[ $RELEASE_TESTS_FAILED == "true" ]]; then
240+ if [[ $STRICT_DEV == "false" ]]; then
241+ COMMENT_BODY+=":x: **Error:** Incompatible while testing against released HA-core and required to pass.\n"
242+ FAIL_COUNT=2
243+ else
244+ COMMENT_BODY+=":warning: **Warning:** Incompatible while testing against released HA-core.\n"
245+ FAIL_COUNT=1
246+ fi
247+ else
248+ COMMENT_BODY+=":heavy_check_mark: **Success:** No problem with testing against released HA-core.\n"
249+ fi
250+
251+ if [[ $FAIL_COUNT -eq 1 ]]; then
252+ echo "Comment and approve the pull request"
253+ curl -s -X POST \
254+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
255+ -H "Content-Type: application/json" \
256+ --data "{\"event\": \"APPROVE\", \"body\": \"$COMMENT_BODY\"}" \
257+ "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
258+ fi
259+ if [[ $FAIL_COUNT -eq 2 ]]; then
260+ echo "Requesting changes on the pull request"
261+ curl -s -X POST \
262+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
263+ -H "Content-Type: application/json" \
264+ --data "{\"event\": \"REQUEST_CHANGES\", \"body\": \"$COMMENT_BODY\"}" \
265+ "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
266+ fi
0 commit comments