fix cor #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cherry-Pick PRs to Master | |
on: | |
pull_request: | |
types: | |
- closed | |
jobs: | |
get_labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Get Merged PR Labels. | |
id: merged_pr | |
run: | | |
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH") | |
ACCESS_TOKEN="${{ secrets.GITHUB_TOKEN }}" | |
LABELS=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" | jq -r '.labels[].name') | |
echo "Labels: $LABELS" | |
# Initialize an empty array to store the split parts | |
release_labels=() | |
# Use a while loop to split the LABELS | |
while IFS=" " read -r -a labels; do | |
for label in "${labels[@]}"; do | |
if [[ $label == release* ]]; then | |
release_labels+=("$label") | |
fi | |
done | |
done <<< "$LABELS" | |
# Print the split parts | |
for release_label in "${release_labels[@]}"; do | |
echo "12233 $release_label" | |
done | |
for TARGET_BRANCH in "${release_labels[@]}"; do | |
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 | |
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 | |
# for release_label in "${release_labels[@]}"; do | |
# # Fetch PR branch | |
# git fetch --all --prune | |
# git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER} | |
# git checkout pr-${PR_NUMBER} | |
# commit=$( git rev-parse HEAD ) | |
# remote=$(git remote -v) | |
# echo "fsfsf: $remote" | |
# git checkout -b pr-${PR_NUMBER}-cherry-pick-${release_label} origin/$release_label | |
# # Cherry-pick the PR commit(s) | |
# # git cherry-pick pr-${PR_NUMBER} | |
# # Create a new pull request | |
# # gh pr create --base ${release_label} --head pr-${PR_NUMBER} --title "Cherry-pick PR ${PR_NUMBER}" --body "Cherry-picking changes from PR ${PR_NUMBER}." | |
# done | |