1313 id : check_command
1414 uses : actions/github-script@v6
1515 with :
16- github-token : ${{secrets.GITHUB_TOKEN}}
16+ github-token : ${{ secrets.GITHUB_TOKEN }}
1717 script : |
1818 const { issue, comment } = context.payload;
1919
2727 core.setOutput('release_branch', releaseBranch);
2828 core.setOutput('pr_number', issue.number);
2929
30+ - name : Install GitHub CLI (for act/local testing)
31+ if : steps.check_command.outputs.release_valid == 'true'
32+ run : |
33+ sudo apt update
34+ sudo apt install -y curl unzip gnupg
35+ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null
36+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
37+ sudo apt update
38+ sudo apt install -y gh
39+
3040 - name : Checkout repository
3141 if : steps.check_command.outputs.release_valid == 'true'
3242 uses : actions/checkout@v3
@@ -35,13 +45,11 @@ jobs:
3545
3646 - name : Set default branch variable
3747 if : steps.check_command.outputs.release_valid == 'true'
38- run : |
39- echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
48+ run : echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
4049
4150 - name : Skip jobs if not a valid release command
4251 if : steps.check_command.outputs.release_valid == 'false'
43- run : |
44- echo "Skipping cherry-pick as the release command is not valid."
52+ run : echo "Skipping cherry-pick as the release command is not valid."
4553 continue-on-error : true
4654
4755 - name : Setup Git
5058 git config --global user.email "bot@tyk.io"
5159 git config --global user.name "Tyk Bot"
5260
53- - name : Get PR details
61+ - name : Get PR base and merge SHAs
5462 id : pr_details
5563 if : steps.check_command.outputs.release_valid == 'true'
5664 env :
6573 - name : Clone repository and cherry-pick commit
6674 if : steps.check_command.outputs.release_valid == 'true'
6775 id : cherry_pick
76+ if : steps.check_command.outputs.release_valid == 'true'
6877 env :
6978 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7079 GITHUB_REPO : ${{ github.repository }}
@@ -77,15 +86,10 @@ jobs:
7786 # Clone the repository
7887 export FOLDER=$(echo $GITHUB_REPO | cut -d '/' -f2)
7988 rm -rf $FOLDER
80- git clone https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPO || true
89+ git clone https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPO
8190 cd $FOLDER
8291
83- # Reset and checkout default branch (master or main)
84- git reset --hard
85- git checkout $DEFAULT_BRANCH
86- git pull
8792 git checkout $GITHUB_BRANCH
88- git reset --hard
8993 git pull
9094
9195 if [ -n "$JIRA_ID" ]; then
@@ -103,7 +107,6 @@ jobs:
103107 # Create and checkout the new branch
104108 git checkout -b $BRANCH_NAME
105109
106- # Cherry-pick the commit
107110 MERGE_FAILED=0
108111 git cherry-pick -x $GITHUB_CHERRY_PICK_COMMIT || MERGE_FAILED=$?
109112
@@ -130,48 +133,34 @@ jobs:
130133 PR_URL=$(gh pr create --title "Merging to $GITHUB_BRANCH: $TITLE" --body "$MESSAGE" --repo $GITHUB_REPO --base $GITHUB_BRANCH --head $BRANCH_NAME)
131134 fi
132135
133- echo "$PR_URL"
134-
135- echo "Extract PR ID"
136- PR_ID="${PR_URL##*/}"
137-
138- echo "$PR_ID"
139-
140- echo "If no merge failure, auto-merge the PR"
141- if [ $MERGE_FAILED -eq 0 ]; then
142- gh pr merge --squash $PR_ID --auto --subject "Merging to $GITHUB_BRANCH: $TITLE" --body "$MESSAGE"
143- fi
144-
145- echo "Set outputs for use in the next step"
146- echo "PR_URL=${PR_URL}" >> $GITHUB_OUTPUT
147- echo "MERGE_FAILED=${MERGE_FAILED}" >> $GITHUB_OUTPUT
148-
149- - name : Comment on PR
136+ - name : Comment back on original PR
150137 if : steps.check_command.outputs.release_valid == 'true' && always()
151138 uses : actions/github-script@v6
152139 with :
153- github-token : ${{secrets.GITHUB_TOKEN}}
140+ github-token : ${{ secrets.GITHUB_TOKEN }}
154141 script : |
155142 const prUrl = '${{ steps.cherry_pick.outputs.PR_URL }}';
156143 const mergeFailed = '${{ steps.cherry_pick.outputs.MERGE_FAILED }}' === '1';
157144 let body;
158145
159146 if ('${{ job.status }}' === 'success') {
160147 if (mergeFailed) {
161- body = `⚠️ Cherry-pick operation completed with conflicts. A draft pull request has been created: ${prUrl}\n\nPlease resolve the conflicts manually.`;
148+ body = `⚠️ Cherry-pick completed with conflicts. A draft PR was created: ${prUrl}`;
149+ } else if (prUrl) {
150+ body = `✅ Cherry-pick successful. A PR was created and auto-merged (if allowed): ${prUrl}`;
162151 } else {
163- body = `✅ Cherry-pick operation completed successfully. New pull request created: ${prUrl} `;
152+ body = `ℹ️ Cherry-pick skipped: no changes needed in target branch. `;
164153 }
165154 } else {
166- body = '❌ Cherry-pick operation failed. Please check the action logs for more information .';
155+ body = '❌ Cherry-pick failed. Please check the workflow logs.';
167156 }
168157
169158 const owner = context.repo.owner || '${{ github.repository_owner }}';
170159 const repo = context.repo.repo || '${{ github.event.repository.name }}';
171160
172161 github.rest.issues.createComment({
173162 issue_number: ${{ steps.check_command.outputs.pr_number }},
174- owner: owner,
175- repo: repo,
163+ owner: context.repo. owner,
164+ repo: context.repo. repo,
176165 body: body
177166 });
0 commit comments