From 06aa464823328d5519ea5da8dc37c875532a99c2 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 8 Feb 2023 15:42:07 +0100 Subject: [PATCH 1/3] Split matrix items into chunks to bypass the 256 limit of matrix items in github actions --- .github/workflows/run-matrix.yml | 37 +++++++++++++++ .github/workflows/test.yml | 77 +++++++++++++++++++++----------- 2 files changed, 89 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/run-matrix.yml diff --git a/.github/workflows/run-matrix.yml b/.github/workflows/run-matrix.yml new file mode 100644 index 000000000..02b7aae1e --- /dev/null +++ b/.github/workflows/run-matrix.yml @@ -0,0 +1,37 @@ +name: run-matrix + +on: + workflow_call: + inputs: + include: + required: true + description: Matrix include JSON string + type: string + +jobs: + docker: + name: "docker (version: ${{ matrix.version }}, framework: ${{ matrix.framework }})" + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + include: ${{ fromJSON(inputs.include) }} + steps: + - uses: actions/checkout@v3 + - name: Run tests + run: ./tests/scripts/docker/run_tests.sh ${{ matrix.version }} ${{ matrix.framework }} + env: + LOCALSTACK_VOLUME_DIR: localstack_data + - if: success() || failure() + name: Upload JUnit Test Results + uses: actions/upload-artifact@v3 + with: + name: test-results + path: "**/*-python-agent-junit.xml" + - if: success() || failure() + name: Upload Coverage Reports + uses: actions/upload-artifact@v3 + with: + name: coverage-reports + path: "**/.coverage*" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a91305c7..69bf12159 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,8 @@ jobs: runs-on: ubuntu-latest outputs: matrix: ${{ steps.generate.outputs.matrix }} + data: ${{ steps.split.outputs.data }} + chunks: ${{ steps.split.outputs.chunks }} steps: - uses: actions/checkout@v3 - id: generate @@ -30,34 +32,59 @@ jobs: # Use .ci/.matrix_framework_full.yml if it's a scheduled workflow, otherwise use .ci/.matrix_framework.yml frameworksFile: .ci/.matrix_framework${{ github.event_name == 'schedule' && '_full' || '' }}.yml excludedFile: .ci/.matrix_exclude.yml + - name: Split matrix + shell: python + id: split + run: | + import os + import json + + def split(lst, n): + return [lst[i::n] for i in range(n)] + + matrix = json.loads(os.environ['GENERATED_MATRIX']) + chunks = split(matrix['include'], 4) + + data = { + 'one': chunks[0], + 'two': chunks[1], + 'three': chunks[2], + 'four': chunks[3], + } + + data_json = json.dumps(data) + chunks_json = json.dumps(chunks) + + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + print(f'data={data_json}', file=f) + print(f'chunks={chunks_json}', file=f) - docker: - name: "docker (version: ${{ matrix.version }}, framework: ${{ matrix.framework }})" - needs: create-matrix - runs-on: ubuntu-latest - strategy: - fail-fast: false - max-parallel: 10 - matrix: ${{ fromJson(needs.create-matrix.outputs.matrix) }} - steps: - - uses: actions/checkout@v3 - - name: Run tests - run: ./tests/scripts/docker/run_tests.sh ${{ matrix.version }} ${{ matrix.framework }} env: - LOCALSTACK_VOLUME_DIR: localstack_data - - if: success() || failure() - name: Upload JUnit Test Results - uses: actions/upload-artifact@v3 - with: - name: test-results - path: "**/*-python-agent-junit.xml" - - if: success() || failure() - name: Upload Coverage Reports - uses: actions/upload-artifact@v3 - with: - name: coverage-reports - path: "**/.coverage*" + GENERATED_MATRIX: ${{ steps.generate.outputs.matrix }} + chunks-0: + needs: create-matrix + uses: ./.github/workflows/run-matrix.yml + with: + include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[0]) }} + + chunks-1: + needs: create-matrix + uses: ./.github/workflows/run-matrix.yml + with: + include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[1]) }} + + chunks-2: + needs: create-matrix + uses: ./.github/workflows/run-matrix.yml + with: + include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[2]) }} + + chunks-3: + needs: create-matrix + uses: ./.github/workflows/run-matrix.yml + with: + include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[3]) }} windows: name: "windows (version: ${{ matrix.version }}, framework: ${{ matrix.framework }}, asyncio: ${{ matrix.asyncio }})" From f65680096d53f8e5aad36ea382613202d9f9b67d Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 8 Feb 2023 17:34:16 +0100 Subject: [PATCH 2/3] cleanup --- .github/workflows/test.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 69bf12159..05ca20f9b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,19 +44,9 @@ jobs: matrix = json.loads(os.environ['GENERATED_MATRIX']) chunks = split(matrix['include'], 4) - - data = { - 'one': chunks[0], - 'two': chunks[1], - 'three': chunks[2], - 'four': chunks[3], - } - - data_json = json.dumps(data) chunks_json = json.dumps(chunks) with open(os.environ['GITHUB_OUTPUT'], 'a') as f: - print(f'data={data_json}', file=f) print(f'chunks={chunks_json}', file=f) env: From d5bac7fbd49f1f0f70b3c4a28becad628b2e70eb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 8 Feb 2023 18:11:26 +0100 Subject: [PATCH 3/3] Add comments --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05ca20f9b..2738f9269 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,10 @@ jobs: return [lst[i::n] for i in range(n)] matrix = json.loads(os.environ['GENERATED_MATRIX']) + + # Using the number 4 because the full matrix has roughly 400+ items + # Hence, it is split into chunks of size ~100 + # We are doing this because the matrix in GH actions has a max limit of 256 chunks = split(matrix['include'], 4) chunks_json = json.dumps(chunks)