Skip to content

[CAT-2931] feat: add distributed lock and should-run-integration-tests actions#7

Merged
dvacca-onfido merged 7 commits into
mainfrom
add-lock-action
Jul 10, 2026
Merged

[CAT-2931] feat: add distributed lock and should-run-integration-tests actions#7
dvacca-onfido merged 7 commits into
mainfrom
add-lock-action

Conversation

@dvacca-onfido

@dvacca-onfido dvacca-onfido commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds two new composite actions to prevent SDK integration tests from running in parallel across repositories and to centralise the logic for when tests should run.

New actions

lock/acquire & lock/release

A distributed lock mechanism using a git branch in a dedicated lock repository (onfido/ci-lock) as an atomic mutex.

  • Acquire: creates a branch locks/<lock-name> — git ref creation is atomic, so only one workflow succeeds. Others poll until the lock is released or timeout (default: 30 min, polling every 30s).
  • Release: deletes the lock branch. Should always run with if: always() to prevent stale locks.
  • Lock holder info: after acquiring, pushes a metadata commit so waiting jobs can see which repo/run holds the lock.
  • Ownership check: release verifies the current run owns the lock before deleting, preventing a timed-out workflow from releasing another run's lock.
  • Auth: uses a GitHub App via actions/create-github-app-token@v2 — short-lived, auto-rotating tokens scoped to the lock repo.

should-run-integration-tests

Determines whether integration tests should run based on the workflow event:

Event Runs tests?
pull_request (internal branch) ✅ Yes
pull_request (fork) ❌ No (secrets unavailable)
push (merge from fork PR) ✅ Yes (catches what couldn't run pre-merge)
push (internal merge/direct) ❌ No (already tested on pull_request)
release / workflow_dispatch / schedule ✅ Yes

Usage

- name: Should run integration tests
  id: should-run-integration-tests
  if: <per-repo matrix/version check>
  uses: onfido/onfido-actions/should-run-integration-tests@main

- name: Acquire integration test lock
  if: steps.should-run-integration-tests.outputs.result == 'true'
  uses: onfido/onfido-actions/lock/acquire@main
  with:
    app-id: ${{ secrets.ONFIDO_CI_LOCK_APP_ID }}
    app-private-key: ${{ secrets.ONFIDO_CI_LOCK_PRIVATE_KEY }}

# ... run tests ...

- name: Release integration test lock
  if: always() && steps.should-run-integration-tests.outputs.result == 'true'
  uses: onfido/onfido-actions/lock/release@main
  with:
    app-id: ${{ secrets.ONFIDO_CI_LOCK_APP_ID }}
    app-private-key: ${{ secrets.ONFIDO_CI_LOCK_PRIVATE_KEY }}

Setup requirements

  1. A GitHub App installed on the org with write access to the ci-lock repository
  2. Two org-level secrets: ONFIDO_CI_LOCK_APP_ID and ONFIDO_CI_LOCK_PRIVATE_KEY

Related PRs

Adds lock/acquire and lock/release composite actions that use a git
branch in onfido/ci-lock as a cross-repository mutex. Creating a git
ref is atomic, making this a reliable distributed lock mechanism.

- lock/acquire: creates a branch to claim lock, polls with timeout
- lock/release: deletes the branch to free lock

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dvacca-onfido dvacca-onfido changed the title [CAT-2931] feat: add distributed lock action using git branch mutex [CAT-2931] feat: add distributed lock and should-run-integration-tests actions Jul 9, 2026
Determines whether integration tests should run based on the event type.
Returns result=true for pull_request, release, workflow_dispatch, schedule
events, and for push events from merged fork PRs (where secrets weren't
available pre-merge).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace github-token with GitHub App credentials (app-id, app-private-key,
app-installation-id) for generating short-lived tokens via
actions/create-github-app-token@v1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dvacca-onfido and others added 2 commits July 10, 2026 12:37
After acquiring the lock, push an empty commit with metadata (repo name
and run URL). When waiting for a held lock, display who holds it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dvacca-onfido dvacca-onfido self-assigned this Jul 10, 2026

@miguelvieiraentrust miguelvieiraentrust left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

dvacca-onfido

This comment was marked as resolved.

dvacca-onfido and others added 2 commits July 10, 2026 14:30
Prevents a timed-out workflow from accidentally releasing another
workflow's lock by checking the commit message for the current run ID.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dvacca-onfido dvacca-onfido merged commit 50b9a95 into main Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants