diff --git a/.github/workflows/merge-back.yaml b/.github/workflows/merge-back.yaml new file mode 100644 index 000000000..68cca7236 --- /dev/null +++ b/.github/workflows/merge-back.yaml @@ -0,0 +1,72 @@ +name: Merge back a reference to main +on: + workflow_call: + inputs: + sha: + required: true + type: string + secrets: + BOT_GITHUB_TOKEN: + required: true + +jobs: + merge-back: + name: Merge back the reference to main + runs-on: ubuntu-22.04 + + steps: + - name: Push branch and open a PR + uses: actions/github-script@v7.0.1 + env: + SHA: ${{ inputs.sha }} + with: + github-token: ${{ secrets.BOT_GITHUB_TOKEN }} + script: | + const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); + const sha = process.env.SHA; + const branch = `ref-merge/${sha}`; + const ref = `heads/${branch}`; + + await github.rest.git.createRef({ + owner, + repo, + ref, + sha, + }); + console.log(`Created branch ${branch} to ${sha}`); + + // Create a PR to merge the branch back to main + const pr = await github.rest.pulls.create({ + owner, + repo, + head: branch, + base: 'main', + title: `Automatic merge back to main`, + body: `This pull request was automatically created by the release workflow. It merges the release branch back to main.`, + maintainer_can_modify: true, + }); + console.log(`Created pull request #${pr.data.number} to merge the release branch back to main`); + console.log(`PR URL: ${pr.data.html_url}`); + + // Add the `T-Task` label to the PR + await github.rest.issues.addLabels({ + owner, + repo, + issue_number: pr.data.number, + labels: ['T-Task'], + }); + + // Enable auto-merge on the PR + await github.graphql( + ` + mutation AutoMerge($id: ID!) { + enablePullRequestAutoMerge(input: { + pullRequestId: $id, + mergeMethod: MERGE, + }) { + clientMutationId + } + } + `, + { id: pr.data.node_id }, + ); diff --git a/.github/workflows/release-branch.yaml b/.github/workflows/release-branch.yaml index 81be0401d..8874eccc3 100644 --- a/.github/workflows/release-branch.yaml +++ b/.github/workflows/release-branch.yaml @@ -73,6 +73,14 @@ jobs: secrets: BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + merge-back: + uses: ./.github/workflows/merge-back.yaml + needs: [tag] + with: + sha: ${{ needs.tag.outputs.sha }} + secrets: + BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + branch: name: Create a new release branch runs-on: ubuntu-22.04 @@ -103,20 +111,3 @@ jobs: sha, }); console.log(`Created branch ${branch} from ${sha}`); - - - name: Checkout the code - uses: actions/checkout@v4.2.2 - with: - ref: "release/v${{ needs.compute-version.outputs.short }}" - - - name: Open a pull request to merge the branch into main - env: - VERSION: ${{ needs.compute-version.outputs.short }} - GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} - run: | - gh pr create \ - --title "Release branch $VERSION" \ - --body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \ - --base main \ - --head "release/v$VERSION" \ - --label "T-Task" diff --git a/.github/workflows/release-bump.yaml b/.github/workflows/release-bump.yaml index 508b262c8..fb6da0a39 100644 --- a/.github/workflows/release-bump.yaml +++ b/.github/workflows/release-bump.yaml @@ -42,7 +42,7 @@ jobs: - name: Compute the new minor RC id: next env: - BUMP: ${{ github.event.inputs.rc && 'prerelease' || 'patch' }} + BUMP: ${{ inputs.rc && 'prerelease' || 'patch' }} VERSION: ${{ steps.current.outputs.version }} run: echo "version=$(npx --yes semver@7.5.4 -i "$BUMP" --preid rc "$VERSION")" >> "$GITHUB_OUTPUT" @@ -54,6 +54,15 @@ jobs: secrets: BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + merge-back: + uses: ./.github/workflows/merge-back.yaml + needs: [tag] + if: inputs.merge-back + with: + sha: ${{ needs.tag.outputs.sha }} + secrets: + BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + update-branch: name: Update the release branch runs-on: ubuntu-22.04 @@ -83,21 +92,3 @@ jobs: sha, }); console.log(`Updated branch ${branch} to ${sha}`); - - - name: Checkout the code - uses: actions/checkout@v4.2.2 - with: - ref: "${{ github.ref_name }}" - - - name: Open a pull request to merge the release branch back to main - if: github.event.inputs.merge-back - env: - VERSION: ${{ needs.compute-version.outputs.version }} - GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} - run: | - gh pr create \ - --title "Release branch $VERSION" \ - --body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \ - --base main \ - --head "$GITHUB_REF_NAME" \ - --label "T-Task"