Sync to Template #3
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
# Credit : https://github.com/solvaholic/template | |
name: Sync to Template | |
on: | |
schedule: | |
- cron: "17 5 * * 5" | |
workflow_dispatch: | |
env: | |
BASE_BRANCH: main | |
HEAD_BRANCH: chore/sync-to-template | |
GIT_AUTHOR_NAME: ${{ github.repository_owner }} | |
GIT_AUTHOR_EMAIL: ${{ github.repository_owner }}@users.noreply.github.com | |
REPO_TEMPLATE: jaARke/discord-lambda-py | |
THIS_REPO: ${{ github.repository }} | |
jobs: | |
sync-from-template: | |
if: github.repository != 'jaARke/discord-lambda-py' | |
name: Sync changes from jaARke/discord-lambda-py | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- name: Check out template repository | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ env.REPO_TEMPLATE }} | |
token: ${{ github.token }} | |
path: ${{ env.REPO_TEMPLATE }} | |
- name: Check out ${{ github.repository }} | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.repository }} | |
token: ${{ github.token }} | |
path: ${{ github.repository }} | |
- name: Create branch in ${{ env.THIS_REPO }} | |
run: | | |
git -C "${THIS_REPO}" fetch origin "${HEAD_BRANCH}" || true | |
git -C "${THIS_REPO}" branch -a | |
git -C "${THIS_REPO}" checkout -B "${HEAD_BRANCH}" \ | |
"remotes/origin/${HEAD_BRANCH}" || \ | |
git -C "${THIS_REPO}" checkout -b "${HEAD_BRANCH}" | |
- name: Copy template contents | |
run: | | |
_files="$(find ${REPO_TEMPLATE} \ | |
! -path "*/.git/*" \ | |
! -path "*/.github/workflows/*" \ | |
! -name ".gitignore" \ | |
! -name "README.md" \ | |
! -name "LICENSE" \ | |
! -name "requirements.txt" \ | |
! -name "test_command.py" \ | |
! -name ".env_sample" \ | |
-type f \ | |
-print)" | |
for _file in ${_files}; do | |
_src="${_file}" | |
_dst="${THIS_REPO}/${_file#${REPO_TEMPLATE}/}" | |
_dst="${_dst%/*}/" | |
mkdir -p "${_dst}" | |
echo "INFO: Copy '${_src}' to '${_dst}'." | |
cp "${_src}" "${_dst}" | |
done | |
git -C "${THIS_REPO}" diff | |
- name: Commit changes, if any | |
run: | | |
git -C ${THIS_REPO} config user.name "${GIT_AUTHOR_NAME}" | |
git -C ${THIS_REPO} config \ | |
user.email "${GIT_AUTHOR_EMAIL}" | |
git -C ${THIS_REPO} add . | |
git -C ${THIS_REPO} commit \ | |
-m "Sync from template@${{ github.sha }}" | |
- name: Push topic branch | |
run: git -C ${THIS_REPO} push -u origin "${HEAD_BRANCH}" | |
- name: Create pull request | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
GITHUB_USER: ${{ github.actor }} | |
run: | | |
pushd ${THIS_REPO} | |
hub pull-request \ | |
-b "${BASE_BRANCH}" \ | |
-h "${HEAD_BRANCH}" \ | |
--no-edit \ | |
-m "Pull updates from ${REPO_TEMPLATE}" \ | |
-m "Pull updates from ${REPO_TEMPLATE}" | |
popd |