Disable old auto-pr #8
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: Precise Auto PR | |
on: | |
push: | |
branches: | |
- 'release/*' | |
jobs: | |
auto-pr: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.AUTOPR_SECRET }} | |
- name: set git config | |
run: | | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
git config --global user.name "${GITHUB_ACTOR}" | |
git config --global advice.mergeConflict false | |
git config --global --add safe.directory "${{ github.workspace }}" | |
git config -l | |
- name: check branch names | |
id: branch_info | |
run: | | |
RELEASE_VERSIONS=$(git branch -r | grep 'release/' | cut -d '/' -f 3 | sort -V) | |
CURRENT_VERSION=$(echo $GITHUB_REF | rev | cut -d '/' -f 1 | rev) | |
CURRENT_BRANCH="release/$CURRENT_VERSION" | |
ME_AND_MY_NEXT=$(echo "$RELEASE_VERSIONS" | grep -w $CURRENT_VERSION -A 1) | |
NUM=$(echo "$ME_AND_MY_NEXT" | wc -l) | |
if (( NUM > 1 )); then | |
NEXT_VERSION=$(echo "$ME_AND_MY_NEXT" | tail -n 1) | |
NEXT_BRANCH="release/$NEXT_VERSION" | |
set -x | |
else | |
echo "No more higher release versions, will merge to main" | |
NEXT_VERSION="main" | |
NEXT_BRANCH="main" | |
set -x | |
fi | |
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT | |
echo "NEXT_BRANCH=$NEXT_BRANCH" >> $GITHUB_OUTPUT | |
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
echo "CURRENT_BRANCH=$CURRENT_BRANCH" >> $GITHUB_OUTPUT | |
- name: create pr branch | |
id: create_branch | |
run: | | |
PRBRANCH=auto-pr-${{github.event.after}}-${{steps.branch_info.outputs.NEXT_VERSION}} | |
echo "PRBRANCH=$PRBRANCH" >> $GITHUB_OUTPUT | |
- name: Merge release branch into ${{steps.branch_info.outputs.NEXT_BRANCH}} | |
id: merge-changes | |
run: | | |
set -x | |
git checkout ${{steps.branch_info.outputs.NEXT_BRANCH}} | |
git checkout -b ${{steps.create_branch.outputs.PRBRANCH}} | |
TITLE=$(git log --format="| %s" ${{ github.event.commits[0].id }}~..${{ github.event.after }} | xargs) | |
echo "TITLE=$TITLE" >> $GITHUB_OUTPUT | |
echo "MESSAGE<<__EOF" >> $GITHUB_OUTPUT | |
git log --format="> %B" ${{ github.event.commits[0].id }}~..${{ github.event.after }} >> $GITHUB_OUTPUT | |
echo "__EOF" >> $GITHUB_OUTPUT | |
REVS=$(git rev-list --reverse ${{ github.event.commits[0].id }}~..${{ github.event.after }} ) | |
for rev in "$REVS"; do | |
if ! git cherry-pick -X theirs ${rev} ; then | |
echo "merge=false" >> $GITHUB_OUTPUT | |
exit 0; | |
fi | |
done | |
git push -d origin ${{steps.create_branch.outputs.PRBRANCH}} || true | |
git push -u origin ${{steps.create_branch.outputs.PRBRANCH}} | |
echo "merge=true" >> $GITHUB_OUTPUT | |
- uses: actions/github-script@v7 | |
name: Open pick PR to ${{steps.branch_info.outputs.NEXT_BRANCH}} | |
if: steps.merge-changes.outputs.merge == 'true' | |
with: | |
github-token: ${{ secrets.AUTOPR_SECRET }} | |
script: | | |
await github.rest.pulls.create({ | |
...context.repo, | |
title: `[Pick][${{steps.branch_info.outputs.CURRENT_VERSION}} to ${{steps.branch_info.outputs.NEXT_VERSION}}] ${{steps.merge-changes.outputs.TITLE}}`, | |
head: `${{steps.create_branch.outputs.PRBRANCH}}`, | |
base: `${{steps.branch_info.outputs.NEXT_BRANCH}}`, | |
body: `${{steps.merge-changes.outputs.MESSAGE}}\nGenerated by Auto PR, by cherry-pick related commits`, | |
}); | |
- uses: actions/github-script@v7 | |
name: Open merge PR to ${{steps.branch_info.outputs.NEXT_BRANCH}} | |
if: steps.merge-changes.outputs.merge == 'false' | |
with: | |
github-token: ${{ secrets.AUTOPR_SECRET }} | |
script: | | |
await github.rest.pulls.create({ | |
...context.repo, | |
title: `[Merge][${{steps.branch_info.outputs.CURRENT_VERSION}} to ${{steps.branch_info.outputs.NEXT_VERSION}}] ${{steps.merge-changes.outputs.TITLE}}`, | |
head: `${context.ref}`, | |
base: `${{steps.branch_info.outputs.NEXT_BRANCH}}`, | |
body: `${{steps.merge-changes.outputs.MESSAGE}}\nGenerated by Auto PR, using merge since cherry-pick failed`, | |
}); |