Skip to content

Instantly share code, notes, and snippets.

@seantrane
Last active October 31, 2023 15:01
Show Gist options
  • Save seantrane/d739179f19431d1e12017a83262cbc6f to your computer and use it in GitHub Desktop.
Save seantrane/d739179f19431d1e12017a83262cbc6f to your computer and use it in GitHub Desktop.
Upstream Sync, with Tags, without Forking

Upstream Sync, with Tags, without Forking

This approach uses the Upstream Sync GitHub Action to keep a remote/origin in sync with the remote/upstream repo.

  1. Create and navgiate to, directory for repo: mkdir <repo_name> && cd <repo_name>
  2. Initiate a new git repo: git init
  3. Add upstream remote config: git remote add --tags -t <branch> upstream [email protected]:<upstream_profile>/<upstream_repo>.git
  4. Add origin remote config: git remote add origin [email protected]:<origin_profile>/<origin_repo>.git
  5. Fetch upstream tags: git fetch --tags --prune upstream
  6. Pull upstream branch: git pull upstream
  7. Push origin branch: git push -u --tags origin <branch>
  8. Create Upstream Sync Action workflow file: touch .github/workflows/sync.yml
  9. Copy/Paste sync.yml file contents, making required changes.
  10. Commit changes: git add -A && git commit -m "ci: add upstream sync action workflow"
  11. Push changes to origin repo: git push origin <branch>
---
name: Upstream Sync
# https://github.com/marketplace/actions/upstream-sync
on:
schedule:
- cron: '0 7 * * *' # 7am UTC, everyday
push:
branches: [automation]
paths:
- .github/workflows/sync.yml
workflow_dispatch:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: false
jobs:
sync:
name: Sync to Upstream Repository
runs-on: ubuntu-latest
steps:
- name: Checkout target repo
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0
# optional: set the branch to checkout,
# sync action checks out your 'target_sync_branch' anyway
# ref: <branch>
# REQUIRED if your upstream repo is private (see wiki)
persist-credentials: false
- name: Sync to Upstream Repository
id: sync
uses: aormsby/[email protected]
with:
target_sync_branch: <branch>
target_repo_token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
target_branch_push_args: --force --tags
upstream_pull_args: --rebase=true --tags
upstream_sync_branch: <branch>
upstream_sync_repo: <upstream_profile>/<upstream_repo>
upstream_repo_access_token: ${{ secrets.GH_PAT_UPSTREAM || secrets.GH_PAT || secrets.GITHUB_TOKEN }}
git_config_user: ${{ github.actor }}
git_config_email: ${{ github.actor }}@users.noreply.github.com
git_config_pull_rebase: true
# Set test_mode true to run tests instead of the true action!!
test_mode: false
# Display messages based on the sync output var 'has_new_commits'
- name: New commits found
if: steps.sync.outputs.has_new_commits == 'true'
run: echo "New commits were found to sync."
- name: No new commits
if: steps.sync.outputs.has_new_commits == 'false'
run: echo "There were no new commits."
- name: Show value of 'has_new_commits'
run: echo ${{ steps.sync.outputs.has_new_commits }}
- name: Show value of 'has_new_commits'
run: echo ${{ steps.sync.outputs.has_new_commits }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment