Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/devbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,39 @@ jobs:
name: modmesh-pilot-win64
path: modmesh-pilot-win64/

send_email_on_failure:
fail_on_cancelled_jobs:
needs: [standalone_buffer, build, build_windows]
# Run if any of the dependencies failed in master branch
if: ${{ always() }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it necessary to write the if, if it always() happens?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is. It's an interesting technique. See this reference.

If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a conditional expression that causes the job to continue. If a run contains a series of jobs that need each other, a failure or skip applies to all jobs in the dependency chain from the point of failure or skip onwards. If you would like a job to run even if a job it is dependent on did not succeed, use the always() conditional expression in jobs.<job_id>.if.

In other words, if we remove if: ${{ always() }}, this job would be skipped if the jobs in needs are cancelled or failed. However, we don't want to skip this job at any time, so we need to add if: ${{ always() }}.

runs-on: ubuntu-24.04
steps:
- name: Fail on cancelled jobs
run: |
failed=0
for job_result in \
"standalone_buffer:${{ needs.standalone_buffer.result }}" \
"build:${{ needs.build.result }}" \
"build_windows:${{ needs.build_windows.result }}"
do
job_name="${job_result%%:*}"
result="${job_result#*:}"
echo "${job_name}: ${result}"
if [ "${result}" = "cancelled" ]; then
failed=1
fi
done
exit "${failed}"

send_email_on_failure:
needs: [standalone_buffer, build, build_windows, fail_on_cancelled_jobs]
# Run if any of the dependencies failed or timed out in master branch
if: ${{ always() && contains(needs.*.result, 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
uses: ./.github/workflows/send_email_on_fail.yml
with:
job_results: |
- standalone_buffer: ${{ needs.standalone_buffer.result }}
- build: ${{ needs.build.result }}
- build_windows: ${{ needs.build_windows.result }}
- fail_on_cancelled_jobs: ${{ needs.fail_on_cancelled_jobs.result }}
secrets:
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
18 changes: 16 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,28 @@ jobs:
CMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
CMAKE_ARGS="-DPYTHON_EXECUTABLE=$(which python3)"

send_email_on_failure:
fail_on_cancelled_jobs:
needs: [lint]
# Run if any of the dependencies failed in master branch
if: ${{ always() }}
runs-on: ubuntu-24.04
steps:
- name: Fail on cancelled jobs
run: |
result="${{ needs.lint.result }}"
echo "lint: ${result}"
if [ "${result}" = "cancelled" ]; then
exit 1
fi

send_email_on_failure:
needs: [lint, fail_on_cancelled_jobs]
# Run if any of the dependencies failed or timed out in master branch
if: ${{ always() && contains(needs.*.result, 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
uses: ./.github/workflows/send_email_on_fail.yml
with:
job_results: |
- lint: ${{ needs.lint.result }}
- fail_on_cancelled_jobs: ${{ needs.fail_on_cancelled_jobs.result }}
secrets:
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
18 changes: 16 additions & 2 deletions .github/workflows/nouse_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,28 @@ jobs:
pytest --rootdir=. -v
cd ..

send_email_on_failure:
fail_on_cancelled_jobs:
needs: [nouse_install]
# Run if any of the dependencies failed in master branch
if: ${{ always() }}
runs-on: ubuntu-24.04
steps:
- name: Fail on cancelled jobs
run: |
result="${{ needs.nouse_install.result }}"
echo "nouse_install: ${result}"
if [ "${result}" = "cancelled" ]; then
exit 1
fi
Comment on lines -88 to +99
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We cannot make a time-out job as a failure job easily. There are two workaround method.
The first opinion is to create a new job to monitor the cancelled jobs, and it would raise failure when there is a cancelled job.
The second opinion is to time the process by a timer. If the process times out, the timer would return 1.

I prefer the first opinion, so I create a new job to monitor the cancelled jobs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would work, but is not as elegant as I hoped for.

If there is not a better way, I would take it. But I hope there is.


send_email_on_failure:
needs: [nouse_install, fail_on_cancelled_jobs]
# Run if any of the dependencies failed or timed out in master branch
if: ${{ always() && contains(needs.*.result, 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
uses: ./.github/workflows/send_email_on_fail.yml
with:
job_results: |
- nouse_install: ${{ needs.nouse_install.result }}
- fail_on_cancelled_jobs: ${{ needs.fail_on_cancelled_jobs.result }}
Comment on lines +101 to +109
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

When a job is cancelled, a notified email would be sent now.

secrets:
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
18 changes: 16 additions & 2 deletions .github/workflows/profiling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,27 @@ jobs:
run: |
make pyprof

send_email_on_failure:
fail_on_cancelled_jobs:
needs: [profile]
if: ${{ always() && (needs.*.result == 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
if: ${{ always() }}
runs-on: ubuntu-24.04
steps:
- name: Fail on cancelled jobs
run: |
result="${{ needs.profile.result }}"
echo "profile: ${result}"
if [ "${result}" = "cancelled" ]; then
exit 1
fi

send_email_on_failure:
needs: [profile, fail_on_cancelled_jobs]
if: ${{ always() && contains(needs.*.result, 'failure') && github.ref_name == 'master' && github.event.repository.fork == false }}
uses: ./.github/workflows/send_email_on_fail.yml
with:
job_results: |
- profile: ${{ needs.profile.result }}
- fail_on_cancelled_jobs: ${{ needs.fail_on_cancelled_jobs.result }}
secrets:
EMAIL_USERNAME: ${{ secrets.EMAIL_USERNAME }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
Loading