Merge (ff only) #1
This file contains 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: Merge (ff only) | |
on: | |
workflow_dispatch: | |
workflow_call: | |
inputs: | |
source-repo: | |
required: true | |
type: string | |
description: Source repo path in the format [REPO_OWNER]/[REPO_NAME] | |
target-repo: | |
required: true | |
type: string | |
description: Target repo path in the format [REPO_OWNER]/[REPO_NAME] | |
source-branch: | |
required: true | |
type: string | |
description: Source branch from [SOURCE_REPO] that you want merged into [TARGET_BRANCH] from [TARGET_REPO] | |
target-branch: | |
required: true | |
type: string | |
description: Target branch to merge [SOURCE_BRANCH] from [SOURCE_REPO] into. | |
env-name: | |
required: true | |
type: string | |
description: Github environment name that your github token secret is in | |
secrets: | |
github-token: | |
required: true | |
jobs: | |
Promote: | |
environment: ${{ inputs.env-name }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ inputs.source-repo }} | |
ref: ${{ inputs.source-branch }} | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Merge source-branch into target-branch | |
env: | |
# gh needs this env var set with the exact name GH_TOKEN | |
GH_TOKEN: ${{ secrets.github-token }} | |
SOURCE_BRANCH: ${{ inputs.source-branch }} | |
TARGET_BRANCH: ${{ inputs.target-branch }} | |
TARGET_REPO: ${{ inputs.target-repo }} | |
shell: bash | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "auto-promote" | |
git config --global --add --bool push.autoSetupRemote true | |
git remote add target-repo "https://[email protected]/$TARGET_REPO.git" | |
git fetch -q target-repo | |
git branch --track "$TARGET_BRANCH-target-repo" remotes/target-repo/$TARGET_BRANCH | |
echo "After tracking target branch external" | |
git switch -q "$TARGET_BRANCH-target-repo" | |
git merge $SOURCE_BRANCH --ff-only | |
git push -q target-repo HEAD:$TARGET_BRANCH | |