From 56595c32cb2ea1f981901bdd6c9bb6c1aa664afa Mon Sep 17 00:00:00 2001 From: Aria Date: Sat, 4 Feb 2023 20:23:26 +0100 Subject: [PATCH] Simplify workflows (#394 * Break the CI steps into separate jobs so they run in parallel and are easier to distinguish * Cache yarn more aggressively * Re-use actions in different jobs --- .github/actions/yarn-nm-install/action.yml | 54 ++++++++++ .github/workflows/ci.yml | 119 +++++++++++++++++++++ .github/workflows/compatibility-tests.yml | 52 --------- .github/workflows/main.yml | 82 -------------- .github/workflows/publish-prerelease.yml | 18 +--- 5 files changed, 177 insertions(+), 148 deletions(-) create mode 100644 .github/actions/yarn-nm-install/action.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/compatibility-tests.yml delete mode 100644 .github/workflows/main.yml diff --git a/.github/actions/yarn-nm-install/action.yml b/.github/actions/yarn-nm-install/action.yml new file mode 100644 index 0000000..419760c --- /dev/null +++ b/.github/actions/yarn-nm-install/action.yml @@ -0,0 +1,54 @@ +name: yarn-nm-install +description: Installs deps via yarn and re-uses the cache +runs: + using: composite + steps: + # A shared action to install dependencies via yarn and re-use the cache. + # This will skip the install step if the cache is hit. + - name: Restore node_modules + id: yarn-node-modules-cache + uses: actions/cache@v3 + with: + path: | + **/node_modules + .yarn/cache + key: + # Ideally we'd only have to list the lockfile, and `yarn install` + # would take care of the rest. But that's not the case, because + # `yarn install` would still build packages, even if they'd already + # been built before. Yarn's message is: + # `YN0007: │ esbuild@npm:0.16.7 must be built because it never has been before or the last one failed` + # I couldn't figure out how to make it not build packages, so I + # added the `package.json` files to the cache key (so in a later step, we can entirely skip the install step). + # + # However, this means that if we add a new workspace under any of the + # existing workspaces, run this action, and then change the package.json + # of that new workspace, then the cache will be hit, and the new package.json + # will be ignored. + ${{ runner.os }}-yarn-mono-nm-node-modules-${{ hashFiles('yarn.lock', + '.yarnrc.yml', 'package.json', '*/package.json', '*/*/package.json') + }} + + # Thanks to https://github.com/rafaelbiten for this step https://github.com/microsoft/playwright/issues/7249#issuecomment-1385567519 + - name: Cache Playwright Browsers for Playwright's Version + id: cache-playwright-browsers + uses: actions/cache@v3 + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('yarn.lock') }} + + # This step is only needed if the cache was not hit. + - run: yarn install --immutable --inline-builds + if: steps.yarn-node-modules-cache.outputs.cache-hit != 'true' + shell: bash + env: + YARN_NM_MODE: 'hardlinks-local' + + # This step is only needed if the job runs playwright tests. But we have + # to include it in all jobs. The reason is, both `yarn install` and `yarn run playwright install` + # modify the `~/.cache/ms-playwright` folder. If we don't include this step in all jobs, + # then the cache will change in some jobs and not in others, which would make the cache useless. + - name: Download playwright + if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' + shell: bash + run: yarn workspace playground run playwright install --with-deps diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2871c79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,119 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + Build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + + - run: yarn build + Lint: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + + - run: yarn lint:all --max-warnings 0 + + Test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + + - run: yarn test + Typecheck: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + + - run: yarn typecheck + VisualRegression: + name: Visual regression tests + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + + - name: Run e2e tests with percy + uses: percy/exec-action@v0.3.1 + with: + custom-command: 'yarn test:e2e:ci' + env: + PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} + + Compatibility-Tests: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install + # re-enable the following line if we start to get EINTEGRITY errors again + # - run: npm cache clean || npm cache verify + # This will test whether `npm install`/`yarn install` can actually run on each compatibility test fixture. See `compatibility-tests/README.md` for more info. + - run: + yarn workspace @theatre/compatibility-tests run install-fixtures + --verbose + # after that, we run the jest tests for each fixture + - run: yarn test:compat diff --git a/.github/workflows/compatibility-tests.yml b/.github/workflows/compatibility-tests.yml deleted file mode 100644 index 6bbcaf8..0000000 --- a/.github/workflows/compatibility-tests.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Compatibility tests - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - Compatibility-Tests: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - # Note that we assume the following things about the compatibility tests here: - # 1. Every directory in `build_test` is a project managed with yarn - # 2. All these projects store their cache in `/.yarn/cache` - # It's not that robust, but should be sufficient for us for now. - path: | - ${{ steps.yarn-cache-dir-path.outputs.dir }} - ${{ github.workspace }}/compatibility-tests/*/.yarn/cache - key: - ${{ runner.os }}-${{ matrix.node-version }}-yarn-${{ - hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.node-version }}-yarn- - - - run: yarn install - # re-enable the following line if we start to get EINTEGRITY errors again - # - run: npm cache clean || npm cache verify - # This will test whether `npm install`/`yarn install` can actually run on each compatibility test fixture. See `compatibility-tests/README.md` for more info. - - run: - yarn workspace @theatre/compatibility-tests run install-fixtures - --verbose - # after that, we run the jest tests for each fixture - - run: yarn test:compat diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 689c3a4..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - Test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - # cache: 'yarn' - - # - name: Get yarn cache directory path - # id: yarn-cache-dir-path - # run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - # - uses: actions/cache@v2 - # id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - # with: - # # Note that we assume the following things about the compatibility tests here: - # # 1. Every directory in `build_test` is a project managed with yarn - # # 2. All these projects store their cache in `/.yarn/cache` - # # It's not that robust, but should be sufficient for us for now. - # path: | - # ${{ steps.yarn-cache-dir-path.outputs.dir }} - # ${{ github.workspace }}/compatibility-tests/*/.yarn/cache - # key: - # ${{ runner.os }}-${{ matrix.node-version }}-yarn-${{ - # hashFiles('**/yarn.lock') }} - # restore-keys: | - # ${{ runner.os }}-${{ matrix.node-version }}-yarn- - - - name: Restore node_modules - id: yarn-node-modules-cache - uses: actions/cache@v3 - with: - path: | - **/node_modules - .yarn/cache - key: - ${{ runner.os }}-yarn-mono-nm-node-modules-${{ - hashFiles('yarn.lock', '.yarnrc.yml') }} - - # Thanks to https://github.com/rafaelbiten for this step https://github.com/microsoft/playwright/issues/7249#issuecomment-1385567519 - - name: Cache Playwright Browsers for Playwright's Version - id: cache-playwright-browsers - uses: actions/cache@v3 - with: - path: ~/.cache/ms-playwright - key: ${{ runner.os }}-playwright-${{ hashFiles('yarn.lock') }} - - - run: yarn install --immutable --inline-builds - env: - YARN_NM_MODE: 'hardlinks-local' - - - run: yarn lint:all --max-warnings 0 - - run: yarn test - - run: yarn typecheck - - run: yarn build - - - name: Download playwright - if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' - run: yarn workspace playground run playwright install --with-deps - - - name: Run e2e tests with percy - uses: percy/exec-action@v0.3.1 - with: - custom-command: 'yarn test:e2e:ci' - env: - PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} diff --git a/.github/workflows/publish-prerelease.yml b/.github/workflows/publish-prerelease.yml index 4349754..2635865 100644 --- a/.github/workflows/publish-prerelease.yml +++ b/.github/workflows/publish-prerelease.yml @@ -7,22 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: - node-version: '16.x' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - run: yarn install + node-version: ${{ matrix.node-version }} + - uses: ./.github/actions/yarn-nm-install - name: Build the Theatre.js packages run: yarn build - name: Update .yarnrc.yml with the auth config for the npmPublishRegistry