Skip to content

Commit 869fe5f

Browse files
authored
Update release-bot.yaml
1 parent efe2eba commit 869fe5f

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

.github/workflows/release-bot.yaml

+37-11
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,59 @@ jobs:
1515
with:
1616
github-token: ${{secrets.GITHUB_TOKEN}}
1717
script: |
18+
console.log('Starting script');
1819
const { issue, comment } = context.payload;
1920
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');
2240
return;
2341
}
2442
43+
console.log('Valid release command');
2544
const releaseBranch = comment.body.split('/release to ')[1].trim();
45+
console.log('Release branch:', releaseBranch);
46+
core.setOutput('release_valid', 'true');
2647
core.setOutput('release_branch', releaseBranch);
2748
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
3556

3657
- name: Checkout repository
58+
if: steps.check_command.outputs.release_valid == 'true'
3759
uses: actions/checkout@v3
3860
with:
3961
fetch-depth: 0
4062

4163
- name: Setup Git
64+
if: steps.check_command.outputs.release_valid == 'true'
4265
run: |
4366
git config --global user.email "[email protected]"
4467
git config --global user.name "Tyk Bot"
4568
4669
- name: Install GitHub CLI
70+
if: steps.check_command.outputs.release_valid == 'true'
4771
run: |
4872
type -p curl >/dev/null || sudo apt install curl -y
4973
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:
5377
&& sudo apt install gh -y
5478
5579
- name: Get PR details
80+
if: steps.check_command.outputs.release_valid == 'true'
5681
id: pr_details
5782
run: |
5883
PR_DATA=$(gh pr view ${{ steps.check_command.outputs.pr_number }} --json headRefOid)
5984
COMMIT_SHA=$(echo $PR_DATA | jq -r .headRefOid)
6085
echo "COMMIT_SHA=${COMMIT_SHA}" >> $GITHUB_OUTPUT
6186
6287
- name: Cherry-pick commit
88+
if: steps.check_command.outputs.release_valid == 'true'
6389
id: cherry_pick
6490
env:
6591
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -93,7 +119,7 @@ jobs:
93119
echo "MERGE_FAILED=$MERGE_FAILED" >> $GITHUB_OUTPUT
94120
95121
- name: Comment on PR
96-
if: always()
122+
if: steps.check_command.outputs.release_valid == 'true' && always()
97123
uses: actions/github-script@v6
98124
with:
99125
github-token: ${{secrets.GITHUB_TOKEN}}
@@ -113,7 +139,7 @@ jobs:
113139
}
114140
115141
github.rest.issues.createComment({
116-
issue_number: '${{ steps.check_command.outputs.pr_number }}',
142+
issue_number: ${{ steps.check_command.outputs.pr_number }},
117143
owner: context.repo.owner,
118144
repo: context.repo.name,
119145
body: body

0 commit comments

Comments
 (0)