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 currents cancel

if: cancelled() runs the step only when the workflow was cancelled, so it costs nothing on a normal run.

Which credential to use

currents 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.

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?