Skip to content

Commit

Permalink
Refactor branch merge into own reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
philnewm committed Nov 17, 2024
1 parent 1f89e68 commit f6bef5c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
35 changes: 9 additions & 26 deletions .github/workflows/initial_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,20 @@ jobs:


merge-to-main:
runs-on: ubuntu-latest
needs:
- verify-latest-release
- verify-repo-secrets
- verify-repo-vars

steps:
- name: ⬇️ Checkout ${{ vars.MAIN_BRANCH }}
uses: actions/checkout@v4
with:
ref: ${{ vars.MAIN_BRANCH }}
fetch-depth: 0

- name: 🔑 Set Bot Authentication
run: |
git config --global user.name "${{ env.GH_USER }}"
git config --global user.email "${{ env.GH_EMAIL }}"
- name: 🔀 Merge ${{ github.ref_name }} -> ${{ vars.MAIN_BRANCH }}
run: |
git pull origin ${{ github.ref_name }}
git merge --no-ff origin/${{ github.ref_name }} -m "[Automated] Merged ${{ github.ref_name }} -> ${{ vars.MAIN_BRANCH }}"
# TODO implement this using gh command
- name: 🔏 Push to protected main branch
uses: CasperWA/[email protected]
with:
token: ${{ env.GH_TOKEN }}
branch: ${{ vars.MAIN_BRANCH }}
tags: false
unprotect_reviews: false
uses: ynput/ops-repo-automation/.github/workflows/merge_branch.yml@refactor-release-workflow-structure
with:
repo: ${{ github.repository }}
checkout_branch: ${{ vars.MAIN_BRANCH }}
merge_from_branch: ${{ github.ref_name }}
secrets:
gh_token: ${{ secrets.token }}
gh_user: ${{ secrets.user }}
gh_email: ${{ secrets.email }}


build-from-main:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/merge_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: merge branch

on:
workflow_call:
inputs:
repo:
type: string
required: true
checkout_branch:
type: string
required: true
merge_from_branch:
type: string
required: true
secrets:
gh_token:
required: true
gh_user:
required: true
gh_email:
required: true

env:
GH_TOKEN: ${{ secrets.gh_token }}

jobs:
merge-to-main:
runs-on: ubuntu-latest

steps:
- name: ⬇️ Checkout ${{ inputs.checkout_branch }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.checkout_branch }}
fetch-depth: 0

- name: 🔑 Set Bot Authentication
run: |
git config --global user.name "${{ secrets.gh_user }}"
git config --global user.email "${{ secrets.gh_email }}"
- name: 🔀 Merge ${{ inputs.merge_from_branch }} -> ${{ inputs.checkout_branch }}
run: |
git pull origin ${{ inputs.merge_from_branch }}
git merge --no-ff origin/${{ inputs.merge_from_branch }} -m "[Automated] Merged ${{ inputs.merge_from_branch }} -> ${{ inputs.checkout_branch }}"
# TODO implement this using gh command
- name: 🔏 Push to protected ${{ inputs.checkout_branch }} branch
uses: CasperWA/[email protected]
with:
token: ${{ secrets.gh_token }}
branch: ${{ inputs.checkout_branch }}
tags: false
unprotect_reviews: false
3 changes: 2 additions & 1 deletion .github/workflows/release_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ jobs:
- name: 🔀 Merge ${{ github.ref_name }} -> ${{ vars.MAIN_BRANCH }}
run: |
git merge origin/${{ github.ref_name }} -m "[Automated] Merged ${{ github.ref_name }} -> ${{ vars.MAIN_BRANCH }}"
git pull origin ${{ github.ref_name }}
git merge --no-ff origin/${{ github.ref_name }} -m "[Automated] Merged ${{ github.ref_name }} -> ${{ vars.MAIN_BRANCH }}"
# TODO implement this using gh command
- name: 🔏 Push to protected ${{ vars.MAIN_BRANCH }} branch
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify_latest_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ on:

env:
GH_REPO : ${{ inputs.repo || github.repository }}
GH_TOKEN: ${{ secrets.gh_token || false }}
GH_TOKEN: ${{ secrets.gh_token }}

jobs:
verify-release:
Expand Down

0 comments on commit f6bef5c

Please sign in to comment.