This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
Sync upstream #125
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: Sync upstream | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 3 * * *' | |
env: | |
UPDATE_BRANCH: upstream-sync | |
REMOTE_URL: https://github.com/yogstation13/Yogstation | |
REMOTE_BRANCH: master | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
# Required because otherwise there are always changes detected when executing diff/rev-list | |
fetch-depth: 0 | |
# If no PAT is used the following error occurs on a push: | |
# refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission | |
token: ${GH_PAT:-$GITHUB_TOKEN} | |
- name: Init Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: Main workflow | |
id: main | |
run: | | |
echo "Adding remote template-repo" | |
git remote add template ${{ env.REMOTE_URL }} | |
echo "Fetching remote template repo" | |
git fetch template | |
echo "Deleting local branch that will contain the updates - if present" | |
git branch -D ${{ env.UPDATE_BRANCH }} || true | |
echo "Checking if the remote template repo has new commits" | |
git rev-list ..template/${{ env.REMOTE_BRANCH }} | |
if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then | |
echo "There are no commits new commits on the template repo" | |
echo "Deleting origin branch that contains the updates - if present" | |
git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true | |
echo "abort=1" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
echo "Found new commits on the template repo" | |
echo "Creating update branch" | |
git branch ${{ env.UPDATE_BRANCH }} template/${{ env.REMOTE_BRANCH }} | |
git branch --unset-upstream ${{ env.UPDATE_BRANCH }} | |
echo "Pushing update branch" | |
git push -f -u origin ${{ env.UPDATE_BRANCH }} | |
echo "Getting current branch" | |
current_branch=$(git branch --show-current) | |
echo "Current branch is $current_branch" | |
echo "current_branch=$current_branch" >> $GITHUB_OUTPUT | |
echo "abort=0" >> $GITHUB_OUTPUT | |
- name: pull-request | |
uses: repo-sync/pull-request@v2 | |
if: steps.main.outputs.abort == 0 | |
with: | |
github_token: ${GH_PAT:-$GITHUB_TOKEN} | |
source_branch: ${{ env.UPDATE_BRANCH }} | |
destination_branch: ${{ steps.main.outputs.current_branch }} | |
pr_title: "[Sync] Pull Upstream" | |
pr_body: "An automated PR to sync changes from the upstream" |