Search code examples
github-actionsbuilding-github-actions

How do I hook and execute cleanup commands in a GitHub Action when someone cancels the job?


I'm creating an action (using actions/javascript-actions) that creates something and then needs to clean up that something should someone cancel the job halfway.

I'm having trouble finding how to hook into pre-exit/cancel and do cleanup actions. Is this possible? Does anyone have any suggestions on achieving this?


Solution

  • Finally figured it out. actions/checkout is a great example of the post "runs" to achieve this.

    runs:
      using: node12
      main: dist/index.js
      post: dist/index.js