admin管理员组

文章数量:1398819

I'm trying to configure a GitHub Actions workflow where all tests run sequentially on a single runner instance without spawning multiple runners of the same type.

What I Want to Achieve:

  • I have a matrix of tests and runner types.
  • For each runner type, I want all the tests to run one after another (sequentially) instead of running in parallel. As I don't want GitHub Actions to scale up and create multiple runners of the same type.
  • However, if I have different runner types (e.g., t4g.small, t4g.medium, t4g.large), I want those to run in parallel on their respective instances.

Example Scenario:

  • Runners: t4g.small, t4g.medium, t4g.large
  • Tests: test1, test2, test3

Expected Execution:

  • On t4g.small: test1 → test2 → test3 (Sequentially)
  • On t4g.medium: test1 → test2 → test3 (Sequentially)
  • On t4g.large: test1 → test2 → test3 (Sequentially)

All three runners can run in parallel, but each test within a runner should queue up and run one after another.


What I Tried:

  1. Using concurrency with Matrix Strategy:
concurrency:
  group: "${{ matrix.instance_type }}"
  cancel-in-progress: false
  • This didn't work as expected. It canceled jobs in progress with messages like:

    Canceling since a higher priority waiting request for ... exists

  1. Using Queuing with max-parallel: 1:
strategy:
  max-parallel: 1
  • This applied globally, limiting the total number of jobs, which is not what I wanted.

My Current Workflow Code:

name: Concurrency Test

on:
  push:
    branches:
      - main

jobs:
  setup-matrix:
    runs-on: ubuntu-latest
    outputs:
      instance_types: ${{ steps.set-output.outputs.instance_types }}
      tests: ${{ steps.set-output.outputs.tests }}
    steps:
      - name: Set Matrix Variables
        id: set-output
        run: |
          echo 'instance_types=["t4g.small","t4g.medium","t4g.large"]' >> $GITHUB_OUTPUT
          echo 'tests=["test1","test2","test3"]' >> $GITHUB_OUTPUT

  run-tests:
    name: Run ${{ matrix.test }} on ${{ matrix.instance_type }}
    needs: setup-matrix
    runs-on: ${{ matrix.instance_type }}
    strategy:
      fail-fast: false
      matrix:
        instance_type: ${{ fromJson(needs.setup-matrix.outputs.instance_types) }}
        test: ${{ fromJson(needs.setup-matrix.outputs.tests) }}
    concurrency:
      group: ${{ matrix.instance_type }}
      cancel-in-progress: false
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Initialize Counter
        run: echo "COUNTER=0" >> $GITHUB_ENV

      - name: Increment Counter
        run: |
          COUNTER=$((COUNTER+1))
          echo "COUNTER=$COUNTER" >> $GITHUB_ENV
          echo "Running Job Number: $COUNTER for ${{ matrix.instance_type }} ${{ matrix.test }}"

      - name: Simulate Task
        run: sleep 5

Question:

  • How can I configure GitHub Actions to ensure all tests on a single runner type run sequentially while still allowing different runner types to run in parallel?
  • Is there a way to queue up jobs for a specific runner type without relying on concurrency canceling jobs?

Any suggestions or workarounds would be greatly appreciated!

本文标签: