fleetlint Policy for a fleet of repositories
v0.11 (latest)
Getting started

ci/concurrency-cancel

PR pipelines cancel superseded runs

Severityinfo
Tiersall
Stacksany
Scoperoot
Kindexpr
Sourcelibrary v0.8.0
Selected byfleetlint-recommended@v0.8.0

Requirement

GitHub and Gitea workflows triggered by pull requests declare concurrency with cancel-in-progress (top level, or on every job). GitLab merge request pipelines mark their jobs interruptible: true (per job or under default:) and do not set workflow: auto_cancel: on_new_commit: none. Forgejo workflows are not checked.

Why

Every push to a PR otherwise queues another full run behind the obsolete one.

Applies when

workflows().exists(w, "pull_request" in triggers(w) && ci_kind(w) != "forgejo")

Check

For each item in:

workflows().filter(w, "pull_request" in triggers(w) && ci_kind(w) != "forgejo")
type(yaml(item)) == map && (ci_kind(item) == "gitlab"
  ? !("workflow" in yaml(item) && type(yaml(item).workflow) == map
      && "auto_cancel" in yaml(item).workflow && type(yaml(item).workflow.auto_cancel) == map
      && "on_new_commit" in yaml(item).workflow.auto_cancel && yaml(item).workflow.auto_cancel.on_new_commit == "none")
    && (jobs(item).all(j, j.interruptible)
      || workflows().exists(g, ci_kind(g) == "gitlab" && type(yaml(g)) == map && "default" in yaml(g)
           && type(yaml(g)["default"]) == map && "interruptible" in yaml(g)["default"]
           && yaml(g)["default"].interruptible == true))
  : ("concurrency" in yaml(item) && type(yaml(item).concurrency) == map
      && "cancel-in-progress" in yaml(item).concurrency && yaml(item).concurrency["cancel-in-progress"] != false)
    || ("jobs" in yaml(item) && type(yaml(item).jobs) == map && yaml(item).jobs.size() > 0
      && yaml(item).jobs.all(k, type(yaml(item).jobs[k]) == map && "concurrency" in yaml(item).jobs[k]
        && type(yaml(item).jobs[k].concurrency) == map && "cancel-in-progress" in yaml(item).jobs[k].concurrency
        && yaml(item).jobs[k].concurrency["cancel-in-progress"] != false)))

Fix

Add a concurrency block keyed on the workflow and ref with cancel-in-progress: true (GitLab: default: interruptible: true).

Agent instruction: Add concurrency: { group: ${{ github.workflow }}-${{ github.ref }}, cancel-in-progress: true } at the top level of the workflow; for GitLab add interruptible: true under default: and leave deploy jobs non-interruptible if they must finish.

Sources


Generated by fleetlint docs from catalog v0.8.0.