Skip to content
Latchkey

How to Add Pre and Post Steps to a Custom Action

The pre and post keys run extra scripts before and after a JavaScript action main, ideal for setup and cleanup.

Add runs.pre and runs.post in action.yml. The runner executes pre before the job step, main during it, and post at the end of the job even if a later step failed.

Steps

  • Point runs.main at the primary script.
  • Add runs.pre for setup that runs before the step.
  • Add runs.post for cleanup that always runs at job end.

action.yml

action.yml
runs:
  using: "node20"
  pre: "setup.js"
  main: "index.js"
  post: "cleanup.js"
  post-if: "always()"

cleanup.js

index.js
const core = require('@actions/core');
core.info('Tearing down the temporary tunnel');

Gotchas

  • pre and post are supported for JavaScript actions, not composite or Docker.
  • Use post-if to control whether cleanup runs on success, failure, or always.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →