Create PR for beta branch (v4-beta -> v4) #8
This file contains hidden or 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: "Create PR for beta branch (v4-beta -> v4)" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| target_branch: | |
| description: "Target branch to merge into" | |
| required: true | |
| type: choice | |
| options: | |
| - v4 | |
| default: "v4" | |
| jobs: | |
| merge: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Generate Zen Artisan Token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.GH_ZEN_APP_ID }} | |
| private-key: ${{ secrets.GH_ZEN_APP_PRIVATE_KEY }} | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.target_branch }} | |
| token: ${{ steps.app-token.outputs.token }} | |
| fetch-depth: 1000 | |
| - name: Get GitHub App User ID | |
| id: get-user-id | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| echo \ | |
| "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" \ | |
| >> "$GITHUB_OUTPUT" | |
| - name: Merge ${{ github.event.inputs.target_branch }}-beta | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| USER_ID: ${{ steps.get-user-id.outputs.user-id }} | |
| APP_SLUG: ${{ steps.app-token.outputs.app-slug }} | |
| run: | | |
| set -x | |
| git config --global user.name "${APP_SLUG}[bot]" | |
| git config --global user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com>" | |
| DATE=$(date +%Y-%m-%d) | |
| MERGE_BRANCH="merge-${DATE}" | |
| git fetch origin | |
| git branch --remotes | |
| if git branch --remotes | grep -q "origin/${MERGE_BRANCH}"; then | |
| git checkout "${TARGET_BRANCH}" | |
| else | |
| git checkout "origin/${MERGE_BRANCH}" | |
| fi | |
| git checkout -b "${MERGE_BRANCH}" | |
| git merge \ | |
| --message "Merge ${TARGET_BRANCH}-beta into ${TARGET_BRANCH}" \ | |
| "origin/${TARGET_BRANCH}-beta" \ | |
| --strategy-option theirs | |
| # Replace all @v4-beta with @v4 in all action.yaml and all workflows | |
| { | |
| find . -type f -name "action.yaml" | |
| find .github/workflows -type f -name "*.yaml" | |
| } | | |
| xargs -L 1 \ | |
| sed -i "s/${TARGET_BRANCH}-beta/${TARGET_BRANCH}/g" | |
| git add . | |
| git commit -m "Merge ${TARGET_BRANCH}-beta into ${TARGET_BRANCH}" | |
| git push origin "${MERGE_BRANCH}" | |
| gh pr create \ | |
| --title "Merge ${TARGET_BRANCH}-beta into ${TARGET_BRANCH}" \ | |
| --base "${TARGET_BRANCH}" \ | |
| --head "${MERGE_BRANCH}" |