Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to get a green checkmark even though an optional job failed #1347

Merged
merged 19 commits into from
Oct 31, 2024
Merged
26 changes: 24 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,17 @@ jobs:
tox run -e lint --notest

- name: Run unit tests
run: tox run -e ${TOX_ENV}
id: test
run: |
status=0
tox run -e "${TOX_ENV}" || status=$?
Comment on lines +240 to +241
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC $? is a feature of any shell, most likely any shell in Microsoft Github Actions, therefore both lines can be condensed to a single line on the second lines' composition:

tox run -e "${TOX_ENV}"; status=$?

Thanks for posting a useful comment updating the other thread! @wsanchez

if [ ${status} -ne 0 ] && [ "${{ matrix.optional }}" == "true" ]; then
echo "::warning::Optional matrix job failed."
echo "optional_fail=true" >> "${GITHUB_OUTPUT}"
echo "optional_fail_status=${status}" >> "${GITHUB_OUTPUT}"
exit 0 # Ignore error here to keep the green checkmark going
fi;
exit ${status}
env:
IMS_TEST_MYSQL_HOST: localhost
IMS_TEST_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
Expand All @@ -244,12 +254,24 @@ jobs:
IMS_TEST_MYSQL_PASSWORD: ims

- name: Upload Trial log artifact
if: ${{ failure() }}
if: ${{ failure() || steps.test.outputs.optional_fail == 'true' }}
uses: actions/upload-artifact@v4
with:
name: trial
path: .tox/${TOX_ENV}/log/trial.log

- name: Add comment if optional job failed; delete otherwise
if: ${{ matrix.optional }}
uses: thollander/actions-comment-pull-request@v3
with:
# Note: tag must be unique to each matrix case
comment-tag: "${{ matrix.python-version }}-${{ matrix.os }}-optional-notice"
message: |
### ⚠️ Optional matrix job Py:${{ matrix.python-version }} - ${{ matrix.os }} failed ⚠️
- tox prefix: ${{ matrix.tox-prefix }}
- exit status: ${{ steps.test.outputs.optional_fail_status }}
mode: ${{ steps.test.outputs.optional_fail == 'true' && 'upsert' || 'delete' }}

# Use the latest supported Python version for combining coverage to
# prevent parsing errors in older versions when looking at modern code.
- uses: "actions/setup-python@v5"
Expand Down
Loading