From 09e1ff71c1910a7ac2754d374f29f9ef51a54721 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:29:46 +0800 Subject: [PATCH 1/9] ci: speed up the CI by running tests concurrently --- .github/workflows/ci.yml | 105 +++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dac657cd..ddc14409 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,38 +11,99 @@ on: branches: - '**' jobs: + build: + runs-on: ubuntu-latest + name: Build the package + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + - uses: pnpm/action-setup@v2 + with: + version: 7 + - run: pnpm install + env: + CYPRESS_INSTALL_BINARY: 0 + - run: pnpm build + + # Use cache to share the output across different jobs + # No need to cache node_modules because they are all bundled + - uses: actions/cache/save@v3 + id: cache + with: + path: outfile.cjs + key: ${{ github.sha }}-${{ hashFiles('pnpm-lock.yaml') }} + test: - runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.os == 'windows-latest' }} + needs: build strategy: - fail-fast: false matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - node-version: - - 16 + os: [ubuntu-latest, macos-latest, windows-latest] + node-version: [18] + flag-for-ts: ['--typescript', ''] + flag-for-jsx: ['--jsx', ''] + flag-for-router: ['--router', ''] + flag-for-pinia: ['--pinia', ''] + flag-for-vitest: ['--vitest', ''] + flag-for-e2e: ['--cypress', '--playwright', ''] + flag-for-linter-and-formatter: ['--eslint', '--eslint --prettier', ''] include: - node-version: 14 os: ubuntu-latest - - node-version: 18 + - node-version: 16 os: ubuntu-latest - name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.os == 'windows-latest' }} + env: + FEATURE_FLAGS: ${{ matrix.flag-for-ts }} ${{ matrix.flag-for-jsx }} ${{ matrix.flag-for-router }} ${{ matrix.flag-for-pinia }} ${{ matrix.flag-for-vitest }} ${{ matrix.flag-for-e2e }} steps: - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - uses: pnpm/action-setup@v2.2.4 - with: - version: 6 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'pnpm' - - run: pnpm install - - run: pnpm pretest - - name: Install Playground Dependencies - working-directory: ./playground - run: pnpm install --no-frozen-lockfile - - run: pnpm test + - uses: pnpm/action-setup@v2 + with: + version: 7 + - uses: actions/cache/restore@v3 + id: cache-restore + with: + path: outfile.cjs + key: ${{ github.sha }}-${{ hashFiles('pnpm-lock.yaml') }} + - name: Build the package on cache miss + if: steps.cache.outputs.cache-hit != 'true' + run: pnpm install && pnpm build + env: + CYPRESS_INSTALL_BINARY: 0 + + - if: ${{ (contains(env.FEATURE_FLAGS, '--')) }} + name: Create the sample project with feature flags + run: node ./outfile.cjs sample-project ${{ env.FEATURE_FLAGS }} + + - if: ${{ !(contains(env.FEATURE_FLAGS, '--')) }} + name: Create the sample project with default options + run: node ./outfile.cjs sample-project --default + + - name: Move the sample project to the upper-level directory + run: mv sample-project ../sample-project + + - name: Install dependencies in the sample project + working-directory: ../sample-project + run: pnpm install + + - if: ${{ contains(matrix.flag-for-vitest, '--') }} + name: Run unit test script + run: pnpm test:unit + + - if: ${{ contains(matrix.flag-for-e2e, '--cypress') }} + name: Run Cypress with dev server + run: pnpm test:e2e:dev + + - name: Run build script + run: pnpm build + + - if: ${{ contains(matrix.flag-for-e2e, '--') }} + name: Run e2e test script + run: pnpm test:e2e From 4cb86a11bd3d77e9bab10546c5ab88b2f8f620ac Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:32:20 +0800 Subject: [PATCH 2/9] ci: pnpm should be installed before node for proper caching See https://github.com/actions/setup-node/issues/530#issuecomment-1169317505 --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddc14409..43098bfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,13 +16,13 @@ jobs: name: Build the package steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 7 - uses: actions/setup-node@v3 with: node-version: 18 cache: 'pnpm' - - uses: pnpm/action-setup@v2 - with: - version: 7 - run: pnpm install env: CYPRESS_INSTALL_BINARY: 0 @@ -60,13 +60,13 @@ jobs: FEATURE_FLAGS: ${{ matrix.flag-for-ts }} ${{ matrix.flag-for-jsx }} ${{ matrix.flag-for-router }} ${{ matrix.flag-for-pinia }} ${{ matrix.flag-for-vitest }} ${{ matrix.flag-for-e2e }} steps: - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 7 - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'pnpm' - - uses: pnpm/action-setup@v2 - with: - version: 7 - uses: actions/cache/restore@v3 id: cache-restore with: From 97314063a2b3b982cda72c3673f1780a177408e4 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:36:00 +0800 Subject: [PATCH 3/9] ci: GitHub actions matrix can't generate more than 256 jobs Let's comment out some and fix that later --- .github/workflows/ci.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43098bfd..e7e4738e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,8 @@ jobs: needs: build strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest] + # , macos-latest, windows-latest node-version: [18] flag-for-ts: ['--typescript', ''] flag-for-jsx: ['--jsx', ''] @@ -48,12 +49,12 @@ jobs: flag-for-pinia: ['--pinia', ''] flag-for-vitest: ['--vitest', ''] flag-for-e2e: ['--cypress', '--playwright', ''] - flag-for-linter-and-formatter: ['--eslint', '--eslint --prettier', ''] - include: - - node-version: 14 - os: ubuntu-latest - - node-version: 16 - os: ubuntu-latest + # flag-for-linter-and-formatter: ['--eslint', '--eslint --prettier', ''] + # include: + # - node-version: 14 + # os: ubuntu-latest + # - node-version: 16 + # os: ubuntu-latest runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.os == 'windows-latest' }} env: From bbadcf224e2942be63a2e7e49ae6a2f9c485215f Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:39:13 +0800 Subject: [PATCH 4/9] ci: add working-directory --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7e4738e..09f21818 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,15 +96,19 @@ jobs: - if: ${{ contains(matrix.flag-for-vitest, '--') }} name: Run unit test script + working-directory: ../sample-project run: pnpm test:unit - if: ${{ contains(matrix.flag-for-e2e, '--cypress') }} name: Run Cypress with dev server + working-directory: ../sample-project run: pnpm test:e2e:dev - name: Run build script + working-directory: ../sample-project run: pnpm build - if: ${{ contains(matrix.flag-for-e2e, '--') }} name: Run e2e test script + working-directory: ../sample-project run: pnpm test:e2e From 534036c38bc16fa7b1f728149f81ffc9183360bd Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:42:08 +0800 Subject: [PATCH 5/9] ci: fix playwright tests --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09f21818..a3df38f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,6 +108,11 @@ jobs: working-directory: ../sample-project run: pnpm build + - if: ${{ contains(matrix.flag-for-e2e, '--playwright') }} + name: Install Playwright dependencies + working-directory: ../sample-project + run: npx playwright install + - if: ${{ contains(matrix.flag-for-e2e, '--') }} name: Run e2e test script working-directory: ../sample-project From 46257e5666177bb89953a37ea3022c8ab4e77ab2 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:49:19 +0800 Subject: [PATCH 6/9] ci: add comments on the limitation of github actions and our choices --- .github/workflows/ci.yml | 48 ++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3df38f1..8a80db3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,6 @@ jobs: strategy: matrix: os: [ubuntu-latest] - # , macos-latest, windows-latest node-version: [18] flag-for-ts: ['--typescript', ''] flag-for-jsx: ['--jsx', ''] @@ -49,12 +48,47 @@ jobs: flag-for-pinia: ['--pinia', ''] flag-for-vitest: ['--vitest', ''] flag-for-e2e: ['--cypress', '--playwright', ''] - # flag-for-linter-and-formatter: ['--eslint', '--eslint --prettier', ''] - # include: - # - node-version: 14 - # os: ubuntu-latest - # - node-version: 16 - # os: ubuntu-latest + + # Skip ESLint/Prettier tests as we've reached the limit of job numbers + # TODO: Find a way to test them without adding new jobs + + # Run a few tests on other systems and Node.js versions + include: + - node-version: 18 + os: windows-latest + flag-for-ts: '--typescript' + flag-for-jsx: '--jsx' + flag-for-router: '--router' + flag-for-pinia: '--pinia' + flag-for-vitest: '--vitest' + flag-for-e2e: '--cypress' + + - node-version: 18 + os: macos-latest + flag-for-ts: '--typescript' + flag-for-jsx: '--jsx' + flag-for-router: '--router' + flag-for-pinia: '--pinia' + flag-for-vitest: '--vitest' + flag-for-e2e: '--cypress' + + - node-version: 14 + os: ubuntu-latest + flag-for-ts: '--typescript' + flag-for-jsx: '--jsx' + flag-for-router: '--router' + flag-for-pinia: '--pinia' + flag-for-vitest: '--vitest' + flag-for-e2e: '--cypress' + + - node-version: 16 + os: ubuntu-latest + flag-for-ts: '--typescript' + flag-for-jsx: '--jsx' + flag-for-router: '--router' + flag-for-pinia: '--pinia' + flag-for-vitest: '--vitest' + flag-for-e2e: '--cypress' runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.os == 'windows-latest' }} env: From 13e6a35b51632f4a6dcebebfb74a4a9a6c039ccd Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:49:54 +0800 Subject: [PATCH 7/9] ci: need to install playwright dependencies --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a80db3a..e562283d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,7 +145,7 @@ jobs: - if: ${{ contains(matrix.flag-for-e2e, '--playwright') }} name: Install Playwright dependencies working-directory: ../sample-project - run: npx playwright install + run: npx playwright install --with-deps - if: ${{ contains(matrix.flag-for-e2e, '--') }} name: Run e2e test script From d2b3151a32c0ce4ce1d5010ea72a68df8e8f0de2 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 19:57:42 +0800 Subject: [PATCH 8/9] ci: skip Cypress dev (it requires human interaction) --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e562283d..173b6459 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,11 +133,6 @@ jobs: working-directory: ../sample-project run: pnpm test:unit - - if: ${{ contains(matrix.flag-for-e2e, '--cypress') }} - name: Run Cypress with dev server - working-directory: ../sample-project - run: pnpm test:e2e:dev - - name: Run build script working-directory: ../sample-project run: pnpm build From 2ff90e46b154e780db6065b952aeb20d7ee12531 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 24 Feb 2023 20:10:15 +0800 Subject: [PATCH 9/9] chore: add comments about Cypress/Playwright test time [skip ci] --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 173b6459..60777f91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,10 @@ jobs: flag-for-router: ['--router', ''] flag-for-pinia: ['--pinia', ''] flag-for-vitest: ['--vitest', ''] + + # It's quite costly to install Cypress & Playwright even with cache. + # Maybe we can split them into another job so that all the projects + # can share the same binary installation. flag-for-e2e: ['--cypress', '--playwright', ''] # Skip ESLint/Prettier tests as we've reached the limit of job numbers