Skip to content

Commit 08d7760

Browse files
committed
Complex adding of tests results
1 parent 52ce974 commit 08d7760

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

.github/workflows/test.yml

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ on:
2424
- unlabeled
2525

2626
jobs:
27-
# 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+
2835
pre-commit:
2936
name: Validate pre-commit requirements
3037
runs-on: ubuntu-latest
@@ -74,6 +81,8 @@ jobs:
7481
name: Setup for HA-core (release/master)
7582
needs:
7683
- pre-commit
84+
outputs:
85+
release_failed: ${{ steps.ha_core_tests.outputs.failed }}
7786
steps:
7887
- name: Check out committed code
7988
uses: actions/checkout@v4.2.2
@@ -108,15 +117,25 @@ jobs:
108117
${{ env.CACHE_VERSION}}-${{ runner.os }}
109118
${{ env.CACHE_VERSION}}
110119
- name: Test through HA-core (master/release) - continue-on-error = ${{ env.STRICT_DEV == 'true' }}
120+
id: ha-core-tests
111121
continue-on-error: ${{ env.STRICT_DEV == 'true' }} # Allow master failures only if dev is strict
112122
run: |
113123
GITHUB_ACTIONS="" scripts/core-testing.sh
124+
if [ $? -ne 0 ]; then
125+
echo "::warning::Release HA core incompatibility"
126+
echo "RELEASE_TESTS_FAILED=true" >> $GITHUB_ENV
127+
else
128+
echo "Successfully tested against released HA-core"
129+
echo "RELEASE_TESTS_FAILED=false" >> $GITHUB_ENV
130+
fi
114131
115132
ha-core-dev:
116133
runs-on: ubuntu-latest
117134
name: Setup for HA-core (dev)
118135
needs:
119136
- pre-commit
137+
outputs:
138+
dev_failed: ${{ steps.ha_core_tests.outputs.failed }}
120139
steps:
121140
- name: Check out committed code
122141
uses: actions/checkout@v4.2.2
@@ -151,14 +170,80 @@ jobs:
151170
${{ env.CACHE_VERSION}}-${{ runner.os }}
152171
${{ env.CACHE_VERSION}}
153172
- name: Test through HA-core (dev) - continue-on-error = ${{ env.STRICT_DEV == 'false' }}
173+
id: ha-core-tests
154174
continue-on-error: ${{ env.STRICT_DEV == 'false' }} # Allow dev failures unless strict
155175
run: |
156176
GITHUB_ACTIONS="" BRANCH="dev" scripts/core-testing.sh
177+
if [ $? -ne 0 ]; then
178+
echo "::warning::Development HA core incompatibility"
179+
echo "DEV_TESTS_FAILED=true" >> $GITHUB_ENV
180+
else
181+
echo "Successfully tested against dev HA-core"
182+
echo "DEV_TESTS_FAILED=false" >> $GITHUB_ENV
183+
fi
157184
158-
shellcheck:
159-
name: Shellcheck
185+
final-comment:
160186
runs-on: ubuntu-latest
187+
needs: [ha-core-release, ha-core-dev]
161188
steps:
162-
- uses: actions/checkout@v4.2.2
163-
- name: Run ShellCheck
164-
uses: ludeeus/action-shellcheck@master
189+
- name: Determine Branch Test Mode
190+
id: determine_mode
191+
run: |
192+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'require-dev-pass') }}" == "true" ]]; then
193+
echo "STRICT_DEV=true" >> $GITHUB_ENV
194+
else
195+
echo "STRICT_DEV=false" >> $GITHUB_ENV
196+
fi
197+
- name: Create combined comment
198+
run: |
199+
# Get the results of the previous scripts
200+
STRICT_DEV=$STRICT_DEV
201+
DEV_TESTS_FAILED=$DEV_TESTS_FAILED
202+
RELEASE_TESTS_FAILED=$RELEASE_TESTS_FAILED
203+
FAIL_COUNT=0
204+
205+
COMMENT_BODY="**Error while testing for RELEASED HA-core:**\n"
206+
if [[ $DEV_TESTS_FAILED == "true" ]]; then
207+
COMMENT_BODY="**Error while testing for Development HA-core:**\n"
208+
fi
209+
210+
if [[ $DEV_TESTS_FAILED == "true" ]]; then
211+
if [[ $STRICT_DEV == "true" ]]; then
212+
COMMENT_BODY+="**Error:** Incompatible while testing against dev HA-core and required to pass.\n"
213+
FAIL_COUNT=2
214+
else
215+
COMMENT_BODY+="**Warning:** Incompatible while testing against dev HA-core.\n"
216+
FAIL_COUNT=1
217+
fi
218+
else
219+
COMMENT_BODY+="**Success:** No problem with testing against dev HA-core.\n"
220+
fi
221+
222+
if [[ $RELEASE_TESTS_FAILED == "true" ]]; then
223+
if [[ $STRICT_DEV == "false" ]]; then
224+
COMMENT_BODY+="**Error:** Incompatible while testing against released HA-core and required to pass.\n"
225+
FAIL_COUNT=2
226+
else
227+
COMMENT_BODY+="**Warning:** Incompatible while testing against released HA-core.\n"
228+
FAIL_COUNT=1
229+
fi
230+
else
231+
COMMENT_BODY+="**Success:** No problem with testing against released HA-core.\n"
232+
fi
233+
234+
if [[ FAIL_COUNT == 1 ]]; then
235+
# Create a comment on the pull request
236+
curl -s -X POST \
237+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
238+
-H "Content-Type: application/json" \
239+
--data "{\"body\": \"$COMMENT_BODY\"}" \
240+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
241+
fi
242+
if [[ FAIL_COUNT == 2 ]]; then
243+
# Request changes on the pull request
244+
curl -s -X POST \
245+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
246+
-H "Content-Type: application/json" \
247+
--data ""{\"event\": \"REQUEST_ACTIONS\", \"body\": \"$COMMENT_BODY\"}" \
248+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
249+
fi

0 commit comments

Comments
 (0)