From 7f7b4cb885c9c1abd2ffd6b7ad4053535c697f22 Mon Sep 17 00:00:00 2001 From: Tom Milewski Date: Fri, 3 Nov 2023 13:38:44 -0700 Subject: [PATCH] fix(repo): GHA optimizations (#2037) * fix(repo): GHA optimizations * fix(repo): GHA attempt 4vCPU intial step * fix(repo): Remove GITHUB_ACCESS_TOKEN for better Turbo caching * fix(repo): Enable Turbo summarize * chore(repo): Remove unneeded Turbo globalDeps * chore(repo): Re-introduce follow-on jobs to CI workflow * chore(repo): Turbo summarize unit tests * chore(repo): Test reducing CI integration boxes as Playwright isn't using all vCPUs * chore(repo): Disable remix integration test until ready --- .github/actions/init/action.yml | 12 ++++++--- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++--- .github/workflows/labeler.yml | 2 +- integration/playwright.config.ts | 7 +++++- package.json | 1 + turbo.json | 18 ++------------ 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/.github/actions/init/action.yml b/.github/actions/init/action.yml index 4bb0adf0d2..c4b5abcb21 100644 --- a/.github/actions/init/action.yml +++ b/.github/actions/init/action.yml @@ -10,6 +10,10 @@ inputs: description: 'Enable Playwright?' required: false default: 'false' + turbo-summarize: + description: 'The token to use for Turbo task summaries' + required: false + default: 'false' turbo-enabled: description: 'Enable Turbo?' required: false @@ -44,6 +48,7 @@ runs: CACHE_DIR: ${{ inputs.turbo-cache-dir }} REMOTE_ONLY: ${{ inputs.turbo-remote-only }} SIGNATURE: ${{ inputs.turbo-signature }} + SUMMARIZE: ${{ inputs.turbo-summarize }} TEAM: ${{ inputs.turbo-team }} TOKEN: ${{ inputs.turbo-token }} with: @@ -54,13 +59,14 @@ runs: ? os.availableParallelism() : os.cpus().length; - const { ENABLED, CACHE_DIR, SIGNATURE, REMOTE_ONLY, TEAM, TOKEN } = process.env + const { ENABLED, CACHE_DIR, SIGNATURE, REMOTE_ONLY, SUMMARIZE, TEAM, TOKEN } = process.env core.exportVariable('TURBO_ARGS', [ '--output-logs=new-only', `--cache-dir=${CACHE_DIR}`, - `--concurrency=${cpus}` + `--concurrency=${cpus}`, + `--summarize=${SUMMARIZE}`, ].join(' ') ) @@ -90,7 +96,7 @@ runs: id: npm-cache with: path: ./node_modules - key: ${{ runner.os }}-node-${{ inputs.node-version }}-node-modules-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-node-${{ inputs.node-version }}-node-modules-${{ hashFiles('package-lock.json') }} - name: Install NPM Dependencies if: steps.npm-cache.outputs.cache-hit != 'true' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20fd463121..1684c65177 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,12 @@ concurrency: jobs: formatting-linting: name: Formatting, linting & changeset checks - runs-on: ${{ vars.RUNNER_NORMAL }} + runs-on: ${{ vars.RUNNER_LARGE }} timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_NORMAL) }} + env: + TURBO_SUMMARIZE: true + steps: - name: Checkout Repo timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_SHORT) }} @@ -28,12 +31,13 @@ jobs: show-progress: false - name: Setup - timeout-minutes: ${{ vars.TIMEOUT_MINUTES_SHORT }} + timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_SHORT) }} id: config uses: ./.github/actions/init with: turbo-remote-only: false turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} + turbo-summarize: ${{ env.TURBO_SUMMARIZE }} turbo-team: ${{ vars.TURBO_TEAM }} turbo-token: ${{ secrets.TURBO_TOKEN }} @@ -67,12 +71,24 @@ jobs: timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_SHORT) }} run: npm run lint -- $TURBO_ARGS -- --quiet + - name: Upload Turbo Summary + uses: actions/upload-artifact@v3 + if: ${{ env.TURBO_SUMMARIZE == 'true' }} + continue-on-error: true + with: + name: turbo-summary-report-lint-${{ github.run_id }}-${{ github.run_attempt }} + path: .turbo/runs + retention-days: 5 + unit-tests: name: Unit Tests needs: formatting-linting runs-on: ${{ vars.RUNNER_LARGE }} timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_NORMAL) }} + env: + TURBO_SUMMARIZE: true + strategy: matrix: node-version: [ 18, 20 ] @@ -90,6 +106,7 @@ jobs: with: node-version: ${{ matrix.node-version }} turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} + turbo-summarize: ${{ env.TURBO_SUMMARIZE }} turbo-team: ${{ vars.TURBO_TEAM }} turbo-token: ${{ secrets.TURBO_TOKEN }} @@ -98,24 +115,36 @@ jobs: env: NODE_VERSION: ${{ matrix.node-version }} + - name: Upload Turbo Summary + uses: actions/upload-artifact@v3 + if: ${{ env.TURBO_SUMMARIZE == 'true' }} + continue-on-error: true + with: + name: turbo-summary-report-unit-${{ github.run_id }}-${{ github.run_attempt }}-node-${{ matrix.node-version }} + path: .turbo/runs + retention-days: 5 + integration-tests: name: Integration Tests needs: formatting-linting - runs-on: ${{ vars.RUNNER_LARGE }} + runs-on: ${{ vars.RUNNER_MEDIUM }} timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_NORMAL) }} strategy: matrix: + # TODO: Remove `matrix.test-name != 'remix'` when ready, or from matrix when required check is disabled test-name: [ 'generic', 'nextjs', 'remix' ] steps: - name: Checkout Repo + if: ${{ matrix.test-name != 'remix' }} uses: actions/checkout@v4 with: fetch-depth: 0 show-progress: false - name: Setup + if: ${{ matrix.test-name != 'remix' }} id: config uses: ./.github/actions/init with: @@ -125,20 +154,24 @@ jobs: playwright-enabled: true - name: Verdaccio + if: ${{ matrix.test-name != 'remix' }} uses: ./.github/actions/verdaccio with: publish-cmd: | if [ "$(npm config get registry)" = "https://registry.npmjs.org/" ]; then echo 'Error: Using default registry' && exit 1; else npx turbo build $TURBO_ARGS && npx changeset publish --no-git-tag; fi - name: Install @clerk/backend in /integration + if: ${{ matrix.test-name != 'remix' }} working-directory: ./integration run: npm init -y && npm install @clerk/backend - name: Install @clerk/clerk-js in os temp + if: ${{ matrix.test-name != 'remix' }} working-directory: ${{runner.temp}} run: mkdir clerk-js && cd clerk-js && npm init -y && npm install @clerk/clerk-js - name: Run Integration Tests + if: ${{ matrix.test-name != 'remix' }} run: npm run test:integration:${{ matrix.test-name }} env: E2E_APP_CLERK_JS_DIR: ${{runner.temp}} @@ -147,9 +180,10 @@ jobs: MAILSAC_API_KEY: ${{ secrets.MAILSAC_API_KEY }} # - name: Upload Integration Report for ${{ matrix.test-name }} + # if: ${{ matrix.test-name != 'remix' }} # uses: actions/upload-artifact@v3 # if: always() # with: - # name: integration-report-${{ github.ref }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.test-name }} + # name: integration-report-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.test-name }} # path: playwright-report/ # retention-days: 1 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 5c15aa76b2..e3a2542465 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -5,7 +5,7 @@ on: jobs: triage: - timeout-minutes: ${{ vars.TIMEOUT_MINUTES_SHORT }} + timeout-minutes: 3 permissions: contents: read pull-requests: write diff --git a/integration/playwright.config.ts b/integration/playwright.config.ts index 8c07d2f8da..2ff91c4ac6 100644 --- a/integration/playwright.config.ts +++ b/integration/playwright.config.ts @@ -1,4 +1,6 @@ /* eslint-disable turbo/no-undeclared-env-vars */ +import os from 'node:os'; + import type { PlaywrightTestConfig } from '@playwright/test'; import { defineConfig, devices } from '@playwright/test'; import { config } from 'dotenv'; @@ -6,6 +8,8 @@ import * as path from 'path'; config({ path: path.resolve(__dirname, '.env.local') }); +const numAvailableWorkers = os.cpus().length - 1; + export const common: PlaywrightTestConfig = { testDir: './tests', snapshotDir: './tests/snapshots', @@ -13,7 +17,8 @@ export const common: PlaywrightTestConfig = { forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, timeout: process.env.CI ? 90000 : 30000, - workers: process.env.CI ? '50%' : '70%', + maxFailures: process.env.CI ? 1 : undefined, + workers: process.env.CI ? numAvailableWorkers : '70%', reporter: [[process.env.CI ? 'html' : 'line', { open: 'never' }]] as any, use: { trace: 'on-first-retry', diff --git a/package.json b/package.json index 3ff7a63b1e..af64f3e426 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "release": "TURBO_FORCE=true FORCE_COLOR=1 npm run build -- --force && changeset publish && git push --follow-tags", "release:snapshot": "TURBO_FORCE=true FORCE_COLOR=1 npm run build && changeset publish --tag snapshot --no-git-tag", "release:staging": "TURBO_FORCE=true FORCE_COLOR=1 npm run build && changeset publish --tag staging --no-git-tag", + "release:verdaccio": "if [ \"$(npm config get registry)\" = \"https://registry.npmjs.org/\" ]; then echo 'Error: Using default registry' && exit 1; else TURBO_CONCURRENCY=1 npm run build && changeset publish --no-git-tag; fi", "test": "FORCE_COLOR=1 turbo test --concurrency=${TURBO_CONCURRENCY:-80%}", "test:cache:clear": "FORCE_COLOR=1 turbo test:cache:clear --continue --concurrency=${TURBO_CONCURRENCY:-80%}", "test:integration:base": "DEBUG=1 npx playwright test --config integration/playwright.config.ts", diff --git a/turbo.json b/turbo.json index 941dde6e66..468f92c395 100644 --- a/turbo.json +++ b/turbo.json @@ -3,20 +3,7 @@ "remoteCache": { "signature": true }, - "globalDependencies": [ - ".changeset/changelog.js", - ".changeset/config.json", - ".github/**", - ".jit", - ".nvmrc", - ".prettier*", - "jest.*.ts", - "package.json", - "package-lock.json", - "tsconfig.json", - "tsconfig.*.json", - "verdaccio.yaml" - ], + "globalDependencies": ["jest.*.ts", "package.json", "package-lock.json", "tsconfig.json", "tsconfig.*.json"], "globalEnv": [ "CLERK_*", "GATSBY_CLERK_*", @@ -26,8 +13,7 @@ "NODE_VERSION", "NPM_VERSION", "TZ", - "VERCEL", - "GITHUB_ACCESS_TOKEN" + "VERCEL" ], "pipeline": { "build": {