diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dac657cd..60777f91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,38 +11,142 @@ on: branches: - '**' jobs: + build: + runs-on: ubuntu-latest + 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' + - 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] + node-version: [18] + flag-for-ts: ['--typescript', ''] + flag-for-jsx: ['--jsx', ''] + 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 + # 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 - - 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' + + - node-version: 16 os: ubuntu-latest - name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + 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: + 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: - submodules: 'recursive' - - uses: pnpm/action-setup@v2.2.4 - with: - version: 6 + version: 7 - 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: 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 + working-directory: ../sample-project + run: pnpm test:unit + + - name: Run build script + 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 --with-deps + + - if: ${{ contains(matrix.flag-for-e2e, '--') }} + name: Run e2e test script + working-directory: ../sample-project + run: pnpm test:e2e