Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-merge

GitHub Action

Sync and merge upstream repository with your current repository

v1.0.0.b

Sync and merge upstream repository with your current repository

git-merge

Sync and merge upstream repository with your current repository

Syncs and merges your current repository with the upstream repository. Fork of https://github.com/mheene/sync-upstream-repo

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Sync and merge upstream repository with your current repository

uses: dabreadman/[email protected]

Learn more about this action in dabreadman/sync-upstream-repo

Choose a version

Sync Upstream Repo Fork

This is a Github Action used to merge changes from remote.

This is forked from mheene, with me adding authentication using GitHub Token and downstream branch options due to the default branch naming changes.

Use case

  • Perserve a repo while keeping up-to-date (rather than to clone it).
  • Have a branch in sync with upstream, and pull changes into dev branch.

Usage

Example github action here:

name: Sync Upstream

env:
  # Required, URL to upstream (fork base)
  UPSTREAM_URL: "https://github.com/dabreadman/go-web-proxy.git"
  # Optional, defaults to main
  UPSTREAM_BRANCH: "main"
  # Optional, defaults to UPSTREAM_BRANCH
  DOWNSTREAM_BRANCH: ""
  # Optional merge arguments
  MERGE_ARGS: ""
  # Optional push arguments
  PUSH_ARGS: ""

# This runs every day on 1801 UTC
on:
  schedule:
    - cron: '1 18 * * *'
  # Allows manual workflow run (must in default branch to work)
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: GitHub Sync to Upstream Repository
        uses: dabreadman/[email protected]
        with: 
          upstream_repo: ${{ env.UPSTREAM_URL }}
          upstream_branch: ${{ env.UPSTREAM_BRANCH }}
          downstream_branch: ${{ env.DOWNSTREAM_BRANCH }}
          token: ${{ secrets.GITHUB_TOKEN }}
          merge_args: ${{ env.MERGE_ARGS }}
          push_args: ${{ env.PUSH_ARGS }}

This action syncs your repo (merge changes from remote) at branch main with the upstream repo https://github.com/dabreadman/go-web-proxy.git every day on 1801 UTC.
Do note GitHub Action scheduled workflow usually face delay as it is pushed onto a queue, the delay is usually within 1 hour long.

Development

In action.yml, we define inputs.
We then pass these arguments into Dockerfile, which then passed onto entrypoint.sh.

entrypoint.sh does the heavy-lifting,

  • Set up variables.
  • Set up git config.
  • Clone downstream repository.
  • Fetch upstream repository.
  • Attempt merge if behind, and push to downstream.