CI workflows should be idempotent and handle cleanup automatically to avoid manual intervention and ensure reliable execution. When designing workflows that create resources, branches, or temporary artifacts, always include cleanup steps that can run safely multiple times.
CI workflows should be idempotent and handle cleanup automatically to avoid manual intervention and ensure reliable execution. When designing workflows that create resources, branches, or temporary artifacts, always include cleanup steps that can run safely multiple times.
Key practices:
Example from workflow design:
- name: "Create Draft PR"
run: |
# Clean up existing branch if it exists
git branch -D run-ci-on-behalf-of-$ 2>/dev/null || true
git checkout -b run-ci-on-behalf-of-$
This prevents scenarios where workflows fail on subsequent runs due to existing branches, resources, or conflicts, eliminating the need for manual cleanup and ensuring consistent behavior across executions.
Enter the URL of a public GitHub repository