From 4a88051531f6403e21ba1ff1567cbfb0fade319d Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Fri, 21 Jun 2024 21:52:27 -0300 Subject: [PATCH] chore: Only run E2E suite when ready-for-e2e label added (#15529) * chore: Improve CI workflow * Made a new pre-merge flow that runs the builds and e2e * Refactored back into 1 file * Adding another condition for checking the ready-for-e2e * syntax * More syntax * Change e2e-required to only run when ready so it doesn't fail * A different attempt at getting the ready-for-e2e label * Supporting PRs and workflow_dispatch * logging the branch * hardcoding to test * Trying the rest call * Added logging * Check for the label in the same step * More logging * Added job-level output * Reverted back to 'true' * Moved the e2e required check into the main required check * More logging * Peeling the branch off of the ref * Fix the ref * Trying a separate workflow for labeling * Updated name for the labeled file * Checking label events to avoid unnecessary runs * Got rid of the extra check to see if required should run * Upgraded old actions running Node 16 * Updated the pre-reqs for running jobs * Removed the dependency of API builds before starting E2E suites * Removed extra production build used by analyze job * Fixed the run-e2e check * Using the pull request object when available * Checking for null PR * Added check for no event --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> --- .github/workflows/api-v1-production-build.yml | 2 +- .github/workflows/api-v2-production-build.yml | 2 +- .github/workflows/nextjs-bundle-analysis.yml | 6 - .github/workflows/pr-review.yml | 17 +++ .github/workflows/pr.yml | 133 ++++++++++++++++-- 5 files changed, 142 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/pr-review.yml diff --git a/.github/workflows/api-v1-production-build.yml b/.github/workflows/api-v1-production-build.yml index 3fdd51d512..80a24ef801 100644 --- a/.github/workflows/api-v1-production-build.yml +++ b/.github/workflows/api-v1-production-build.yml @@ -65,7 +65,7 @@ jobs: - uses: ./.github/actions/yarn-install - uses: ./.github/actions/cache-db - name: Cache API v1 production build - uses: buildjet/cache@v3 + uses: buildjet/cache@v4 id: cache-api-v1-build env: cache-name: api-v1-build diff --git a/.github/workflows/api-v2-production-build.yml b/.github/workflows/api-v2-production-build.yml index da2f17c40a..28fe054a93 100644 --- a/.github/workflows/api-v2-production-build.yml +++ b/.github/workflows/api-v2-production-build.yml @@ -34,7 +34,7 @@ jobs: - uses: ./.github/actions/dangerous-git-checkout - uses: ./.github/actions/yarn-install - name: Cache API v2 production build - uses: buildjet/cache@v3 + uses: buildjet/cache@v4 id: cache-api-v2-build env: cache-name: api-v2-build diff --git a/.github/workflows/nextjs-bundle-analysis.yml b/.github/workflows/nextjs-bundle-analysis.yml index 823063321f..dc293e4501 100644 --- a/.github/workflows/nextjs-bundle-analysis.yml +++ b/.github/workflows/nextjs-bundle-analysis.yml @@ -45,13 +45,7 @@ env: TURBO_TEAM: ${{ secrets.TURBO_TEAM }} jobs: - build: - name: Production builds - if: ${{ github.event_name == 'push' }} - uses: ./.github/workflows/production-build-without-database.yml - secrets: inherit analyze: - needs: build if: always() runs-on: buildjet-2vcpu-ubuntu-2204 steps: diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml new file mode 100644 index 0000000000..d18a871ef8 --- /dev/null +++ b/.github/workflows/pr-review.yml @@ -0,0 +1,17 @@ +name: PR Reviewed + +on: + pull_request_review: + types: [submitted] + +jobs: + label-pr: + runs-on: ubuntu-latest + + steps: + - name: Label PR as ready for E2E + if: github.event.review.state == 'approved' + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: 'ready-for-e2e' diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e8099fae92..40b57091a3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -2,6 +2,7 @@ name: PR Update on: pull_request_target: + types: [opened, synchronize, reopened, labeled] branches: - main workflow_dispatch: @@ -27,37 +28,149 @@ jobs: filters: | has-files-requiring-all-checks: - "!(**.md|.github/CODEOWNERS)" + + check-label: + runs-on: buildjet-2vcpu-ubuntu-2204 + name: Check for E2E label + outputs: + run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event_name != 'labeled' || (github.event_name == 'labeled' && github.event.label.name == 'ready-for-e2e')) }} + run-jobs: ${{ github.event_name != 'labeled' }} + steps: + - name: Get PR from branch name + id: check-if-pr-has-label + uses: actions/github-script@v7 + with: + script: | + let pr; + if (github.event && github.event.pull_request) { + const response = await github.rest.pulls.get({ + owner: github.context.repo.owner, + repo: github.context.repo.repo, + pull_number: github.event.pull_request.number + }); + + pr = response.data; + } else { + const ref = '${{ github.ref }}'; + const branch = ref.replace('refs/heads/', ''); + console.log(ref); + console.log(branch); + const response = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: `${context.repo.owner}:${branch}` + }); + + if (response.data.length > 0) { + pr = response.data[0]; + } else { + core.setOutput('run-e2e', false); + console.log('No PR found matching the branch'); + } + } + + if (!pr) { + console.log('No PR found'); + return; + } + + const labels = pr.labels.map(label => label.name); + console.log('PR #', pr.number); + if (labels.includes('ready-for-e2e')) { + core.setOutput('run-e2e', true); + console.log('Found the label'); + } else { + core.setOutput('run-e2e', false); + console.log('Did not find the label'); + } + type-check: name: Type check - needs: [changes] - if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/check-types.yml secrets: inherit lint: name: Linters - needs: [changes] - if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/lint.yml secrets: inherit unit-test: name: Tests - needs: [changes] - if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/unit-tests.yml secrets: inherit integration-test: name: Tests - needs: [changes] - if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/integration-tests.yml secrets: inherit + build-api-v1: + name: Production builds + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/api-v1-production-build.yml + secrets: inherit + + build-api-v2: + name: Production builds + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/api-v2-production-build.yml + secrets: inherit + + build: + name: Production builds + needs: [changes, check-label] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/production-build-without-database.yml + secrets: inherit + + e2e: + name: Tests + needs: [changes, check-label, build] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/e2e.yml + secrets: inherit + + e2e-app-store: + name: Tests + needs: [changes, check-label, build] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/e2e-app-store.yml + secrets: inherit + + e2e-embed: + name: Tests + needs: [changes, check-label, build] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/e2e-embed.yml + secrets: inherit + + e2e-embed-react: + name: Tests + needs: [changes, check-label, build] + if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + uses: ./.github/workflows/e2e-embed-react.yml + secrets: inherit + + analyze: + name: Analyze Build + needs: [build] + uses: ./.github/workflows/nextjs-bundle-analysis.yml + secrets: inherit + required: - needs: [changes, lint, type-check, unit-test, integration-test] - if: always() + needs: [changes, lint, type-check, unit-test, integration-test, check-label, build, build-api-v1, build-api-v2, e2e, e2e-embed, e2e-embed-react, e2e-app-store] + if: ${{ needs.check-label.outputs.run-e2e == 'true' }} runs-on: buildjet-2vcpu-ubuntu-2204 steps: - name: fail if conditional jobs failed