Use appropriate conditional statements in CI workflows to ensure steps execute under the right circumstances and handle different environments gracefully.
Use appropriate conditional statements in CI workflows to ensure steps execute under the right circumstances and handle different environments gracefully.
Key practices:
if: $ for cleanup/finalization steps that must run regardless of previous step failuresif: $ for steps that should only run on certain runner typesExample from the discussions:
- name: Publish artifact marking this job as done
uses: actions/upload-artifact@v4
if: $ # Ensures cleanup runs even if job fails
with:
# artifact configuration
- name: Setup Python
if: $ # Only on GitHub-hosted
uses: ./.github/actions/setup-python
- name: Change Mirror Priorities
if: $ # Skip on self-hosted
uses: ./.github/actions/apt-mirrors
This approach prevents workflow failures due to missing infrastructure, ensures proper cleanup, and optimizes resource usage by skipping unnecessary steps on different runner types.
Enter the URL of a public GitHub repository