diff --git a/.github/workflows/create_release_branch.yml b/.github/workflows/create_release_branch.yml new file mode 100644 index 000000000..5fbaffe76 --- /dev/null +++ b/.github/workflows/create_release_branch.yml @@ -0,0 +1,94 @@ +name: Create Release Branch Workflow +on: + workflow_dispatch: + inputs: + version: + description: "Release version" + required: true + type: string + branch_name: + description: "Release branch name" + required: true + type: string + commit_sha: + description: "Optional commit SHA to start release branch from. By default, it will use the latest commit on the main branch." + required: false + type: string + +jobs: + create-release-branch: + runs-on: ubuntu-latest + steps: + + - name: Create GitHub App Token + uses: actions/create-github-app-token@v2 + id: app-token + with: + app-id: ${{ vars.MONGODB_KUBERNETES_APP_ID }} + private-key: ${{ secrets.MONGODB_KUBERNETES_APP_PRIVATE_KEY }} + + - name: Checkout repository (master) + if: ${{ github.event.inputs.commit_sha == '' }} + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + ref: ${{ github.head_ref }} + + - name: Checkout repository (commit SHA)) + if: ${{ github.event.inputs.commit_sha != '' }} + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + ref: ${{ github.event.inputs.commit_sha }} + + - name: Get GitHub App User ID + id: get-user-id + run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + + - name: Set up Git + id: setup-git + run: | + git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' + git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' + + - name: Check if release branch already exists + id: check-branch + run: | + if git show-ref --verify --quiet refs/heads/${{ github.event.inputs.branch_name }}; then + echo "Release branch ${{ github.event.inputs.branch_name }} already exists." + git checkout ${{ github.event.inputs.branch_name }} + else + echo "create_new_branch=true" >> $GITHUB_ENV + fi + + - name: Create release branch + id: create-branch + if: env.create_new_branch == 'true' + run: | + git checkout -b ${{ github.event.inputs.branch_name }} + git push --set-upstream origin ${{ github.event.inputs.branch_name }} + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + + - name: Replace version in release.json + id: replace-version + run: | + jq --arg version "${{ github.event.inputs.version }}" '.mongodbOperator=$version' release.json > tmp_release.json + mv tmp_release.json release.json + git add release.json + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.app-token.outputs.token }} + sign-commits: true + commit-message: Release version `${{ github.event.inputs.version }}` + title: Release version `${{ github.event.inputs.version }}` + signoff: false + delete-branch: false + branch: bump-${{ github.event.inputs.version }}-version + draft: true