From 2da6fdd2eb3ba1d616007d17ba9b564e9087bd1b Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Thu, 26 Oct 2023 00:55:27 +0800 Subject: [PATCH] Auto PR --- .github/workflows/auto-pr.yml | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/auto-pr.yml diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml new file mode 100644 index 00000000..7fcf89a1 --- /dev/null +++ b/.github/workflows/auto-pr.yml @@ -0,0 +1,38 @@ +name: Auto PR + +on: + push: + branches: + - 'release/*' + +jobs: + auto-pr: + runs-on: ubuntu-latest + + env: + GH_TOKEN: ${{ github.token }} + + steps: + - uses: actions/checkout@v3 + + - name: Create Pull Request to the next higher release version + + run: | + git fetch + RELEASE_VERSIONS=$(git branch -r | grep 'release/' | cut -d '/' -f 3 | sort -V) + CURRENT_VERSION=$(echo $GITHUB_REF | rev | cut -d '/' -f 1 | rev) + 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) + set -x + gh pr create --base "release/$NEXT_VERSION" --head "release/$CURRENT_VERSION" \ + --title "Auto PR from release/$CURRENT_VERSION to release/$NEXT_VERSION" \ + --body 'Created by Github action' + else + echo "No more higher release versions, will merge to main" + set -x + gh pr create --base main --head "release/$CURRENT_VERSION" \ + --title "Auto PR from release/$CURRENT_VERSION to main \ + --body 'Created by Github action' + fi