19
19
pull-requests : read
20
20
outputs :
21
21
has-files-requiring-all-checks : ${{ steps.filter.outputs.has-files-requiring-all-checks }}
22
+ commit-sha : ${{ steps.get_sha.outputs.commit-sha }}
22
23
steps :
23
24
- uses : actions/checkout@v4
24
25
- uses : ./.github/actions/dangerous-git-checkout
@@ -28,59 +29,57 @@ jobs:
28
29
filters : |
29
30
has-files-requiring-all-checks:
30
31
- "!(**.md|.github/CODEOWNERS)"
32
+ - name : Get Latest Commit SHA
33
+ id : get_sha
34
+ run : |
35
+ echo "commit-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
31
36
32
37
check-label :
38
+ needs : [changes]
33
39
runs-on : buildjet-2vcpu-ubuntu-2204
34
40
name : Check for E2E label
35
41
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' }}
42
+ 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')) }}
43
+ run-jobs : ${{ github.event.action != 'labeled' }}
38
44
steps :
39
- - name : Get PR from branch name
45
+ - name : Check if PR exists with ready-for-e2e label for this SHA
40
46
id : check-if-pr-has-label
41
47
uses : actions/github-script@v7
42
48
with :
43
49
script : |
44
- let pr;
45
- console.log('github.event_name', '${{ github.event_name }}');
46
- const parsedEvent = ${{ github.event }};
47
- if (parsedEvent && parsedEvent.pull_request) {
48
- const response = await github.rest.pulls.get({
49
- owner: github.context.repo.owner,
50
- repo: github.context.repo.repo,
51
- pull_number: parsedEvent.pull_request.number
52
- });
53
-
54
- pr = response.data;
55
- } else {
56
- const ref = '${{ github.ref }}';
57
- const branch = ref.replace('refs/heads/', '');
58
- console.log('ref', ref);
59
- console.log('branch', branch);
60
- const response = await github.rest.pulls.list({
50
+ console.log('github.event.action', '${{ github.event.action }}');
51
+ try {
52
+ const sha = '${{ needs.changes.outputs.commit-sha }}';
53
+ console.log('sha', sha);
54
+ const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
61
55
owner: context.repo.owner,
62
56
repo: context.repo.repo,
63
- state: 'open',
64
- head: `${context.repo.owner}:${branch}`
57
+ commit_sha: sha
65
58
});
66
59
67
- if (response.data.length > 0) {
68
- pr = response.data[0];
60
+ if (prs.length === 0) {
61
+ core.setOutput('run-e2e', false);
62
+ console.log(`No pull requests found for commit SHA ${sha}`);
63
+ return;
69
64
}
70
- }
71
65
72
- if (!pr) {
66
+ const pr = prs[0];
67
+ console.log(`PR number: ${pr.number}`);
68
+ console.log(`PR title: ${pr.title}`);
69
+ console.log(`PR state: ${pr.state}`);
70
+ console.log(`PR URL: ${pr.html_url}`);
71
+
72
+ const labels = pr.labels.map(label => label.name);
73
+ const labelFound = labels.includes('ready-for-e2e');
74
+ console.log('PR #', pr.number);
75
+ console.log('Found the label?', labelFound);
76
+ core.setOutput('run-e2e', labelFound);
77
+ }
78
+ catch (e) {
73
79
core.setOutput('run-e2e', false);
74
- console.log('No PR found');
75
- return;
80
+ console.log(e);
76
81
}
77
82
78
- const labels = pr.labels.map(label => label.name);
79
- const labelFound = labels.includes('ready-for-e2e');
80
- console.log('PR #', pr.number);
81
- console.log('Found the label?', labelFound);
82
- core.setOutput('run-e2e', labelFound);
83
-
84
83
type-check :
85
84
name : Type check
86
85
needs : [changes, check-label]
0 commit comments