Skip to content

Mashetty330 patch 2 #48

Mashetty330 patch 2

Mashetty330 patch 2 #48

Workflow file for this run

name: Cherry Pick PR
on:
pull_request:
types:
- closed
jobs:
cherry-pick:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Git committer identity
run: |
git config user.name "mashetty330"
git config user.email "[email protected]"
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install dependencies
run: npm install @actions/github
- name: Check if PR is merged and labeled
run: |
if [ "${{ github.event.pull_request.merged }}" == "true" ]; then
# Extract the version label
LABEL=$(node -e "console.log(require('@actions/github').context.payload.pull_request.labels.find(label => /^cherry-pick-release-[0-9]+\\.[0-9]+$/.test(label.name)).name)")
if [ "$LABEL" != "" ]; then
echo "PR is merged and labeled with $LABEL"
TARGET_BRANCH="release-$(echo $LABEL | cut -d'-' -f4-)"
echo "Target release branch: $TARGET_BRANCH"
# Log the LABEL value to the console
echo "LABEL: $LABEL"
git fetch --all --prune
echo "Target release branch exists: $TARGET_BRANCH"
git checkout master && git fetch --all && git reset --hard origin/master
git checkout -b cherry-pick-pr-"${{ github.event.pull_request.number }}" origin/$TARGET_BRANCH
#git pull origin $TARGET_BRANCH
#git checkout -b cherry-pick-pr-"${{ github.event.pull_request.number }}"
echo "checked out cherry pick pr branch"
echo "commit sha ${{ github.event.pull_request.head.sha }}"
git cherry-pick "${{ github.event.pull_request.head.sha }}"
echo "fetched commit"
# Handle any potential conflicts here if necessary
git push origin cherry-pick-pr-"${{ github.event.pull_request.number }}"
echo "pushed"
# Create a new pull request
curl -X POST "https://api.github.com/repos/${{ github.repository }}/pulls" \
-H "Authorization: token ${{ secrets.ACTION_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{
"title": "Cherry-pick to '$TARGET_BRANCH'",
"body": "This PR is a cherry-pick of the changes from #${{ github.event.pull_request.number }}",
"head": "cherry-pick-pr-${{ github.event.pull_request.number }}",
"base": "'$TARGET_BRANCH'"
}'
else
echo "PR is not labeled for cherry-pick"
fi
else
echo "PR is not merged"
fi
env:
GITHUB_TOKEN: ${{ secrets.ACTION_PAT }}