Skip to content

Commit

Permalink
improve: Split CI test
Browse files Browse the repository at this point in the history
Signed-off-by: Evaldo Felipe <[email protected]>
  • Loading branch information
evaldofelipe committed Sep 25, 2023
1 parent f9ae6d8 commit ff92515
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
52 changes: 35 additions & 17 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,64 @@ name: Checks
on: [push]
env:
NODE_OPTIONS: "--max-old-space-size=6144"
NODE_VERSION: "16"
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
build:
name: Build
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
- name: Install Additional dependencies
run: |
sudo apt-get update -y
sudo apt-get -y install rsync libudev-dev libusb-1.0-0-dev
- name: Use Node $NODE_VERSION
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
node-version: $NODE_VERSION
cache: "yarn"
- name: Install packages
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
- name: Build
run: yarn build
test:
name: Test
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
node: [16]
ci_index: [0, 1, 2, 3]
ci_total: [4]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install Additional dependencies
run: |
sudo apt-get update -y
sudo apt-get -y install rsync libudev-dev libusb-1.0-0-dev
- name: Use Node ${{ matrix.node }}
- name: Use Node $NODE_VERSION
uses: actions/setup-node@v3
with:
node-version: $NODE_VERSION
cache: "yarn"
- name: Execute tests
run: yarn test --bail
env:
CI_TOTAL: ${{ matrix.ci_total }}
CI_INDEX: ${{ matrix.ci_index }}
lint:
name: Lint
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node $NODE_VERSION
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
node-version: $NODE_VERSION
cache: "yarn"
- name: Install packages
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Test
run: yarn test --bail
- name: Lint
run: yarn lint
40 changes: 40 additions & 0 deletions test/split.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import glob from 'glob';

if (!process.env.CI_TOTAL) {
console.error('No environment variable CI_TOTAL defined');
process.exit(1);
}

if (!process.env.CI_INDEX) {
console.error('No environment variable CI_INDEX defined');
process.exit(1);
}

function splitChunks(items: string[], total: number): string[][] {
let chunks: string[][] = [];

let currentChunk = 0;
for (let currentItem = 0; currentItem < items.length; currentItem++) {
if (!chunks[currentChunk]) {
chunks[currentChunk] = [];
}

chunks[currentChunk].push(items[currentItem]);

currentChunk++;
if (currentChunk >= total) {
currentChunk = 0;
}
}

return chunks;
}

const files: string[] = glob.sync('test/**/*.ts');
const chunks: string[][] = splitChunks(files, parseInt(process.env.CI_TOTAL));

if (chunks[parseInt(process.env.CI_INDEX)]) {
for (const file of chunks[parseInt(process.env.CI_INDEX)]) {
process.stdout.write(file + "\n");
}
}

0 comments on commit ff92515

Please sign in to comment.