deploy-pages icon indicating copy to clipboard operation
deploy-pages copied to clipboard

Add post hook to cancel in-progress deployments if the job/workflow run ends unsuccessfully

Open JamesMGreene opened this issue 2 years ago • 1 comments

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#runspost
  • postif: 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 post cleanup 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

JamesMGreene avatar Feb 16 '23 18:02 JamesMGreene

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:

screenshot of Pages deployment failing due to concurrency

Furthermore, if you never queue any "RunC" after those (or re-run "RunB"), the changes associated with "RunB" may never get deployed. 👻

JamesMGreene avatar Mar 21 '23 17:03 JamesMGreene

Haven't been able to reproduce in the recent past. 🤷

JamesMGreene avatar Apr 29 '24 18:04 JamesMGreene