Skip to content

Commit 4a88051

Browse files
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>
1 parent 765b0b4 commit 4a88051

5 files changed

+142
-18
lines changed

.github/workflows/api-v1-production-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- uses: ./.github/actions/yarn-install
6666
- uses: ./.github/actions/cache-db
6767
- name: Cache API v1 production build
68-
uses: buildjet/cache@v3
68+
uses: buildjet/cache@v4
6969
id: cache-api-v1-build
7070
env:
7171
cache-name: api-v1-build

.github/workflows/api-v2-production-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- uses: ./.github/actions/dangerous-git-checkout
3535
- uses: ./.github/actions/yarn-install
3636
- name: Cache API v2 production build
37-
uses: buildjet/cache@v3
37+
uses: buildjet/cache@v4
3838
id: cache-api-v2-build
3939
env:
4040
cache-name: api-v2-build

.github/workflows/nextjs-bundle-analysis.yml

-6
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ env:
4545
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
4646

4747
jobs:
48-
build:
49-
name: Production builds
50-
if: ${{ github.event_name == 'push' }}
51-
uses: ./.github/workflows/production-build-without-database.yml
52-
secrets: inherit
5348
analyze:
54-
needs: build
5549
if: always()
5650
runs-on: buildjet-2vcpu-ubuntu-2204
5751
steps:

.github/workflows/pr-review.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: PR Reviewed
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
jobs:
8+
label-pr:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Label PR as ready for E2E
13+
if: github.event.review.state == 'approved'
14+
uses: actions-ecosystem/action-add-labels@v1
15+
with:
16+
github_token: ${{ secrets.GITHUB_TOKEN }}
17+
labels: 'ready-for-e2e'

.github/workflows/pr.yml

+123-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: PR Update
22

33
on:
44
pull_request_target:
5+
types: [opened, synchronize, reopened, labeled]
56
branches:
67
- main
78
workflow_dispatch:
@@ -27,37 +28,149 @@ jobs:
2728
filters: |
2829
has-files-requiring-all-checks:
2930
- "!(**.md|.github/CODEOWNERS)"
31+
32+
check-label:
33+
runs-on: buildjet-2vcpu-ubuntu-2204
34+
name: Check for E2E label
35+
outputs:
36+
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')) }}
37+
run-jobs: ${{ github.event_name != 'labeled' }}
38+
steps:
39+
- name: Get PR from branch name
40+
id: check-if-pr-has-label
41+
uses: actions/github-script@v7
42+
with:
43+
script: |
44+
let pr;
45+
if (github.event && github.event.pull_request) {
46+
const response = await github.rest.pulls.get({
47+
owner: github.context.repo.owner,
48+
repo: github.context.repo.repo,
49+
pull_number: github.event.pull_request.number
50+
});
51+
52+
pr = response.data;
53+
} else {
54+
const ref = '${{ github.ref }}';
55+
const branch = ref.replace('refs/heads/', '');
56+
console.log(ref);
57+
console.log(branch);
58+
const response = await github.rest.pulls.list({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
state: 'open',
62+
head: `${context.repo.owner}:${branch}`
63+
});
64+
65+
if (response.data.length > 0) {
66+
pr = response.data[0];
67+
} else {
68+
core.setOutput('run-e2e', false);
69+
console.log('No PR found matching the branch');
70+
}
71+
}
72+
73+
if (!pr) {
74+
console.log('No PR found');
75+
return;
76+
}
77+
78+
const labels = pr.labels.map(label => label.name);
79+
console.log('PR #', pr.number);
80+
if (labels.includes('ready-for-e2e')) {
81+
core.setOutput('run-e2e', true);
82+
console.log('Found the label');
83+
} else {
84+
core.setOutput('run-e2e', false);
85+
console.log('Did not find the label');
86+
}
87+
3088
type-check:
3189
name: Type check
32-
needs: [changes]
33-
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
90+
needs: [changes, check-label]
91+
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
3492
uses: ./.github/workflows/check-types.yml
3593
secrets: inherit
3694

3795
lint:
3896
name: Linters
39-
needs: [changes]
40-
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
97+
needs: [changes, check-label]
98+
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
4199
uses: ./.github/workflows/lint.yml
42100
secrets: inherit
43101

44102
unit-test:
45103
name: Tests
46-
needs: [changes]
47-
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
104+
needs: [changes, check-label]
105+
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
48106
uses: ./.github/workflows/unit-tests.yml
49107
secrets: inherit
50108

51109
integration-test:
52110
name: Tests
53-
needs: [changes]
54-
if: ${{ needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
111+
needs: [changes, check-label]
112+
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
55113
uses: ./.github/workflows/integration-tests.yml
56114
secrets: inherit
57115

116+
build-api-v1:
117+
name: Production builds
118+
needs: [changes, check-label]
119+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
120+
uses: ./.github/workflows/api-v1-production-build.yml
121+
secrets: inherit
122+
123+
build-api-v2:
124+
name: Production builds
125+
needs: [changes, check-label]
126+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
127+
uses: ./.github/workflows/api-v2-production-build.yml
128+
secrets: inherit
129+
130+
build:
131+
name: Production builds
132+
needs: [changes, check-label]
133+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
134+
uses: ./.github/workflows/production-build-without-database.yml
135+
secrets: inherit
136+
137+
e2e:
138+
name: Tests
139+
needs: [changes, check-label, build]
140+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
141+
uses: ./.github/workflows/e2e.yml
142+
secrets: inherit
143+
144+
e2e-app-store:
145+
name: Tests
146+
needs: [changes, check-label, build]
147+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
148+
uses: ./.github/workflows/e2e-app-store.yml
149+
secrets: inherit
150+
151+
e2e-embed:
152+
name: Tests
153+
needs: [changes, check-label, build]
154+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
155+
uses: ./.github/workflows/e2e-embed.yml
156+
secrets: inherit
157+
158+
e2e-embed-react:
159+
name: Tests
160+
needs: [changes, check-label, build]
161+
if: ${{ needs.check-label.outputs.run-e2e == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
162+
uses: ./.github/workflows/e2e-embed-react.yml
163+
secrets: inherit
164+
165+
analyze:
166+
name: Analyze Build
167+
needs: [build]
168+
uses: ./.github/workflows/nextjs-bundle-analysis.yml
169+
secrets: inherit
170+
58171
required:
59-
needs: [changes, lint, type-check, unit-test, integration-test]
60-
if: always()
172+
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]
173+
if: ${{ needs.check-label.outputs.run-e2e == 'true' }}
61174
runs-on: buildjet-2vcpu-ubuntu-2204
62175
steps:
63176
- name: fail if conditional jobs failed

0 commit comments

Comments
 (0)