From dd0514bd2cd312dbbc01ec8f018ff575bb93182f Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Fri, 15 Sep 2023 16:17:41 -0400 Subject: [PATCH] ci: multiple jobs (#3337) * ci: move playwright install to test:e2e script * test: adjust test db names to avoid conflicts * ci: clean up core job * ci: add db-mongodb build job * chore: add jest setup db adapter logging * chore: install on mongodb job * chore: adjust root deps * chore: use turbo for db-mongodb to ensure build order * chore: use turbo from .bin * chore: add build script for db-postgres * ci: add db-postgres build job * chore: upgrade actions/checkout and actions/setup-node * chore: rename github workflow file to main --- .github/workflows/main.yml | 155 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 74 --------------- package.json | 7 +- pnpm-lock.yaml | 24 ++--- test/buildConfigWithDefaults.ts | 14 +-- test/jest.setup.ts | 9 ++ 6 files changed, 187 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..e5cd207f19 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,155 @@ +name: build + +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: ['master', '2.0'] + +jobs: + core: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: https://registry.npmjs.org + scope: '@payloadcms' + always-auth: true + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Debug print versions + run: | + node -v + pnpm -v + + - name: Install dependencies + run: pnpm install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Build + run: pnpm build + + - name: Component Tests + run: pnpm test:components + + - name: E2E Tests + run: pnpm test:e2e --bail + + - name: Integration Tests + run: pnpm test:int + + - name: Generate Payload Types + run: pnpm dev:generate-types fields + + - name: Generate GraphQL schema file + run: pnpm dev:generate-graphql-schema graphql-schema-gen + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: test-results + path: test-results/ + retention-days: 30 + + db_mongodb: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: https://registry.npmjs.org + scope: '@payloadcms' + always-auth: true + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Build db-mongodb + run: ./node_modules/.bin/turbo run build --filter=db-mongodb + + db_postgres: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: https://registry.npmjs.org + scope: '@payloadcms' + always-auth: true + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Build db-postgres + run: ./node_modules/.bin/turbo run build --filter=db-postgres diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 8dee497e18..0000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: build - -on: - pull_request: - types: [opened, reopened, synchronize] - push: - branches: ['master', '2.0'] - -jobs: - install_and_build_pnpm: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16.x, 18.x, 20.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - registry-url: https://registry.npmjs.org - scope: '@payloadcms' - always-auth: true - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Debug print versions - run: | - node -v - pnpm -v - - name: Install dependencies - run: pnpm install - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: pnpm build - - - name: Component Tests - run: pnpm test:components - - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: E2E Tests - run: pnpm test:e2e --bail - - - name: Integration Tests - run: pnpm test:int - - - name: Generate Payload Types - run: pnpm dev:generate-types fields - - - name: Generate GraphQL schema file - run: pnpm dev:generate-graphql-schema graphql-schema-gen - - - uses: actions/upload-artifact@v3 - if: always() - with: - name: test-results - path: test-results/ - retention-days: 30 diff --git a/package.json b/package.json index 8c0ffb05b1..218300e488 100644 --- a/package.json +++ b/package.json @@ -26,15 +26,12 @@ "pretest": "pnpm build", "test": "pnpm test:int && pnpm test:components && pnpm test:e2e", "test:components": "cross-env jest --config=jest.components.config.js", - "test:e2e": "ts-node -T ./test/runE2E.ts", + "test:e2e": "npx playwright install --with-deps && ts-node -T ./test/runE2E.ts", "test:e2e:debug": "cross-env PWDEBUG=1 DISABLE_LOGGING=true playwright test", "test:e2e:headed": "cross-env DISABLE_LOGGING=true playwright test --headed", "test:int": "cross-env DISABLE_LOGGING=true jest --forceExit --detectOpenHandles", "translateNewKeys": "pnpm --filter payload run translateNewKeys" }, - "dependencies": { - "turbo": "^1.10.13" - }, "devDependencies": { "@payloadcms/eslint-config": "workspace:*", "@playwright/test": "1.37.1", @@ -53,8 +50,10 @@ "jest": "29.6.4", "jest-environment-jsdom": "29.6.4", "prettier": "^3.0.3", + "rimraf": "3.0.2", "shelljs": "0.8.5", "ts-node": "10.9.1", + "turbo": "^1.10.13", "typescript": "5.2.2", "uuid": "^9.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f51e2a2c38..387185fe3c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,10 +7,6 @@ settings: importers: .: - dependencies: - turbo: - specifier: ^1.10.13 - version: 1.10.13 devDependencies: '@payloadcms/eslint-config': specifier: workspace:* @@ -63,12 +59,18 @@ importers: prettier: specifier: ^3.0.3 version: 3.0.3 + rimraf: + specifier: 3.0.2 + version: 3.0.2 shelljs: specifier: 0.8.5 version: 0.8.5 ts-node: specifier: 10.9.1 version: 10.9.1(@swc/core@1.3.76)(@types/node@20.5.7)(typescript@5.2.2) + turbo: + specifier: ^1.10.13 + version: 1.10.13 typescript: specifier: 5.2.2 version: 5.2.2 @@ -13994,7 +13996,7 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true - dev: false + dev: true optional: true /turbo-darwin-arm64@1.10.13: @@ -14002,7 +14004,7 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true - dev: false + dev: true optional: true /turbo-linux-64@1.10.13: @@ -14010,7 +14012,7 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /turbo-linux-arm64@1.10.13: @@ -14018,7 +14020,7 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /turbo-windows-64@1.10.13: @@ -14026,7 +14028,7 @@ packages: cpu: [x64] os: [win32] requiresBuild: true - dev: false + dev: true optional: true /turbo-windows-arm64@1.10.13: @@ -14034,7 +14036,7 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true - dev: false + dev: true optional: true /turbo@1.10.13: @@ -14047,7 +14049,7 @@ packages: turbo-linux-arm64: 1.10.13 turbo-windows-64: 1.10.13 turbo-windows-arm64: 1.10.13 - dev: false + dev: true /type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} diff --git a/test/buildConfigWithDefaults.ts b/test/buildConfigWithDefaults.ts index 014e1b2f6b..c18df1fe4a 100644 --- a/test/buildConfigWithDefaults.ts +++ b/test/buildConfigWithDefaults.ts @@ -1,18 +1,18 @@ -import path from 'path'; +import path from 'path' -import type { Config, SanitizedConfig } from '../packages/payload/src/config/types'; +import type { Config, SanitizedConfig } from '../packages/payload/src/config/types' -import { mongooseAdapter } from '../packages/db-mongodb/src/index'; -import { postgresAdapter } from '../packages/db-postgres/src/index'; -import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build'; +import { mongooseAdapter } from '../packages/db-mongodb/src/index' +import { postgresAdapter } from '../packages/db-postgres/src/index' +import { buildConfig as buildPayloadConfig } from '../packages/payload/src/config/build' const databaseAdapters = { mongoose: mongooseAdapter({ - url: process.env.MONGO_URL || 'mongodb://127.0.0.1/payload', + url: 'mongodb://127.0.0.1/payloadtests', }), postgres: postgresAdapter({ client: { - connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payload', + connectionString: process.env.POSTGRES_URL || 'postgres://127.0.0.1:5432/payloadtests', }, }), } diff --git a/test/jest.setup.ts b/test/jest.setup.ts index aadc6b0d8d..be4326f2e4 100644 --- a/test/jest.setup.ts +++ b/test/jest.setup.ts @@ -1,3 +1,12 @@ module.exports = () => { process.env.PAYLOAD_DISABLE_ADMIN = 'true' + + if (process.env.PAYLOAD_DATABASE) { + console.log('\n\nUsing database:', process.env.PAYLOAD_DATABASE) + if (process.env.PAYLOAD_DATABASE === 'postgres') { + process.env.PAYLOAD_DROP_DATABASE = 'true' + } + } else { + console.log('\n\nNo database specified, using default') + } }