Skip to content

Commit

Permalink
chore(ci): split load across a constrained amount of workers
Browse files Browse the repository at this point in the history
  • Loading branch information
magne4000 committed Sep 18, 2024
1 parent 2c95c78 commit 083b636
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
33 changes: 13 additions & 20 deletions .github/workflows/reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ on:
entry:
required: true
type: string
os:
required: true
type: string
node:
required: true
jobs:
reusable_workflow_job:
runs-on: ${{ matrix.os }}
runs-on: ${{ inputs.os }}

env:
BATI_TEST: true
Expand All @@ -17,26 +22,14 @@ jobs:
TEST_GITHUB_CLIENT_ID: ${{ secrets.TEST_GITHUB_CLIENT_ID }}
TEST_GITHUB_CLIENT_SECRET: ${{ secrets.TEST_GITHUB_CLIENT_SECRET }}

strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ ubuntu-latest ]
node: [ 20 ]
# include:
# - os: ubuntu-latest
# node: 18
# - os: ubuntu-latest
# node: 22
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
node-version: ${{ inputs.node }}

- name: Cache for Turbo
uses: rharkor/[email protected]
Expand All @@ -49,25 +42,25 @@ jobs:
- name: Download Bati CLI
uses: actions/download-artifact@v4
with:
name: bati-cli-${{ matrix.os }}-${{ matrix.node }}
name: bati-cli-${{ inputs.os }}-${{ inputs.node }}
path: ./bati-cli

- name: Download Bati tests
uses: actions/download-artifact@v4
with:
name: bati-tests-${{ matrix.os }}-${{ matrix.node }}
name: bati-tests-${{ inputs.os }}-${{ inputs.node }}
path: ./bati-tests

- name: Download tests-utils
uses: actions/download-artifact@v4
with:
name: tests-utils-${{ matrix.os }}-${{ matrix.node }}
name: tests-utils-${{ inputs.os }}-${{ inputs.node }}
path: ./bati-tests-utils

- name: Download tests-files
uses: actions/download-artifact@v4
with:
name: tests-files-${{ matrix.os }}-${{ matrix.node }}
name: tests-files-${{ inputs.os }}-${{ inputs.node }}
path: ./bati-tests-files

- name: Generate dynamic composite action
Expand All @@ -77,8 +70,8 @@ jobs:
id: gen
uses: ./.github/actions/bati-gen
with:
os: ${{ matrix.os }}
node: ${{ matrix.node }}
os: ${{ inputs.os }}
node: ${{ inputs.node }}

- name: Cleanup
if: always() && steps.gen.outcome != 'success'
Expand Down
54 changes: 46 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ jobs:

strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
node: [20]
include:
- os: ubuntu-latest
node: 18
- os: ubuntu-latest
node: 22
fail-fast: false

steps:
Expand Down Expand Up @@ -172,7 +166,18 @@ jobs:

- name: List e2e tests
id: list-e2e
run: pnpm run test:e2e list --workers 10
run: pnpm run test:e2e list --workers 5
env:
TEST_AUTH0_CLIENT_ID: ${{ secrets.TEST_AUTH0_CLIENT_ID }}
TEST_AUTH0_ISSUER_BASE_URL: ${{ secrets.TEST_AUTH0_ISSUER_BASE_URL }}
TEST_FIREBASE_ACCOUNT: ${{ secrets.TEST_FIREBASE_ACCOUNT }}
TEST_FIREBASE_USER_UID: ${{ secrets.TEST_FIREBASE_USER_UID }}
TEST_GITHUB_CLIENT_ID: ${{ secrets.TEST_GITHUB_CLIENT_ID }}
TEST_GITHUB_CLIENT_SECRET: ${{ secrets.TEST_GITHUB_CLIENT_SECRET }}

- name: List e2e tests
id: list-e2e-small
run: pnpm run test:e2e list --workers 1 --filter=react,hono
env:
TEST_AUTH0_CLIENT_ID: ${{ secrets.TEST_AUTH0_CLIENT_ID }}
TEST_AUTH0_ISSUER_BASE_URL: ${{ secrets.TEST_AUTH0_ISSUER_BASE_URL }}
Expand All @@ -183,6 +188,7 @@ jobs:

outputs:
test-matrix: ${{ steps.list-e2e.outputs.test-matrix }}
test-matrix-small: ${{ steps.list-e2e-small.outputs.test-matrix }}

# - name: Archive summary
# if: matrix.os == 'ubuntu-latest'
Expand All @@ -204,3 +210,35 @@ jobs:
secrets: inherit
with:
entry: ${{ matrix.test-matrix[1] }}
os: ubuntu-latest
node: 20

generated-windows:
needs: monorepo
strategy:
fail-fast: false
matrix:
test-matrix: ${{ fromJson(needs.monorepo.outputs.test-matrix-small) }}
name: "Trigger e2e tests: Group Windows"

uses: ./.github/workflows/reusable.yml
secrets: inherit
with:
entry: ${{ matrix.test-matrix[1] }}
os: windows-latest
node: 20

generated-macos:
needs: monorepo
strategy:
fail-fast: false
matrix:
test-matrix: ${{ fromJson(needs.monorepo.outputs.test-matrix-small) }}
name: "Trigger e2e tests: Group MacOS"

uses: ./.github/workflows/reusable.yml
secrets: inherit
with:
entry: ${{ matrix.test-matrix[1] }}
os: macos-latest
node: 20
9 changes: 6 additions & 3 deletions packages/tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ async function spinner<T>(title: string, callback: () => T): Promise<T> {
return zx.spinner(title, callback);
}

function chunkArray<T>(arr: T[], size: number): T[][] {
function chunkArray<T>(arr: T[], maxChunks: number): T[][] {
if (maxChunks <= 0) throw new Error("The number of chunks must be greater than 0");

const result: T[][] = [];
const chunkSize = Math.ceil(arr.length / Math.min(arr.length, maxChunks));

for (let i = 0; i < arr.length; i += size) {
result.push(arr.slice(i, i + size));
for (let i = 0; i < arr.length; i += chunkSize) {
result.push(arr.slice(i, i + chunkSize));
}

return result;
Expand Down

0 comments on commit 083b636

Please sign in to comment.