Skip to content

Update notebook

Update notebook #93

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 "const labels = require('@actions/github').context.payload.pull_request.labels;
const cherryPickReleaseLabels = labels.filter(label => /^cherry-pick-release-[0-9]+\.[0-9]+$/.test(label.name)).map(label => label.name);
if (cherryPickReleaseLabels.length > 0) {
cherryPickReleaseLabels.forEach(label => console.log(label));
} else {
console.log('None');
}")
if [ "$LABEL" != "None" ]; then
echo "PR is merged and labeled with $LABEL"
# Parse through each cherry-pick labels and raise PR accordingly
mapfile -t labels <<< "$(echo -e "$LABEL")"
for label in "${labels[@]}"
do
TARGET_BRANCH="release-$(echo $label | cut -d'-' -f4-)"
git fetch --all --prune
echo "Target release branch exists: $TARGET_BRANCH"
git checkout master
if [ "$(git rev-parse --is-shallow-repository)" == "true" ];then
git fetch --all --unshallow
else
git fetch --all
fi
git reset --hard origin/master
output=$(git log "${{ github.event.pull_request.merge_commit_sha }}"^.."${{ github.event.pull_request.merge_commit_sha }}" --format="%H")
commit_shas=$(echo "$output" | sed '1d' | tr '\n' ' ')
git checkout -b "$TARGET_BRANCH"-cherry-pick-pr-"${{ github.event.pull_request.number }}" origin/$TARGET_BRANCH
echo "Checked out cherry pick pr branch"
echo "These are the commits need cherry-pick : $commit_shas"
git cherry-pick $commit_shas || git cherry-pick --abort && continue
echo "Cherry-picked commits"
# Handle any potential conflicts here if necessary
git push origin "$TARGET_BRANCH"-cherry-pick-pr-"${{ github.event.pull_request.number }}"
echo "Pushed to the Cherry-pick branch"
# 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": "'$TARGET_BRANCH'-cherry-pick-pr-${{ github.event.pull_request.number }}",
"base": "'$TARGET_BRANCH'"
}'
done
echo "Cherry-pick PR raised successfully"
else
echo "PR is not labeled for cherry-pick"
fi
else
echo "PR is not merged"
fi
env:
GITHUB_TOKEN: ${{ secrets.ACTION_PAT }}