@@ -15,35 +15,59 @@ jobs:
15
15
with :
16
16
github-token : ${{secrets.GITHUB_TOKEN}}
17
17
script : |
18
+ console.log('Starting script');
18
19
const { issue, comment } = context.payload;
19
20
20
- if (!issue || !issue.pull_request || !comment || !comment.body.startsWith('/release to ')) {
21
- core.setFailed('Not a valid release command on a pull request.');
21
+ // Debugging the values of issue and comment
22
+ console.log('Issue:', JSON.stringify(issue, null, 2));
23
+ console.log('Comment:', JSON.stringify(comment, null, 2));
24
+
25
+ if (!issue) {
26
+ console.log('No issue object found in the payload.');
27
+ core.setOutput('release_valid', 'false');
28
+ return;
29
+ }
30
+
31
+ if (!issue.pull_request) {
32
+ console.log('This issue is not related to a pull request.');
33
+ core.setOutput('release_valid', 'false');
34
+ return;
35
+ }
36
+
37
+ if (!comment || !comment.body.startsWith('/release to ')) {
38
+ console.log(`Comment body does not start with '/release to '. Comment: ${comment ? comment.body : 'undefined'}`);
39
+ core.setOutput('release_valid', 'false');
22
40
return;
23
41
}
24
42
43
+ console.log('Valid release command');
25
44
const releaseBranch = comment.body.split('/release to ')[1].trim();
45
+ console.log('Release branch:', releaseBranch);
46
+ core.setOutput('release_valid', 'true');
26
47
core.setOutput('release_branch', releaseBranch);
27
48
core.setOutput('pr_number', issue.number);
28
-
29
- await github.rest.issues.createComment({
30
- issue_number: issue.number,
31
- owner: context.repo.owner,
32
- repo: context.repo.name,
33
- body: '🔄 Cherry-pick operation started. Please wait...'
34
- });
49
+
50
+ # Conditionally skip subsequent steps if the release command is not valid
51
+ - name : Skip jobs if not a valid release command
52
+ if : steps.check_command.outputs.release_valid == 'false'
53
+ run : |
54
+ echo "Skipping cherry-pick as the release command is not valid."
55
+ continue-on-error : true
35
56
36
57
- name : Checkout repository
58
+ if : steps.check_command.outputs.release_valid == 'true'
37
59
uses : actions/checkout@v3
38
60
with :
39
61
fetch-depth : 0
40
62
41
63
- name : Setup Git
64
+ if : steps.check_command.outputs.release_valid == 'true'
42
65
run : |
43
66
git config --global user.email "[email protected] "
44
67
git config --global user.name "Tyk Bot"
45
68
46
69
- name : Install GitHub CLI
70
+ if : steps.check_command.outputs.release_valid == 'true'
47
71
run : |
48
72
type -p curl >/dev/null || sudo apt install curl -y
49
73
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
@@ -53,13 +77,15 @@ jobs:
53
77
&& sudo apt install gh -y
54
78
55
79
- name : Get PR details
80
+ if : steps.check_command.outputs.release_valid == 'true'
56
81
id : pr_details
57
82
run : |
58
83
PR_DATA=$(gh pr view ${{ steps.check_command.outputs.pr_number }} --json headRefOid)
59
84
COMMIT_SHA=$(echo $PR_DATA | jq -r .headRefOid)
60
85
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_OUTPUT
61
86
62
87
- name : Cherry-pick commit
88
+ if : steps.check_command.outputs.release_valid == 'true'
63
89
id : cherry_pick
64
90
env :
65
91
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
93
119
echo "MERGE_FAILED=$MERGE_FAILED" >> $GITHUB_OUTPUT
94
120
95
121
- name : Comment on PR
96
- if : always()
122
+ if : steps.check_command.outputs.release_valid == 'true' && always()
97
123
uses : actions/github-script@v6
98
124
with :
99
125
github-token : ${{secrets.GITHUB_TOKEN}}
@@ -113,7 +139,7 @@ jobs:
113
139
}
114
140
115
141
github.rest.issues.createComment({
116
- issue_number: ' ${{ steps.check_command.outputs.pr_number }}' ,
142
+ issue_number: ${{ steps.check_command.outputs.pr_number }},
117
143
owner: context.repo.owner,
118
144
repo: context.repo.name,
119
145
body: body
0 commit comments