From e7fd994259afbe59b74f64c654626664e2744075 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 28 Dec 2024 22:28:36 +0900 Subject: [PATCH 1/5] speed up CI by parallelizing more things --- .github/workflows/bench.yml | 32 ------- .github/workflows/ci.yml | 174 +++++++++++++++++++++++++++--------- package.json | 8 +- 3 files changed, 141 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/bench.yml diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml deleted file mode 100644 index e8805d5f85..0000000000 --- a/.github/workflows/bench.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Performance Benchmarks -permissions: - contents: read -on: - push: - branches: [master] - pull_request: - workflow_dispatch: -jobs: - benchmark: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version-file: "package.json" - - - name: Install dependencies - run: npm ci - - - name: Build Libs - run: npm run build:libs - - - name: Run Benchmarks - uses: CodSpeedHQ/action@v3 - with: - token: ${{ secrets.CODSPEED_TOKEN }} - run: npm run bench diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 862036dc25..4e3a34eaa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,8 @@ on: merge_group: jobs: - static-analysis: - name: Static Analysis + setup: + name: Setup runs-on: ubuntu-latest steps: - name: Checkout @@ -28,47 +28,138 @@ jobs: - name: Build third-party libraries run: npm run build:libs - - name: Run static analysis tests - run: npm run test:static-analysis + - name: Upload workspace + uses: actions/upload-artifact@v4 + with: + name: workspace + path: . - static-analysis-json: - name: Static Analysis (JSON) + js: + needs: setup + name: JavaScript runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace - - name: Setup node - uses: actions/setup-node@v4 + - name: Test JavaScript + run: npm run test:js + + ts-main: + needs: setup + name: TypeScript (main) + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 with: - node-version-file: "package.json" + name: workspace - - name: Install dependencies - run: npm ci + - name: Test TypeScript (main) + run: npm run test:ts:main - - name: Build third-party libraries - run: npm run build:libs + ts-dev: + needs: setup + name: TypeScript + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace - - name: Run static analysis tests - run: npm run test:json + - name: Test TypeScript (dev) + run: npm run test:ts:dev - unit-tests: - name: Unit Tests + ts-test: + needs: setup + name: TypeScript runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace - - name: Setup node - uses: actions/setup-node@v4 + - name: Test TypeScript (test) + run: npm run test:ts:test + + ts-bench: + needs: setup + name: TypeScript + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 with: - node-version-file: "package.json" + name: workspace - - name: Install dependencies - run: npm ci + - name: Test TypeScript (bench) + run: npm run test:ts:bench - - name: Build third-party libraries - run: npm run build:libs + css: + needs: setup + name: CSS + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace + + - name: Test CSS + run: npm run test:css + + html: + needs: setup + name: HTML + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace + + - name: Test HTML + run: npm run test:html + + markdown: + needs: setup + name: Markdown + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace + + - name: Test Markdown + run: npm run test:md + + json: + needs: setup + name: JSON + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace + + - name: Test JSON + run: npm run test:json + + unit-tests: + needs: setup + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Download workspace + uses: actions/download-artifact@v4 + with: + name: workspace - name: Run unit tests run: npm run test:unit @@ -77,22 +168,14 @@ jobs: run: npm run test:unit:options test-build: + needs: setup name: Test Build runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup node - uses: actions/setup-node@v4 + - name: Download workspace + uses: actions/download-artifact@v4 with: - node-version-file: "package.json" - - - name: Install dependencies - run: npm ci - - - name: Build Libs - run: npm run build:libs + name: workspace - name: Build Legal run: npm run license-report:html @@ -106,3 +189,14 @@ jobs: file: ext/manifest.json schema: "https://json.schemastore.org/chrome-manifest.json" fixSchemas: true + + bench: + needs: setup + name: Benchmarks + runs-on: ubuntu-latest + steps: + - name: Run Benchmarks + uses: CodSpeedHQ/action@513a19673a831f139e8717bf45ead67e47f00044 # v3.2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: npm run bench diff --git a/package.json b/package.json index 1aab3df772..2084469b43 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,16 @@ "build:libs": "node ./dev/bin/build-libs.js", "build:serve:firefox-android": "node ./dev/bin/build.js --target firefox-android && web-ext run -s ./builds/yomitan-firefox-android", "build:serve:kiwi-browser": "node ./dev/bin/build.js --target chrome-dev && adb shell mkdir -p /sdcard/yomitan && adb push ./builds/yomitan-chrome-dev.zip /sdcard/yomitan/yomitan-kiwi-browser.zip", + + + "//WARNING": "These are convenience functions for running from CLI but are NOT called from CI because they are not parallel. Make sure you update CI scripts if you update these.", "test": "npm run test:js && npm run test:ts && npm run test:css && npm run test:html && npm run test:unit && npm run test:unit:options && npm run test:json && npm run test:md && npm run test:build", "test:fast": "npm run test:js && npm run test:ts && npm run test:unit && npm run test:json:format", "test:static-analysis": "npm run test:js && npm run test:ts && npm run test:css && npm run test:html && npm run test:md", + "test:ts": "npm run test:ts:main && npm run test:ts:dev && npm run test:ts:test && npm run test:ts:bench", + "//END-WARNING": "", + + "test:js": "npx eslint . --ignore-pattern '**/*.json'", "test:json": "npm run test:json:format && npm run test:json:types", "test:json:format": "npx eslint '**/*.json'", @@ -27,7 +34,6 @@ "test:html": "npx html-validate \"ext/**/*.html\" \"test/**/*.html\" \"dev/**/*.html\"", "test:md": "prettier . --check", "test:md:write": "prettier . --write", - "test:ts": "npm run test:ts:main && npm run test:ts:dev && npm run test:ts:test && npm run test:ts:bench", "test:ts:main": "npx tsc --noEmit --project jsconfig.json", "test:ts:dev": "npx tsc --noEmit --project dev/jsconfig.json", "test:ts:test": "npx tsc --noEmit --project test/jsconfig.json", From 35d3f364d3afaa2bbcdc67117664d17cf70d9c13 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 28 Dec 2024 22:35:31 +0900 Subject: [PATCH 2/5] add node_modules caching for when package-lock hasn't changed --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e3a34eaa4..6f5f8f37ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,15 @@ jobs: with: node-version-file: "package.json" + - name: Restore dependencies + id: restore-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: js-depend-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} + - name: Install dependencies + if: steps.restore-dependencies.outputs.cache-hit != 'true' run: npm ci - name: Build third-party libraries From 5e476599e2e4dc550f3d5e1a410bdabe7f075f91 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 28 Dec 2024 22:42:05 +0900 Subject: [PATCH 3/5] Wasn't quite able to do it with artifacts so instead build a composite action --- .github/actions/setup/action.yml | 25 ++++++ .github/workflows/ci.yml | 129 ++++++++----------------------- 2 files changed, 58 insertions(+), 96 deletions(-) create mode 100644 .github/actions/setup/action.yml diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000000..a14ac58736 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,25 @@ +name: Setup +description: Setup the workspace for the CI +runs: + using: "composite" + steps: + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version-file: "package.json" + + - name: Restore dependencies + id: restore-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: js-depend-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.restore-dependencies.outputs.cache-hit != 'true' + shell: bash + run: npm ci + + - name: Build third-party libraries + shell: bash + run: npm run build:libs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f5f8f37ea..a8601c2e92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,164 +10,102 @@ on: merge_group: jobs: - setup: - name: Setup - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version-file: "package.json" - - - name: Restore dependencies - id: restore-dependencies - uses: actions/cache@v4 - with: - path: node_modules - key: js-depend-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - - name: Install dependencies - if: steps.restore-dependencies.outputs.cache-hit != 'true' - run: npm ci - - - name: Build third-party libraries - run: npm run build:libs - - - name: Upload workspace - uses: actions/upload-artifact@v4 - with: - name: workspace - path: . - js: - needs: setup name: JavaScript runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test JavaScript run: npm run test:js ts-main: - needs: setup name: TypeScript (main) runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test TypeScript (main) run: npm run test:ts:main ts-dev: - needs: setup - name: TypeScript + name: TypeScript (dev) runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test TypeScript (dev) run: npm run test:ts:dev ts-test: - needs: setup - name: TypeScript + name: TypeScript (test) runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test TypeScript (test) run: npm run test:ts:test ts-bench: - needs: setup - name: TypeScript + name: TypeScript (bench) runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test TypeScript (bench) run: npm run test:ts:bench css: - needs: setup name: CSS runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test CSS run: npm run test:css html: - needs: setup name: HTML runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test HTML run: npm run test:html markdown: - needs: setup name: Markdown runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test Markdown run: npm run test:md json: - needs: setup name: JSON runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Test JSON run: npm run test:json unit-tests: - needs: setup name: Unit Tests runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Run unit tests run: npm run test:unit @@ -176,14 +114,11 @@ jobs: run: npm run test:unit:options test-build: - needs: setup name: Test Build runs-on: ubuntu-latest steps: - - name: Download workspace - uses: actions/download-artifact@v4 - with: - name: workspace + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup - name: Build Legal run: npm run license-report:html @@ -199,12 +134,14 @@ jobs: fixSchemas: true bench: - needs: setup name: Benchmarks runs-on: ubuntu-latest steps: - - name: Run Benchmarks - uses: CodSpeedHQ/action@513a19673a831f139e8717bf45ead67e47f00044 # v3.2 - with: - token: ${{ secrets.CODSPEED_TOKEN }} - run: npm run bench + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + + - name: Run Benchmarks + uses: CodSpeedHQ/action@513a19673a831f139e8717bf45ead67e47f00044 # v3.2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: npm run bench From 2240f95a147449f90552bc0039e4b270a9ca3c20 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 28 Dec 2024 22:56:46 +0900 Subject: [PATCH 4/5] simplify with matrix --- .github/workflows/ci.yml | 125 +++++++++------------------------------ 1 file changed, 29 insertions(+), 96 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8601c2e92..78efc70eef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,108 +10,41 @@ on: merge_group: jobs: - js: - name: JavaScript + tests: + name: ${{ matrix.name }} runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test JavaScript - run: npm run test:js - - ts-main: - name: TypeScript (main) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test TypeScript (main) - run: npm run test:ts:main - - ts-dev: - name: TypeScript (dev) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test TypeScript (dev) - run: npm run test:ts:dev - - ts-test: - name: TypeScript (test) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test TypeScript (test) - run: npm run test:ts:test - - ts-bench: - name: TypeScript (bench) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup + strategy: + matrix: + include: + - name: JavaScript + test: test:js + - name: TypeScript (main) + test: test:ts:main + - name: TypeScript (dev) + test: test:ts:dev + - name: TypeScript (test) + test: test:ts:test + - name: TypeScript (bench) + test: test:ts:bench + - name: CSS + test: test:css + - name: HTML + test: test:html + - name: Markdown + test: test:md + - name: JSON + test: test:json + - name: Unit Tests + test: test:unit + - name: Unit Tests (options) + test: test:unit:options - - name: Test TypeScript (bench) - run: npm run test:ts:bench - - css: - name: CSS - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test CSS - run: npm run test:css - - html: - name: HTML - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test HTML - run: npm run test:html - - markdown: - name: Markdown - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/setup - - name: Test Markdown - run: npm run test:md - - json: - name: JSON - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Test JSON - run: npm run test:json - - unit-tests: - name: Unit Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - - name: Run unit tests - run: npm run test:unit - - - name: Run unit tests (options) - run: npm run test:unit:options + - name: Run ${{ matrix.name }} tests + run: npm run ${{ matrix.test }} test-build: name: Test Build From 855dcf73399ffef05f0b6232187ded60ef914fa2 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 28 Dec 2024 23:02:05 +0900 Subject: [PATCH 5/5] use the new shared setup action where appropriate --- .github/workflows/create-prerelease-on-tag.yml | 1 + .github/workflows/playwright.yml | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/create-prerelease-on-tag.yml b/.github/workflows/create-prerelease-on-tag.yml index 19be4e7185..f86e4fd6a0 100644 --- a/.github/workflows/create-prerelease-on-tag.yml +++ b/.github/workflows/create-prerelease-on-tag.yml @@ -22,6 +22,7 @@ jobs: with: node-version-file: "package.json" + # intentially do not use cache to keep the build more comprehensible and sandboxed - name: Install dependencies run: npm ci diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index a4b57fe482..5c2f1db420 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -26,13 +26,7 @@ jobs: packages: fonts-ipafont-mincho execute_install_scripts: true - - uses: actions/setup-node@v4 - with: - cache: "npm" - node-version-file: "package.json" - - - name: Install dependencies - run: npm ci + - uses: ./.github/actions/setup - name: Build run: npm run build