Skip to content

Commit 47a8ba1

Browse files
chore: streamline ready-for-e2e label check for PRs (#15545)
* Added a log for pull_request * Added labels logging * Using labels straight from event PR object * Converting to JSON * Switching to use payload * Fixed issue with undefined pr * Fixed non-mapping issue * Removed the types * Removed issue with run-jobs * Put back the types
1 parent c4e78c2 commit 47a8ba1

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

.github/workflows/pr.yml

+38-35
Original file line numberDiff line numberDiff line change
@@ -41,71 +41,75 @@ jobs:
4141
name: Check for E2E label
4242
outputs:
4343
run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'ready-for-e2e')) }}
44-
run-jobs: ${{ github.event.action != 'labeled' }}
4544
steps:
4645
- name: Check if PR exists with ready-for-e2e label for this SHA
4746
id: check-if-pr-has-label
4847
uses: actions/github-script@v7
4948
with:
5049
script: |
51-
console.log('github.event.action', '${{ github.event.action }}');
52-
try {
53-
const sha = '${{ needs.changes.outputs.commit-sha }}';
54-
console.log('sha', sha);
55-
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
56-
owner: context.repo.owner,
57-
repo: context.repo.repo,
58-
commit_sha: sha
59-
});
60-
61-
if (prs.length === 0) {
50+
let labels = [];
51+
52+
if (context.payload.pull_request) {
53+
labels = context.payload.pull_request.labels;
54+
} else {
55+
try {
56+
const sha = '${{ needs.changes.outputs.commit-sha }}';
57+
console.log('sha', sha);
58+
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
commit_sha: sha
62+
});
63+
64+
if (prs.length === 0) {
65+
core.setOutput('run-e2e', false);
66+
console.log(`No pull requests found for commit SHA ${sha}`);
67+
return;
68+
}
69+
70+
const pr = prs[0];
71+
console.log(`PR number: ${pr.number}`);
72+
console.log(`PR title: ${pr.title}`);
73+
console.log(`PR state: ${pr.state}`);
74+
console.log(`PR URL: ${pr.html_url}`);
75+
76+
labels = pr.labels;
77+
}
78+
catch (e) {
6279
core.setOutput('run-e2e', false);
63-
console.log(`No pull requests found for commit SHA ${sha}`);
64-
return;
80+
console.log(e);
6581
}
66-
67-
const pr = prs[0];
68-
console.log(`PR number: ${pr.number}`);
69-
console.log(`PR title: ${pr.title}`);
70-
console.log(`PR state: ${pr.state}`);
71-
console.log(`PR URL: ${pr.html_url}`);
72-
73-
const labels = pr.labels.map(label => label.name);
74-
const labelFound = labels.includes('ready-for-e2e');
75-
console.log('PR #', pr.number);
76-
console.log('Found the label?', labelFound);
77-
core.setOutput('run-e2e', labelFound);
78-
}
79-
catch (e) {
80-
core.setOutput('run-e2e', false);
81-
console.log(e);
8282
}
8383
84+
const labelFound = labels.map(l => l.name).includes('ready-for-e2e');
85+
console.log('Found the label?', labelFound);
86+
core.setOutput('run-e2e', labelFound);
87+
8488
type-check:
8589
name: Type check
8690
needs: [changes, check-label]
87-
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
91+
if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
8892
uses: ./.github/workflows/check-types.yml
8993
secrets: inherit
9094

9195
lint:
9296
name: Linters
9397
needs: [changes, check-label]
94-
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
98+
if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
9599
uses: ./.github/workflows/lint.yml
96100
secrets: inherit
97101

98102
unit-test:
99103
name: Tests
100104
needs: [changes, check-label]
101-
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
105+
if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
102106
uses: ./.github/workflows/unit-tests.yml
103107
secrets: inherit
104108

105109
integration-test:
106110
name: Tests
107111
needs: [changes, check-label]
108-
if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
112+
if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }}
109113
uses: ./.github/workflows/integration-tests.yml
110114
secrets: inherit
111115

@@ -166,7 +170,6 @@ jobs:
166170

167171
required:
168172
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]
169-
if: ${{ needs.check-label.outputs.run-e2e == 'true' }}
170173
runs-on: buildjet-2vcpu-ubuntu-2204
171174
steps:
172175
- name: fail if conditional jobs failed

0 commit comments

Comments
 (0)