Skip to content

Commit

Permalink
Add GHA workflow to sync fork with upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You authored and github-actions[bot] committed May 9, 2024
1 parent 407d1dd commit 1287827
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/sync-fork.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sync fork

on:
schedule:
- cron: "41 19 * * *"
workflow_dispatch:

jobs:
sync:
runs-on: ubuntu-latest

permissions:
contents: write

timeout-minutes: 5

steps:
- name: Checkout current fork HEAD
uses: actions/[email protected]
with:
fetch-depth: 0
show-progress: false

- name: Set up upstream git remote
run: |
upstream="$(gh repo view "${{ github.repository }}" --json parent --jq '.parent.owner.login + "/" + .parent.name')"
echo "upstream=$upstream"
git remote add upstream "https://github.com/$upstream.git"
git fetch upstream "${{ github.event.repository.default_branch }}"
env:
GH_TOKEN: ${{ github.token }}

- name: Determine number of missing commits from usptream
id: check-missing-commits
run: |
upstream_commit_count="$(git rev-list --count "$GITHUB_REF_NAME..upstream/${{ github.event.repository.default_branch }}")"
echo "commit-count=$upstream_commit_count" | tee -a "$GITHUB_OUTPUT"
- name: Rebase and push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git rebase --committer-date-is-author-date "upstream/${{ github.event.repository.default_branch }}"
git push --force
if: >-
fromJSON(steps.check-missing-commits.outputs.commit-count) > 0

0 comments on commit 1287827

Please sign in to comment.