From d26732c9dc9b7641e01c8633f77b392c6ac3a044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 21 Feb 2023 17:10:39 -0700 Subject: [PATCH] Refactors Github Workflows (#7267) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Testing * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update production-build.yml * Tests * Update production-build.yml * Update pr.yml * Update pr.yml * Update nextjs-bundle-analysis.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update production-build.yml * Update pr.yml * Update pr.yml * Update pr.yml * Update pr.yml * test * Test * Revert * TEST * Update production-build.yml * Update production-build.yml * DRY * Fixes * Update action.yml * Update action.yml * Fixes * WIP * Update action.yml * Update action.yml * Abstract playwright cache * Update yarn-e2e.yml * Adds type check * Update pr.yml * Tests * Anotha one * Update action.yml * Update pr.yml * Update action.yml * Cleanup * Update package.json * Update yarn-e2e.yml * Test * Cleanup * Update check-types.yml * Update yarn-install.yml * Update yarn-install.yml * Update yarn-install.yml * Fixes * Fixes * Update pr.yml * Fixes * Removed required checks * WIP * Adjustments * Update action.yml * Update pr.yml * Comments out buildjet * Caches DB * Update lint.yml * Update action.yml * Update action.yml * Update action.yml * Upgrades actions/checkout@v3 * Build fixes * Update nextjs-bundle-analysis.yml * Update nextjs-bundle-analysis.yml * Update nextjs-bundle-analysis.yml * Fixes? * Inherit secrets * Re-enables buildjet * Adds missing build cache to e2e * Revert "Re-enables buildjet" This reverts commit badd655e1edf8c2942582439f9fd48c00f892c38. * Fixes build env * Revert "Revert "Re-enables buildjet"" This reverts commit a1d78e7c12618d14b23bd50540ee005c6a550e7b. * Update .github/actions/cache-db/action.yml * Define CODEOWNERS file (#7245) * Start defining CODEOWNERS file * Update CODEOWNERS --------- Co-authored-by: Omar López * improved brand colors on booking page (#7269) --------- Co-authored-by: Alex van Andel Co-authored-by: Peer Richelsen --- .github/actions/cache-build/action.yml | 23 ++++ .github/actions/cache-db/action.yml | 34 ++++++ .../actions/dangerous-git-checkout/action.yml | 10 ++ .github/actions/yarn-build/action.yml | 104 ++++++++++++++++++ .github/actions/yarn-install/action.yml | 30 +++++ .../yarn-playwright-install/action.yml | 19 ++++ .github/workflows/check-if-ui-has-changed.yml | 2 +- .github/workflows/check-types.yml | 27 +---- .github/workflows/crowdin.yml | 4 +- .github/workflows/db-staging-snapshot.yml | 2 +- .github/workflows/e2e-app-store.yml | 56 ++-------- .github/workflows/e2e-embed.yml | 44 ++------ .github/workflows/e2e.yml | 42 ++----- .github/workflows/lint.yml | 32 +----- .github/workflows/nextjs-bundle-analysis.yml | 91 ++------------- .github/workflows/pr.yml | 88 +++++++++++++++ .github/workflows/production-build.yml | 85 ++++++++++++++ .github/workflows/required-checks.yml | 44 -------- .github/workflows/submodule-sync.yml | 2 +- .github/workflows/test.yml | 26 +---- .github/workflows/yarn-install.yml | 14 +++ package.json | 4 +- 22 files changed, 465 insertions(+), 318 deletions(-) create mode 100644 .github/actions/cache-build/action.yml create mode 100644 .github/actions/cache-db/action.yml create mode 100644 .github/actions/dangerous-git-checkout/action.yml create mode 100644 .github/actions/yarn-build/action.yml create mode 100644 .github/actions/yarn-install/action.yml create mode 100644 .github/actions/yarn-playwright-install/action.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/production-build.yml delete mode 100644 .github/workflows/required-checks.yml create mode 100644 .github/workflows/yarn-install.yml diff --git a/.github/actions/cache-build/action.yml b/.github/actions/cache-build/action.yml new file mode 100644 index 0000000000..a57da06a7a --- /dev/null +++ b/.github/actions/cache-build/action.yml @@ -0,0 +1,23 @@ +name: Cache production build binaries +description: "Cache or restore if necessary" +env: + node_version: v16.x +runs: + using: "composite" + steps: + - name: Cache production build + uses: actions/cache@v3 + env: + cache-name: prod-build + key-1: ${{ env.node_version }}-${{ hashFiles('yarn.lock') }} + key-2: ${{ hashFiles('apps/web/next.config.js') }} + with: + path: | + apps/web/.next + node_modules/.cache/turbo + **/.turbo/** + **/dist/** + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}- + ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}- diff --git a/.github/actions/cache-db/action.yml b/.github/actions/cache-db/action.yml new file mode 100644 index 0000000000..54d1e45ff6 --- /dev/null +++ b/.github/actions/cache-db/action.yml @@ -0,0 +1,34 @@ +name: Cache database between jobs +description: "Cache or restore if necessary" +inputs: + DATABASE_URL: + required: true + path: + required: false + default: "backups/backup.sql" +runs: + using: "composite" + steps: + - name: Cache database + id: cache-db + uses: actions/cache@v3 + env: + cache-name: cache-db + with: + path: ${{ inputs.path }} + key: ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.path }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.path }}- + - name: Postgres Dump Backup + if: steps.cache-db.outputs.cache-hit != 'true' + uses: tj-actions/pg-dump@v2.3 + with: + database_url: ${{ inputs.DATABASE_URL }} + path: ${{ inputs.path }} + options: "-O" + - name: Postgres Backup Restore + if: steps.cache-db.outputs.cache-hit == 'true' + uses: tj-actions/pg-restore@v4.5 + with: + database_url: ${{ inputs.DATABASE_URL }} + backup_file: ${{ inputs.path }} diff --git a/.github/actions/dangerous-git-checkout/action.yml b/.github/actions/dangerous-git-checkout/action.yml new file mode 100644 index 0000000000..48dca84cbe --- /dev/null +++ b/.github/actions/dangerous-git-checkout/action.yml @@ -0,0 +1,10 @@ +name: Dangerous git Checkout +description: "Git Checkout from PR code so we can run checks from forks" +runs: + using: "composite" + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 2 diff --git a/.github/actions/yarn-build/action.yml b/.github/actions/yarn-build/action.yml new file mode 100644 index 0000000000..89e55cb2d4 --- /dev/null +++ b/.github/actions/yarn-build/action.yml @@ -0,0 +1,104 @@ +name: Production Build +description: "Creates a production build, caches it and restores if necessary" +inputs: + DATABASE_URL: + required: true + NEXT_PUBLIC_WEBAPP_URL: + required: true + NEXT_PUBLIC_WEBSITE_URL: + required: true + NEXTAUTH_SECRET: + required: true + GOOGLE_API_CREDENTIALS: + required: true + GOOGLE_LOGIN_ENABLED: + required: true + CRON_API_KEY: + required: false + CALENDSO_ENCRYPTION_KEY: + required: true + DAILY_API_KEY: + required: true + NEXT_PUBLIC_STRIPE_PUBLIC_KEY: + required: true + NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE: + required: true + NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE: + required: true + NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE: + required: true + NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE: + required: true + NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN: + required: true + STRIPE_PRIVATE_KEY: + required: true + STRIPE_CLIENT_ID: + required: true + STRIPE_WEBHOOK_SECRET: + required: true + STRIPE_PRO_PLAN_PRODUCT_ID: + required: true + STRIPE_PREMIUM_PLAN_PRODUCT_ID: + required: true + STRIPE_FREE_PLAN_PRODUCT_ID: + required: true + PAYMENT_FEE_PERCENTAGE: + required: true + PAYMENT_FEE_FIXED: + required: true + SAML_DATABASE_URL: + required: true + SAML_ADMINS: + required: true + NEXTAUTH_URL: + required: true + NEXT_PUBLIC_IS_E2E: + required: true + TURBO_TOKEN: + required: true + TURBO_TEAM: + required: true + +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/cache-build + id: prod-build-cache + - name: Next.js production build + if: steps.prod-build-cache.outputs.cache-hit != 'true' + shell: bash + env: + DATABASE_URL: ${{ inputs.DATABASE_URL }} + NEXT_PUBLIC_WEBAPP_URL: ${{ inputs.NEXT_PUBLIC_WEBAPP_URL }} + NEXT_PUBLIC_WEBSITE_URL: ${{ inputs.NEXT_PUBLIC_WEBSITE_URL }} + NEXTAUTH_SECRET: ${{ inputs.NEXTAUTH_SECRET }} + GOOGLE_API_CREDENTIALS: ${{ inputs.GOOGLE_API_CREDENTIALS }} + GOOGLE_LOGIN_ENABLED: ${{ inputs.GOOGLE_LOGIN_ENABLED }} + CALENDSO_ENCRYPTION_KEY: ${{ inputs.CALENDSO_ENCRYPTION_KEY }} + DAILY_API_KEY: ${{ inputs.DAILY_API_KEY }} + NEXT_PUBLIC_STRIPE_PUBLIC_KEY: ${{ inputs.NEXT_PUBLIC_STRIPE_PUBLIC_KEY }} + NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE: ${{ inputs.NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE: ${{ inputs.NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE: ${{ inputs.NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE: ${{ inputs.NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE }} + NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN: ${{ inputs.NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN }} + STRIPE_PRIVATE_KEY: ${{ inputs.STRIPE_PRIVATE_KEY }} + STRIPE_CLIENT_ID: ${{ inputs.STRIPE_CLIENT_ID }} + STRIPE_WEBHOOK_SECRET: ${{ inputs.STRIPE_WEBHOOK_SECRET }} + STRIPE_PRO_PLAN_PRODUCT_ID: ${{ inputs.STRIPE_PRO_PLAN_PRODUCT_ID }} + STRIPE_PREMIUM_PLAN_PRODUCT_ID: ${{ inputs.STRIPE_PREMIUM_PLAN_PRODUCT_ID }} + STRIPE_FREE_PLAN_PRODUCT_ID: ${{ inputs.STRIPE_FREE_PLAN_PRODUCT_ID }} + PAYMENT_FEE_PERCENTAGE: ${{ inputs.PAYMENT_FEE_PERCENTAGE }} + PAYMENT_FEE_FIXED: ${{ inputs.PAYMENT_FEE_FIXED }} + SAML_DATABASE_URL: ${{ inputs.SAML_DATABASE_URL }} + SAML_ADMINS: ${{ inputs.SAML_ADMINS }} + NEXTAUTH_URL: ${{ inputs.NEXTAUTH_URL }} + NEXT_PUBLIC_IS_E2E: ${{ inputs.NEXT_PUBLIC_IS_E2E }} + TURBO_TOKEN: ${{ inputs.TURBO_TOKEN }} + TURBO_TEAM: ${{ inputs.TURBO_TEAM }} + run: | + yarn db-seed + yarn build diff --git a/.github/actions/yarn-install/action.yml b/.github/actions/yarn-install/action.yml new file mode 100644 index 0000000000..0d04c529f0 --- /dev/null +++ b/.github/actions/yarn-install/action.yml @@ -0,0 +1,30 @@ +name: Yarn install +description: "Install all NPM dependencies, caches them and restores if necessary" +env: + node_version: v16.x +runs: + using: "composite" + steps: + - name: Use Node ${{ env.node_version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.node_version }} + cache: "yarn" + - name: node_modules cache + id: node-modules-cache + uses: actions/cache@v3 + env: + cache-name: node-modules-yarn + cache-key: ${{ env.node_version }}-${{ hashFiles('yarn.lock', 'packages/prisma/schema.prisma') }} + with: + path: | + **/node_modules/** + packages/prisma/zod + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.cache-key }} + restore-keys: ${{ runner.os }}-${{ env.cache-name }}- + - name: Yarn install + shell: bash + if: steps.node-modules-cache.outputs.cache-hit != 'true' + run: | + yarn install --prefer-offline --frozen-lockfile + yarn prisma generate diff --git a/.github/actions/yarn-playwright-install/action.yml b/.github/actions/yarn-playwright-install/action.yml new file mode 100644 index 0000000000..65a093bfe2 --- /dev/null +++ b/.github/actions/yarn-playwright-install/action.yml @@ -0,0 +1,19 @@ +name: Install playwright binaries +description: "Install playwright, cache and restore if necessary" +runs: + using: "composite" + steps: + - name: Cache playwright binaries + id: playwright-cache + uses: actions/cache@v2 + with: + path: | + ~/Library/Caches/ms-playwright + ~/.cache/ms-playwright + ${{ github.workspace }}/node_modules/playwright + key: cache-playwright-${{ hashFiles('**/yarn.lock') }} + restore-keys: cache-playwright- + - name: Yarn playwright install + shell: bash + if: steps.playwright-cache.outputs.cache-hit != 'true' + run: yarn playwright install diff --git a/.github/workflows/check-if-ui-has-changed.yml b/.github/workflows/check-if-ui-has-changed.yml index 9e702440e8..d86ee998cd 100644 --- a/.github/workflows/check-if-ui-has-changed.yml +++ b/.github/workflows/check-if-ui-has-changed.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks fetch-depth: 0 diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index bb7a348182..ec165d261b 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -1,34 +1,17 @@ name: Check types on: - pull_request_target: - branches: - - main - paths: - - "**.tsx?" -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + workflow_call: env: NODE_OPTIONS: "--max-old-space-size=8192" jobs: check-types: runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 2 + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout + - uses: ./.github/actions/yarn-install - - name: Use Node 16.x - uses: actions/setup-node@v3 - - with: - node-version: 16.x - cache: "yarn" - - name: Show info run: node -e "console.log(require('v8').getHeapStatistics())" - - - run: yarn --frozen-lockfile + - run: yarn type-check diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.yml index 464e82e7c7..5ccfd25f05 100644 --- a/.github/workflows/crowdin.yml +++ b/.github/workflows/crowdin.yml @@ -9,14 +9,12 @@ concurrency: cancel-in-progress: true jobs: - required-checks: - uses: calcom/cal.com/.github/workflows/required-checks.yml@main synchronize-with-crowdin: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: crowdin action uses: crowdin/github-action@1.4.9 diff --git a/.github/workflows/db-staging-snapshot.yml b/.github/workflows/db-staging-snapshot.yml index 4fa1ae35f9..c31beb1693 100644 --- a/.github/workflows/db-staging-snapshot.yml +++ b/.github/workflows/db-staging-snapshot.yml @@ -7,7 +7,7 @@ jobs: db-staging-snapshot: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install Snaplet CLI run: curl -sL https://app.snaplet.dev/get-cli/ | bash - name: Restore Snapshot diff --git a/.github/workflows/e2e-app-store.yml b/.github/workflows/e2e-app-store.yml index ebb0edf01f..71c3585862 100644 --- a/.github/workflows/e2e-app-store.yml +++ b/.github/workflows/e2e-app-store.yml @@ -1,29 +1,12 @@ name: E2E App-Store Apps on: - push: - branches: [fixes/e2e-consolidation] # TODO: Remove this after merged in main - pull_request_target: # So we can test on forks - branches: - - main - paths-ignore: - - apps/api/** - - apps/console/** - - apps/docs/** - - apps/swagger/** - - apps/website/** - - apps/web/public/** -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + workflow_call: + jobs: - test: + e2e-app-store: timeout-minutes: 20 name: E2E App-Store Apps - strategy: - matrix: - node: ["16.x"] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest env: DATABASE_URL: postgresql://postgres:@localhost:5432/calendso @@ -65,32 +48,15 @@ jobs: - 5432:5432 steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks - fetch-depth: 2 + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - - name: Use Node ${{ matrix.node }} - uses: actions/setup-node@v3 + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db with: - node-version: ${{ matrix.node }} - cache: "yarn" - - - name: Cache playwright binaries - uses: actions/cache@v2 - id: playwright-cache - with: - path: | - ~/Library/Caches/ms-playwright - ~/.cache/ms-playwright - ${{ github.workspace }}/node_modules/playwright - key: cache-playwright-${{ hashFiles('**/yarn.lock') }} - restore-keys: cache-playwright- - - run: yarn --frozen-lockfile - - name: Install playwright deps - if: steps.playwright-cache.outputs.cache-hit != 'true' - run: yarn playwright install --with-deps + DATABASE_URL: ${{ env.DATABASE_URL }} + - uses: ./.github/actions/cache-build - name: Run Tests run: yarn test-e2e:app-store diff --git a/.github/workflows/e2e-embed.yml b/.github/workflows/e2e-embed.yml index 9312999331..9fa784441d 100644 --- a/.github/workflows/e2e-embed.yml +++ b/.github/workflows/e2e-embed.yml @@ -1,21 +1,11 @@ name: E2E Embed tests and booking flow(for non-embed as well) on: - pull_request_target: # So we can test on forks - branches: - - main - # Embed e2e - tests verify booking flow which is applicable to non-embed case also. So, don't ignore apps/web changes. - paths: - - apps/web/** - - packages/embeds/** workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + jobs: e2e-embed: timeout-minutes: 20 runs-on: ubuntu-latest - env: DATABASE_URL: postgresql://postgres:@localhost:5432/calendso NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000 @@ -61,35 +51,17 @@ jobs: - 5432:5432 steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks - fetch-depth: 2 + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - - name: Use Node 16.x - uses: actions/setup-node@v3 + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db with: - node-version: 16.x - cache: "yarn" - - - name: Cache playwright binaries - uses: actions/cache@v2 - id: playwright-cache - with: - path: | - ~/Library/Caches/ms-playwright - ~/.cache/ms-playwright - ${{ github.workspace }}/node_modules/playwright - key: cache-playwright-${{ hashFiles('**/yarn.lock') }} - restore-keys: cache-playwright- - - run: yarn --frozen-lockfile - - name: Install playwright deps - if: steps.playwright-cache.outputs.cache-hit != 'true' - run: yarn playwright install --with-deps + DATABASE_URL: ${{ env.DATABASE_URL }} + - uses: ./.github/actions/cache-build - name: Run Tests run: yarn turbo run embed-tests-update-snapshots:ci --scope=@calcom/embed-react --concurrency=1 - - name: Upload embed-core results if: ${{ always() }} uses: actions/upload-artifact@v2 diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index df4e687496..f1fa8cb5f0 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,20 +1,10 @@ name: E2E test on: - pull_request_target: # So we can test on forks - branches: - - main - paths: - - apps/web/** - - packages/** workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true jobs: e2e: timeout-minutes: 20 runs-on: buildjet-4vcpu-ubuntu-2204 - env: DATABASE_URL: postgresql://postgres:@localhost:5432/calendso NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000 @@ -64,34 +54,16 @@ jobs: - 5432:5432 steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks - fetch-depth: 2 + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV - - name: Use Node 16.x - uses: actions/setup-node@v3 + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/yarn-playwright-install + - uses: ./.github/actions/cache-db with: - node-version: 16.x - cache: "yarn" - - - name: Cache playwright binaries - uses: actions/cache@v2 - id: playwright-cache - with: - path: | - ~/Library/Caches/ms-playwright - ~/.cache/ms-playwright - ${{ github.workspace }}/node_modules/playwright - key: cache-playwright-${{ hashFiles('**/yarn.lock') }} - restore-keys: cache-playwright- - - run: yarn --frozen-lockfile - - name: Install playwright deps - if: steps.playwright-cache.outputs.cache-hit != 'true' - run: yarn playwright install --with-deps + DATABASE_URL: ${{ env.DATABASE_URL }} + - uses: ./.github/actions/cache-build - run: yarn test-e2e - - name: Upload test results if: ${{ always() }} uses: actions/upload-artifact@v2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a4a3718dc9..b566168d0a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,38 +1,14 @@ name: Lint on: - pull_request_target: - branches: - - main - paths: - - "**.tsx?" - - "**.jsx?" -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + workflow_call: jobs: lint: runs-on: buildjet-4vcpu-ubuntu-2204 steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 2 - - - name: Use Node 16.x - uses: actions/setup-node@v3 - with: - node-version: 16.x - cache: "yarn" - - - name: Install deps - if: steps.yarn-cache.outputs.cache-hit != 'true' - run: yarn --frozen-lockfile - - - name: Test Code Linting - run: yarn lint - + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout + - uses: ./.github/actions/yarn-install - name: Save Code Linting Reports run: yarn lint:report continue-on-error: true diff --git a/.github/workflows/nextjs-bundle-analysis.yml b/.github/workflows/nextjs-bundle-analysis.yml index 49f3fbab01..27fd9d597e 100644 --- a/.github/workflows/nextjs-bundle-analysis.yml +++ b/.github/workflows/nextjs-bundle-analysis.yml @@ -1,91 +1,21 @@ name: "Next.js Bundle Analysis" on: - pull_request: - push: - branches: - - main - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -defaults: - run: - # change this if your nextjs app does not live at the root of the repo - working-directory: ./apps/web/ + workflow_call: jobs: analyze: - env: - DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000 - NEXT_PUBLIC_WEBSITE_URL: http://localhost:3000 - NEXTAUTH_SECRET: secret - GOOGLE_API_CREDENTIALS: ${{ secrets.CI_GOOGLE_API_CREDENTIALS }} - GOOGLE_LOGIN_ENABLED: true - CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }} - DAILY_API_KEY: ${{ secrets.CI_DAILY_API_KEY }} - NEXT_PUBLIC_STRIPE_PUBLIC_KEY: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PUBLIC_KEY }} - NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE }} - NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE }} - NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE }} - NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE: ${{ secrets.NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE }} - NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN: 1 - STRIPE_PRIVATE_KEY: ${{ secrets.CI_STRIPE_PRIVATE_KEY }} - STRIPE_CLIENT_ID: ${{ secrets.CI_STRIPE_CLIENT_ID }} - STRIPE_WEBHOOK_SECRET: ${{ secrets.CI_STRIPE_WEBHOOK_SECRET }} - STRIPE_PRO_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_PRO_PLAN_PRODUCT_ID }} - STRIPE_PREMIUM_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_PREMIUM_PLAN_PRODUCT_ID }} - STRIPE_FREE_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_FREE_PLAN_PRODUCT_ID }} - PAYMENT_FEE_PERCENTAGE: 0.005 - PAYMENT_FEE_FIXED: 10 - SAML_DATABASE_URL: postgresql://postgres:@localhost:5432/calendso - SAML_ADMINS: pro@example.com - NEXTAUTH_URL: http://localhost:3000/api/auth - NEXT_PUBLIC_IS_E2E: 1 - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - services: - postgres: - image: postgres:12.1 - env: - POSTGRES_USER: postgres - POSTGRES_DB: calendso - ports: - - 5432:5432 runs-on: ubuntu-latest steps: + - run: cd ${{ github.workspace }} - uses: actions/checkout@v3 - - - name: Set up node - uses: actions/setup-node@v3 - with: - node-version: 16.x - cache: "yarn" - - - name: Install dependencies - uses: bahmutov/npm-install@v1 - - - name: Restore next build - uses: actions/cache@v2 - id: restore-build-cache - env: - cache-name: cache-next-build - with: - path: apps/web/.next/cache - # change this if you prefer a more strict cache - key: ${{ runner.os }}-build-${{ env.cache-name }} - - - name: Build next.js app - # change this if your site requires a custom build command - run: cd ../.. && yarn db-seed && yarn build - - # Here's the first place where next-bundle-analysis' own script is used - # This step pulls the raw bundle stats for the current bundle + - uses: ./.github/actions/dangerous-git-checkout + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/cache-build - name: Analyze bundle - run: npx -p nextjs-bundle-analysis report + run: | + cd apps/web + npx -p nextjs-bundle-analysis report - name: Upload bundle uses: actions/upload-artifact@v2 @@ -116,12 +46,15 @@ jobs: # entry in your package.json file. - name: Compare with base branch bundle if: success() && github.event.number - run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare + run: | + cd apps/web + ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare - name: Get comment body id: get-comment-body if: success() && github.event.number run: | + cd apps/web body=$(cat .next/analyze/__bundle_analysis_comment.txt) body="${body//'%'/'%25'}" body="${body//$'\n'/'%0A'}" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000000..a1e2c0921e --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,88 @@ +name: PR Update + +on: + push: + pull_request_target: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + app-store: ${{ steps.filter.outputs.app-store }} + embed: ${{ steps.filter.outputs.embed }} + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + app-store: + - 'apps/web/**' + - 'packages/app-store/**' + embed: + - 'apps/web/**' + - 'packages/embeds/**' + + setup: + name: Yarn install & cache + uses: ./.github/workflows/yarn-install.yml + secrets: inherit + + type-check: + name: Type check + needs: setup + uses: ./.github/workflows/check-types.yml + secrets: inherit + + test: + name: Unit tests + needs: setup + uses: ./.github/workflows/test.yml + secrets: inherit + + lint: + name: Linters + needs: setup + uses: ./.github/workflows/lint.yml + secrets: inherit + + build: + name: Production build + needs: setup + uses: ./.github/workflows/production-build.yml + secrets: inherit + + e2e: + name: E2E tests + needs: [lint, build] + uses: ./.github/workflows/e2e.yml + secrets: inherit + + e2e-app-store: + name: E2E App Store tests + if: ${{ needs.changes.outputs.app-store == 'true' }} + needs: [changes, lint, build] + uses: ./.github/workflows/e2e-app-store.yml + secrets: inherit + + e2e-embed: + name: E2E embeds tests + if: ${{ needs.changes.outputs.embed == 'true' }} + needs: [changes, lint, build] + uses: ./.github/workflows/e2e.yml + secrets: inherit + + analyze: + needs: build + uses: ./.github/workflows/nextjs-bundle-analysis.yml + secrets: inherit diff --git a/.github/workflows/production-build.yml b/.github/workflows/production-build.yml new file mode 100644 index 0000000000..de22d21e7e --- /dev/null +++ b/.github/workflows/production-build.yml @@ -0,0 +1,85 @@ +name: Production Build + +on: + workflow_call: + +env: + DATABASE_URL: postgresql://postgres:@localhost:5432/calendso + NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000 + NEXT_PUBLIC_WEBSITE_URL: http://localhost:3000 + NEXTAUTH_SECRET: secret + GOOGLE_API_CREDENTIALS: ${{ secrets.CI_GOOGLE_API_CREDENTIALS }} + GOOGLE_LOGIN_ENABLED: true + # CRON_API_KEY: xxx + CALENDSO_ENCRYPTION_KEY: ${{ secrets.CI_CALENDSO_ENCRYPTION_KEY }} + DAILY_API_KEY: ${{ secrets.CI_DAILY_API_KEY }} + NEXT_PUBLIC_STRIPE_PUBLIC_KEY: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PUBLIC_KEY }} + NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE: ${{ secrets.CI_NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE: ${{ secrets.NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE }} + NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN: 1 + STRIPE_PRIVATE_KEY: ${{ secrets.CI_STRIPE_PRIVATE_KEY }} + STRIPE_CLIENT_ID: ${{ secrets.CI_STRIPE_CLIENT_ID }} + STRIPE_WEBHOOK_SECRET: ${{ secrets.CI_STRIPE_WEBHOOK_SECRET }} + STRIPE_PRO_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_PRO_PLAN_PRODUCT_ID }} + STRIPE_PREMIUM_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_PREMIUM_PLAN_PRODUCT_ID }} + STRIPE_FREE_PLAN_PRODUCT_ID: ${{ secrets.CI_STRIPE_FREE_PLAN_PRODUCT_ID }} + PAYMENT_FEE_PERCENTAGE: 0.005 + PAYMENT_FEE_FIXED: 10 + SAML_DATABASE_URL: postgresql://postgres:@localhost:5432/calendso + SAML_ADMINS: pro@example.com + NEXTAUTH_URL: http://localhost:3000/api/auth + NEXT_PUBLIC_IS_E2E: 1 + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 30 + services: + postgres: + image: postgres:12.1 + env: + POSTGRES_USER: postgres + POSTGRES_DB: calendso + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/yarn-install + - uses: ./.github/actions/yarn-build + with: + # GitHub Composite actions cannot read secrets, we have to pass them in here + DATABASE_URL: ${{ env.DATABASE_URL }} + NEXT_PUBLIC_WEBAPP_URL: ${{ env.NEXT_PUBLIC_WEBAPP_URL }} + NEXT_PUBLIC_WEBSITE_URL: ${{ env.NEXT_PUBLIC_WEBSITE_URL }} + NEXTAUTH_SECRET: ${{ env.NEXTAUTH_SECRET }} + GOOGLE_API_CREDENTIALS: ${{ env.GOOGLE_API_CREDENTIALS }} + GOOGLE_LOGIN_ENABLED: ${{ env.GOOGLE_LOGIN_ENABLED }} + CALENDSO_ENCRYPTION_KEY: ${{ env.CALENDSO_ENCRYPTION_KEY }} + DAILY_API_KEY: ${{ env.DAILY_API_KEY }} + NEXT_PUBLIC_STRIPE_PUBLIC_KEY: ${{ env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY }} + NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE: ${{ env.NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE: ${{ env.NEXT_PUBLIC_STRIPE_PRO_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE: ${{ env.NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE }} + NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE: ${{ env.NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE }} + NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN: ${{ env.NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN }} + STRIPE_PRIVATE_KEY: ${{ env.STRIPE_PRIVATE_KEY }} + STRIPE_CLIENT_ID: ${{ env.STRIPE_CLIENT_ID }} + STRIPE_WEBHOOK_SECRET: ${{ env.STRIPE_WEBHOOK_SECRET }} + STRIPE_PRO_PLAN_PRODUCT_ID: ${{ env.STRIPE_PRO_PLAN_PRODUCT_ID }} + STRIPE_PREMIUM_PLAN_PRODUCT_ID: ${{ env.STRIPE_PREMIUM_PLAN_PRODUCT_ID }} + STRIPE_FREE_PLAN_PRODUCT_ID: ${{ env.STRIPE_FREE_PLAN_PRODUCT_ID }} + PAYMENT_FEE_PERCENTAGE: ${{ env.PAYMENT_FEE_PERCENTAGE }} + PAYMENT_FEE_FIXED: ${{ env.PAYMENT_FEE_FIXED }} + SAML_DATABASE_URL: ${{ env.SAML_DATABASE_URL }} + SAML_ADMINS: ${{ env.SAML_ADMINS }} + NEXTAUTH_URL: ${{ env.NEXTAUTH_URL }} + NEXT_PUBLIC_IS_E2E: ${{ env.NEXT_PUBLIC_IS_E2E }} + TURBO_TOKEN: ${{ env.TURBO_TOKEN }} + TURBO_TEAM: ${{ env.TURBO_TEAM }} + - uses: ./.github/actions/cache-db + with: + DATABASE_URL: ${{ env.DATABASE_URL }} diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml deleted file mode 100644 index af0bce1bae..0000000000 --- a/.github/workflows/required-checks.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: "Meta Workflow: Require Conditional Status Checks" -on: - pull_request: - branches: - - main - workflow_call: -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true -jobs: - required-checks: - runs-on: ubuntu-latest - steps: - - name: Ensure All Conditional Checks Have Passed - uses: blend/require-conditional-status-checks@2022.02.04 - with: - timeout: 15m - github-token: ${{ github.token }} - interval: 20s - # Question marks aren't working - # @see https://github.com/blend/require-conditional-status-checks/pull/11 - checks-yaml: | - - job: lint - paths: - - /**/*.jsx - - /**/*.js - - /**/*.tsx - - /**/*.ts - - job: check-types - paths: - - /**/*.tsx - - /**/*.ts - - job: e2e - paths: - - /apps/web/** - - /packages/** - - job: e2e-embed - paths: - - /apps/web/** - - /packages/embeds/** - - job: test - paths: - - /apps/web/** - - /packages/** diff --git a/.github/workflows/submodule-sync.yml b/.github/workflows/submodule-sync.yml index e8c90cb83e..442ea4bde1 100644 --- a/.github/workflows/submodule-sync.yml +++ b/.github/workflows/submodule-sync.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: submodules: recursive token: ${{ secrets.GH_ACCESS_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfdeac9b47..e71506689f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,33 +1,17 @@ name: Unit tests on: - pull_request_target: # So we can test on forks - branches: - - main - paths: - - apps/web/** - - packages/** + workflow_call: workflow_run: workflows: [Crowdin Action] types: [completed] -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true jobs: test: timeout-minutes: 20 runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks - fetch-depth: 2 - # Should be an 8GB machine as per https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout - run: echo 'NODE_OPTIONS="--max_old_space_size=6144"' >> $GITHUB_ENV - - name: Use Node 16.x - uses: actions/setup-node@v3 - with: - node-version: 16.x - cache: "yarn" - - run: yarn --frozen-lockfile + - uses: ./.github/actions/yarn-install + # Should be an 8GB machine as per https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners - run: yarn test diff --git a/.github/workflows/yarn-install.yml b/.github/workflows/yarn-install.yml new file mode 100644 index 0000000000..3ee08b3f48 --- /dev/null +++ b/.github/workflows/yarn-install.yml @@ -0,0 +1,14 @@ +name: Yarn install + +on: + workflow_call: + +jobs: + setup: + name: Yarn install & cache + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/dangerous-git-checkout + - uses: ./.github/actions/yarn-install diff --git a/package.json b/package.json index 8f2d9a0878..86d0ec2f8d 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "tdd": "jest --watch", "e2e": "NEXT_PUBLIC_IS_E2E=1 yarn playwright test --project=@calcom/web", "e2e:app-store": "QUICK=true yarn playwright test --project=@calcom/app-store", - "test-e2e": "yarn db-seed && yarn build && yarn e2e", - "test-e2e:app-store": "yarn db-seed && yarn build && yarn e2e:app-store", + "test-e2e": "yarn db-seed && yarn e2e", + "test-e2e:app-store": "yarn db-seed && yarn e2e:app-store", "test-playwright": "yarn playwright test --config=playwright.config.ts", "test": "jest", "type-check": "turbo run type-check",