|
| 1 | +name: draft_release_hotfix_pr |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "release/**" |
| 7 | + - "hotfix/**" |
| 8 | + |
| 9 | +env: |
| 10 | + BRANCH_MAIN: main |
| 11 | + BRANCH_DEVELOP: develop |
| 12 | + TAG_PREFIX: v |
| 13 | + |
| 14 | +jobs: |
| 15 | + create_draft_pr: |
| 16 | + name: Create a draft PR for release/hotfix |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + # only create draft pull requests on pushing to branches 'release/' or 'hotfix/' |
| 21 | + if: (startsWith(github.head_ref, 'release/') || startsWith(github.head_ref, 'hotfix/')) |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Set GitHub token |
| 25 | + run: | |
| 26 | + echo "GH_TOKEN=${{ secrets.GH_TOKEN }}" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v3 |
| 30 | + with: |
| 31 | + ref: ${{ github.head_ref }} |
| 32 | + token: ${{ env.GH_TOKEN }} |
| 33 | + # needed by "gh pr create" |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Set environment variables for publishing release |
| 37 | + if: startsWith(github.head_ref, 'release/') |
| 38 | + run: | |
| 39 | + BRANCH_NAME="${{ github.head_ref }}" |
| 40 | + VERSION=${BRANCH_NAME#release/} |
| 41 | + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV |
| 42 | + echo "RELEASE_TYPE=release" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + - name: Set environment variables for publishing hotfix |
| 45 | + if: startsWith(github.head_ref, 'hotfix/') |
| 46 | + run: | |
| 47 | + BRANCH_NAME="${{ github.head_ref }}" |
| 48 | + VERSION=${BRANCH_NAME#hotfix/} |
| 49 | + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV |
| 50 | + echo "RELEASE_TYPE=hotfix" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Check whether pre-release-version |
| 53 | + if: contains(env.RELEASE_VERSION, 'alpha') || contains(env.RELEASE_VERSION, 'beta') || contains(env.RELEASE_VERSION, 'rc') |
| 54 | + run: | |
| 55 | + echo "PRE_RELEASE=true" >> $GITHUB_ENV |
| 56 | +
|
| 57 | + - name: Set PR title |
| 58 | + run: | |
| 59 | + RELEASE_TYPE=${{ env.RELEASE_TYPE }} |
| 60 | + PR_PREFIX=${RELEASE_TYPE^} |
| 61 | + PR_TITLE="${PR_PREFIX} ${{ env.TAG_PREFIX }}${{ env.RELEASE_VERSION }}" |
| 62 | + echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV |
| 63 | +
|
| 64 | + - name: Create PR '${{ env.PR_TITLE }}' |
| 65 | + env: |
| 66 | + PR_LABELS: "automated-pr,${{ env.RELEASE_TYPE}}-pr" |
| 67 | + run: | |
| 68 | + LABELS=${{ env.PR_LABELS }} |
| 69 | + for LABEL in $(echo $LABELS | sed "s/,/ /g"); do gh label create $LABEL --force; done |
| 70 | + [[ ${PRE_RELEASE:false} == "true" ]] && gh label create 'pre-release' --force |
| 71 | +
|
| 72 | + PR_BODY=$(git log ${{ env.BRANCH_MAIN }}..${{ github.head_ref }} --pretty=format:%s) |
| 73 | +
|
| 74 | + gh pr create \ |
| 75 | + --draft \ |
| 76 | + --base ${{ env.BRANCH_MAIN }} \ |
| 77 | + --head ${{ github.head_ref }} \ |
| 78 | + --title "${{ env.PR_TITLE }}" \ |
| 79 | + --body "$PR_BODY" \ |
| 80 | + --label "${{ env.PR_LABELS }}" \ |
| 81 | + --fill |
0 commit comments