Add post hook to cancel in-progress deployments if the job/workflow run ends unsuccessfully
It might be good to add a post hook/step for this Action to cancel any in-progress deployments if the Actions job/workflow run ends unsuccessfully (cancelled, failed, erred, etc.). 🛡️
For state maintenance of the active deployment ID, see: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions
The Actions toolkit also has support for ☝🏻 using core.saveState(...) and core.getState(...): https://github.com/actions/toolkit/tree/main/packages/core#action-state
Requires updates to the Action's manifest file:
post: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runspostpostif: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runspost-if
Rough idea:
- After creating a deployment, save the ID in the state
- After a deployment is terminated (success or failure), save that status indicator in the state
- Add a
postcleanup step- If the deployment ID is present in the state but the terminated status is not (or is not set to
true), make one attempt to cancel the deployment
- If the deployment ID is present in the state but the terminated status is not (or is not set to
This is probably even more important than I originally thought as Pages self-regulates the concurrency of in-progress deployments to one per repository + branch/ref.
As such, if you had an Actions workflow to deploy Pages with a concurrency.cancel-in-progress: true configuration, a second workflow run ("RunB") could cancel an in-progress first workflow run ("RunA"), which might leave the Pages deployment from "RunA" in-progress, but the second workflow run will outright fail because it cannot start another Pages deployment for that same branch until the previous deployment is resolved. 🔁 🔀
Failed workflow run example of that particular scenario:
Furthermore, if you never queue any "RunC" after those (or re-run "RunB"), the changes associated with "RunB" may never get deployed. 👻
Haven't been able to reproduce in the recent past. 🤷