Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/actionify/mod.ts>Job#concurrency

Create and manage your GitHub workflows with TypeScript and Deno.
Latest
method Job.prototype.concurrency
import { Job } from "https://deno.land/x/actionify@0.3.0/mod.ts";

Use concurrency to ensure that only a single job or workflow using the same concurrency group will run at a time. A concurrency group can be any string or expression. The expression can only use the github context. For more information about expressions, see "Expressions."

You can also specify concurrency at the job level. For more information, see jobs.<job_id>.concurrency.

When a concurrent job or workflow is queued, if another job or workflow using the same concurrency group in the repository is in progress, the queued job or workflow will be pending. Any previously pending job or workflow in the concurrency group will be canceled. To also cancel any currently running job or workflow in the same concurrency group, specify cancel-in-progress: true.

Using concurrency and the default behavior
import { workflow, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';

const ci = workflow({ name: 'ci' })
  .on('push')
  .concurrency(ctx => e.concat('ci-', ctx.github.ref));
Using concurrency to cancel any in-progress job or run
import { workflow, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';

const ci = workflow({ name: 'ci' })
  .on('push')
  .concurrency(ctx => ({
    group: e.expr(ctx.github.ref),
    'cancel-in-progress': true,
  }));
Using a fallback value

If you build the group name with a property that is only defined for specific events, you can use a fallback value. For example, github.head_ref is only defined on pull_request events. If your workflow responds to other events in addition to pull_request events, you will need to provide a fallback to avoid a syntax error. The following concurrency group cancels in-progress jobs or runs on pull_request events only; if github.head_ref is undefined, the concurrency group will fallback to the run ID, which is guaranteed to be both unique and defined for the run.

import { workflow, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';

const ci = workflow({ name: 'ci' })
  .on('push')
  .concurrency(ctx => ({
    group: e.op(ctx.github.ref, '||', ctx.github.run_id),
    'cancel-in-progress': true,
  }));
Only cancel in-progress jobs or runs for the current workflow

If you have multiple workflows in the same repository, concurrency group names must be unique across workflows to avoid canceling in-progress jobs or runs from other workflows. Otherwise, any previously in-progress or pending job will be canceled, regardless of the workflow.

To only cancel in-progress runs of the same workflow, you can use the github.workflow property to build the concurrency group:

import { workflow, e } from 'https://deno.land/x/actionify@0.3.0/mod.ts';

const ci = workflow({ name: 'ci' })
  .on('push')
  .concurrency(ctx => ({
    group: e.op(ctx.github.ref, '||', ctx.github.run_id),
    'cancel-in-progress': true,
  }));

Parameters

options: WithContext<ConcurrentOptions, Base, "jobs:jobId:concurrency">