Skip to content

GitHub Actions Concurrency Optimization

Overview

Implemented automatic cancellation of redundant CI/CD workflows to save build minutes and improve developer experience as specified in Linear issue ENG-322.

Implementation Details

1. Main CI/CD Workflow (main.yml)

Added intelligent concurrency control:

yaml
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/meclabs') }}
  • Cancel Strategy: Cancel in-progress runs for pull requests and non-main branch pushes
  • Protection: Never cancels workflows on the main meclabs branch to ensure critical builds complete

2. E2E Test Workflow (test.yml)

Added concurrency control for test runs:

yaml
concurrency:
  group: e2e-${{ inputs.environment }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
  • Cancel Strategy: Always cancel in-progress runs since tests can be safely re-run

3. Deploy Workflow (deploy.yml)

Implemented selective cancellation based on environment:

yaml
concurrency:
  group: deploy-${{ inputs.environment }}-${{ inputs.pr || github.ref }}
  cancel-in-progress: ${{ inputs.environment != 'prod' }}
  • Protection: Production deployments are NEVER cancelled to prevent deployment issues

4. PR Title Validation (pr-title.yml)

Added concurrency for PR title checks:

yaml
concurrency:
  group: pr-title-${{ github.event.pull_request.number }}
  cancel-in-progress: true
  • Cancel Strategy: Always cancel in-progress runs for quick validation

Benefits

  1. Cost Reduction: Eliminates redundant builds when multiple commits are pushed quickly
  2. Faster Feedback: Developers get results from their latest changes without waiting
  3. Resource Optimization: CI/CD runners are freed up for current work
  4. Safety: Production deployments are protected from cancellation

Concurrency Behavior

What Gets Cancelled

  • Feature branch builds when new commits are pushed
  • Pull request checks when updates are made
  • Test runs and linting checks
  • Preview/test environment deployments

What Never Gets Cancelled

  • Production deployments
  • Workflows running on the main meclabs branch
  • Workflow dispatch events (manual triggers)

Monitoring

To track the effectiveness of these changes:

  1. Monitor GitHub Actions usage metrics for reduction in minutes
  2. Track average time from push to CI feedback
  3. Review cancelled workflow counts in GitHub Actions history

References