Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Cancel Runs on Workflow Cancellation

Cancel the Currents run when a GitHub Actions workflow is cancelled

A cancelled workflow stops reporting mid-run. Currents has no way to tell that apart from a job that is still working, so the run stays in progress until it hits the project's Run Timeouts. That leaves a run sitting in the feed as if it were live, for up to an hour.

Add a step that cancels the run when the job is cancelled:

- name: Cancel the Currents run
  if: ${{ cancelled() }}
  run: npx --package @currents/cmd@2 currents run cancel

if: cancelled() runs the step only when the workflow was cancelled, so it costs nothing on a normal run. npx --package @currents/cmd@2 runs the @currents/cmd 2.x command without adding the package to the project. The command requires Node.js 20 or later.

Which credential to use

currents run cancel authenticates with the Record Key the job already uses to report results, so no additional secret is needed. It identifies the run by its CI Build ID or its run ID, which means the same step works on any CI provider.

The cancel-run-gh-action does the same as a GitHub action and accepts either a record key or an API Keys:

- name: Cancel the Currents run
  if: ${{ cancelled() }}
  uses: currents-dev/cancel-run-gh-action@v1

With no inputs, the action reads CURRENTS_RECORD_KEY, CURRENTS_PROJECT_ID and CURRENTS_CI_BUILD_ID from the environment. Declare them on the job, the way the full example below does — a step's env is visible only to that step, so variables set on the reporting step reach the cancelling step empty.

Without a record key or API key, cancel-run-gh-action 1.2.0 or later (@v1) and currents run cancel from @currents/cmd 3.1.0 or later get a short-lived record key from the job's OIDC token when the job has permissions: id-token: write. See Record from CI with an OIDC token instead of a record key.

Like the command, the action can also identify the run by its run ID, through the run-id input or CURRENTS_RUN_ID. The action's README lists every input.

Full example

concurrency with cancel-in-progress: true is what makes this worth setting up: every push to a branch cancels the workflow still running for the previous commit, and each of those leaves a run behind.

Notes

  • Parallel jobs. Every job of a parallelized run records into the same run, and every one of them can run the cancellation step. Cancelling a run that is already cancelled succeeds.

  • Nothing recorded yet. A workflow cancelled before the first results reached Currents has no run to cancel. The step reports that and succeeds, so it does not add a failed step to an already cancelled workflow.

  • Hard cancellations. A job killed without running its remaining steps never reaches the step. That covers a cancelled job that does not honour if: cancelled(), and a runner that disappears. Those runs still end at the inactivity timeout.

See Cancelling Runs for what cancelling a run affects: test statuses, plan usage, analytics and integrations.

Last updated

Was this helpful?