We use submodules for some of our projects to allow for a single soure of truth. Keeping our main project up to date with these changes can be quite painful. This action runs on push to a repo's master branch, and updates the submodule in another repo automatically and raises a pull request
Add the following to .github/workflows/update-submodule.yml:
name: Update Submodule
on:
push:
branches:
- master
jobs:
build:
name: Update Submodule
runs-on: ubuntu-latest
steps:
- uses: nexmo/github-actions/submodule-auto-pr@master
env:
GH_ADMIN_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
PR_ACTIVE_BRANCH: master
PR_BRANCH_NAME: automated-oas-update
PR_SUBMODULE_PATH: _open_api/api_specs
PR_TARGET_BRANCH: master
PR_TARGET_ORG: nexmo
PR_TARGET_REPO: nexmo-developer
PR_TITLE: API Specification UpdateGH_ADMIN_TOKEN- a custom GitHub token to use to make API requests. The defaultGITHUB_TOKENprovided is scoped to the current repo, and we want to change other reposPR_TARGET_ORG- the name of the organization that owns the repo that a PR will be created onPR_TARGET_REPO- the name of the repo that a PR will be created onPR_SUBMODULE_PATH- the path to the submodule that needs updatingPR_BRANCH_NAME- the name of the branch to create when updating submodulesPR_TITLE- the title to use for the PR. This will also be your commit messagePR_TARGET_BRANCH- the branch that we want to merge our PR in toPR_ACTIVE_BRANCH- check if the push was to this branch before continuing (usuallymaster)
- Someone commits to the default branch in a repo that uses this action
- Create
PR_BRANCH_NAMEif it does not already exist - Create a commit with the new submodule SHA
- If
PR_BRANCH_NAMEis created, a new commit is added on top of the latest commit on the default branch - If
PR_BRANCH_NAMEonly contains a single commit, a new commit will be force pushed with the new submodule commit - If there is more than 1 commit, the new submodule will be added as a new commit to the existing tree
- If
- Create a PR named
PR_TITLEif there is not currently a PR open forPR_BRANCH_NAME - Assign the PR to the person that merged the commit to the default branch