Skip to content

merge_repo

merge_repo #78

Workflow file for this run

# This is a basic workflow to help you get started with Actions
name: Merge
on:
repository_dispatch:
types: [merge_repo]
jobs:
merge-lfs:
name: "Merge LFS data (${{ github.event.client_payload.repo }})"
if: github.event.client_payload.job == 'merge-v2'
runs-on: ubuntu-latest
# https://github.com/peaceiris/actions-gh-pages/tree/61cf177907e9ac9e79986e64f4e667fbfa975c04#:~:text=If%20the%20action%20fails%20to%20push%20the%20commit%20or%20tag%20with%20the%20following%20error%3A
# GitHub gives a 403, explicitly allow write permissions.
permissions:
contents: write
env:
SRC_REPO: "${{ github.event.client_payload.repo }}"
SRC_BRANCH: "${{ github.event.client_payload.branch }}"
DST_PATH: "${{ github.event.client_payload.path }}"
steps:
- name: Checkout source repository
uses: actions/checkout@v3
with:
repository: 'genoswitch/${{ github.event.client_payload.repo }}'
lfs: true
# Fetch all history for all tags and branches
fetch-depth: 0
# Use HTTPS - https://github.com/git-lfs/git-lfs/issues/3041
- name: Add merge repository as remote
run: git remote add merge https://github.com/${{ github.repository }}
# https://arwedus.wordpress.com/2021/09/09/avoid-missing-git-lfs-files-on-subtree-merge/
# https://github.com/git-lfs/git-lfs/issues/854
# In source repository, push LFS data to the 'merge' (this) repository.
- name: Upload LFS Data from source repo to merge (this) repo
run: git lfs push merge $SRC_BRANCH --all
merge:
name: "Merge (${{ github.event.client_payload.repo }})"
if: github.event.client_payload.job == 'merge-v2'
runs-on: ubuntu-latest
needs: [merge-lfs]
# https://github.com/peaceiris/actions-gh-pages/tree/61cf177907e9ac9e79986e64f4e667fbfa975c04#:~:text=If%20the%20action%20fails%20to%20push%20the%20commit%20or%20tag%20with%20the%20following%20error%3A
# GitHub gives a 403, explicitly allow write permissions.
permissions:
contents: write
env:
SRC_REPO: "${{ github.event.client_payload.repo }}"
SRC_BRANCH: "${{ github.event.client_payload.branch }}"
DST_PATH: "${{ github.event.client_payload.path }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Fetch all history for all tags and branches
fetch-depth: 0
# Fetch source repo for commit info when we create the commit message
- name: Add remote for source repository
run: git remote add -f source https://github.com/genoswitch/$SRC_REPO
- name: Fetch source repository
run: git fetch source
- name: "Set git committer information"
# Don't identify as GitHub actions as this is intended for GitLab
run: git config --global user.name "genoswitch-ci" && git config --global user.email genoswitch-ci@jcx.ovh
# - name: Merge (without committing) changes from the source repository
# run: git merge -s ours --allow-unrelated-histories --no-commit source/$SRC_BRANCH
# - name: Read the source repository into a subdirectory
# run: git read-tree --prefix=$SRC_REPO -u source/$SRC_BRANCH
# # Alternate method to avoid error from git read-tree command
# # > error: Entry '{file}' overlaps with '{file}'. Cannot bind.
# # https://www.congruityservice.com/blog/fix-git-subtree-merge-wrong-directory-cannot-bind
# - name: Merge (without committing) changes from the source repository
# run: git pull -s subtree -Xsubtree=$DST_PATH source $SRC_BRANCH --no-rebase --no-commit --allow-unrelated-histories
- name: Construct the commit message
run: ./.github/workflows/commit-message-env.sh
- name: Merge changes from source repository using git subtree
run: git subtree pull --prefix $DST_PATH --message "$ACTION_COMMIT_MSG" https://github.com/genoswitch/$SRC_REPO $SRC_BRANCH
- name: Reconstruct root .gitmodules
run: ./.github/workflows/reconstruct-root-gitmodules.sh
- name: Stage .gitmodules
run: git add .gitmodules
- name: Construct the commit message
run: ./.github/workflows/commit-submodule-message-env.sh
- name: Commit the changes
run: git commit -m "$ACTION_COMMIT_MSG" || echo "Nothing to do."
- name: Push the changes
run: git push