Skip to content

Release: Merge Forward #10

Release: Merge Forward

Release: Merge Forward #10

name: "Release: Merge Forward"
on:
workflow_dispatch:
inputs:
forward-branch:
description: 'Name of the branch to merge into (e.g. release/T25.adamwarlock, master)'
default: release/T25.name
required: true
jobs:
create-branch:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.create-branch.outputs.skip }}
steps:
- name: Print input vars to summary
run: |
echo "### Debugging Inputs" >> $GITHUB_STEP_SUMMARY
echo "- forward-branch: \`${{ github.event.inputs.forward-branch }}\`" >> $GITHUB_STEP_SUMMARY
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.forward-branch }}
fetch-depth: 0
- name: Set up Git configuration
run: |
git config --global user.email "actions@github.com"
git config --global user.name "github-actions"
- name: Create and push release branch
id: create-branch
run: |
forwardBranch="${{ github.event.inputs.forward-branch }}"
if git ls-remote --exit-code --heads origin "$forwardBranch"; then
echo "skip=0" >> $GITHUB_OUTPUT
git checkout "$forwardBranch"
else
echo "## Pull Request" >> $GITHUB_STEP_SUMMARY
echo "Branch $forwardBranch does not exist; no need to create a PR." >> $GITHUB_STEP_SUMMARY
# Create and push the branch so that subsequent steps can use it.
git checkout "${{ github.ref_name }}"
git checkout -b "$forwardBranch"
git push origin "$forwardBranch"
echo "skip=1" >> $GITHUB_OUTPUT
fi
create-pull-request:
needs: create-branch
runs-on: ubuntu-latest
# Run only if the branch already existed (skip==0)
if: ${{ needs.create-branch.outputs.skip == '0' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Git configuration
run: |
git config --global user.email "actions@github.com"
git config --global user.name "github-actions"
- name: create new branch from forward branch and merge ref branch.
run: |
forwardBranch="${{ github.event.inputs.forward-branch }}"
HEAD_BRANCH="task/merge-forward-${{ github.ref_name }}-to-$forwardBranch"
git checkout "$forwardBranch"
git checkout -b "$HEAD_BRANCH"
git merge --no-ff "${{ github.ref_name }}"
git push origin "$HEAD_BRANCH"
- name: Create Pull Request using GitHub CLI
id: create_pr
env:
# Use GITHUB_TOKEN so that gh automatically authenticates.
GITHUB_TOKEN: ${{ secrets.GHA_BOT_TOKEN_MANAGER }}
run: |
echo "Creating PR using gh CLI..."
# Define the head branch name for the PR.
HEAD_BRANCH="task/merge-forward-${{ github.ref_name }}-to-${{ github.event.inputs.forward-branch }}"
# Create the PR and capture JSON output.
PR_URL=$(gh pr create \
--base "${{ github.event.inputs.forward-branch }}" \
--head "$HEAD_BRANCH" \
--title "[BOT] Merge forward from '${{ github.ref_name }}' to '${{ github.event.inputs.forward-branch }}'" \
--body "This is an automated PR created by ${{ github.actor }}. It was generated by [this GitHub Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) \\n [skip-changelog] [skip-lint] [skip-phpcs]" \
--assignee "${{ github.actor }}" \
--label "automation")
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
- name: Check outputs
run: |
echo "## Pull Request" >> $GITHUB_STEP_SUMMARY
echo "* URL - [${{ steps.create_pr.outputs.pr_url }}](${{ steps.create_pr.outputs.pr_url }})" >> $GITHUB_STEP_SUMMARY