Git Product home page Git Product logo

merge-upstream's Introduction

Merge Upstream

Merge changes from an upstream repository branch into a current repository branch. For example, updating changes from the repository that was forked from.

Current limitations:

  • only merge only selected branch
  • only work with public upstream Github repository
  • merge fast forward only (--ff-only)

To merge multiple branches, create multiple jobs.

To run action for another repository, create a personal access token (PAT)

      - name: Merge Upstream
        uses: exions/merge-upstream@v1
        with:
          upstream: ${{ github.event.inputs.upstream }}
          upstream-branch: ${{ github.event.inputs.upstream-branch }}
          branch: ${{ github.event.inputs.branch }}
          token: ${{ secrets.TOKEN }}

Usage

Set up for scheduled trigger

name: Scheduled Merge Remote Action
on: 
  schedule:
    - cron: '0 0 * * 1'
    # scheduled for 00:00 every Monday

jobs:
  merge-upstream:
    runs-on: ubuntu-latest
    steps: 
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: upstream             # set the branch to merge to
          fetch-depth: 0 
      - name: Merge Upstream
        uses: exions/merge-upstream@v1
        with:
          upstream: owner/repo      # set the upstream repo
          upstream-branch: master   # set the upstream branch to merge from
          branch: upstream          # set the branch to merge to

  # set up another job to merge another branch
  merge-upstream-another-branch:
    runs-on: ubuntu-latest
    steps: 
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: another-branch       # set the branch to merge to
          fetch-depth: 0 
      - name: Merge Upstream
        uses: exions/merge-upstream@v1
        with:
          upstream: owner/repo              # set the upstream repo
          upstream-branch: another-branch   # set the upstream branch to merge from
          branch: another-branch            # set the branch to merge to

Reference:

How to run this action manually

This action can trigger manually as needed.

  1. Go to Actions at the top of your Github repository
  2. Click on Manual Merge Upstream Action (or other name you have given) under All workflows
  3. You will see Run workflow, click on it
  4. Fill in the upstream repository and branch to merge from, and the branch to merge to (⚠️ double check all are correct)
  5. Click Run workflow
  6. Check your branch commit history

Set up for manual trigger

copy and commit this to .github/workflows/merge-upstream.yml in your default branch of your repository.

name: Manual Merge Remote Action
on: 
  workflow_dispatch:
    inputs:
      upstream:
        description: 'Upstream repository owner/name. Eg. exions/merge-upstream'
        required: true
        default: 'owner/name'       # set the upstream repo
      upstream:
        description: 'Upstream branch to merge from. Eg. master'
        required: true
        default: 'master'           # set the upstream branch to merge from
      branch:
        description: 'Branch to merge to'
        required: true
        default: 'upstream'         # set the branch to merge to

jobs:
  merge-upstream:
    runs-on: ubuntu-latest
    steps: 
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.branch }}
          fetch-depth: 0 
      - name: Merge Upstream
        uses: exions/merge-upstream@v1
        with:
          upstream: ${{ github.event.inputs.upstream }}
          upstream-branch: ${{ github.event.inputs.upstream-branch }}
          branch: ${{ github.event.inputs.branch }}
          token: ${{ secrets.TOKEN }}

merge-upstream's People

Contributors

lcenchew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

merge-upstream's Issues

Can't sync upstream when upstream change file in workflows folder

err:

To https://github.com/Fatpandac/RSSHub
 ! [remote rejected]   master -> master (refusing to allow a GitHub App to create or update workflow `.github/workflows/pr-deploy-route-test.yml` without `workflows` permission)
error: failed to push some refs to 'https://github.com/Fatpandac/RSSHub'

It’s also not solved after setup secrets.TOKEN .

action.yaml

Option to not fail if everything is up to date

It seems like most users (and the intent) of this action is to keep a repository up to date with upstream changes. Currently if the upstream merge fails because everything is already up to date, the action fails. That seems counter to the intended use of the action. It should succeed as no operations were required to get to the desired state.

Your branch is up to date with 'origin/main'.
Error: Process completed with exit code 128.

allow to merge from non-github and not fast-forward

solve

diff --git a/action.yml b/action.yml
index 24c1643..331f43e 100644
--- a/action.yml
+++ b/action.yml
@@ -9,12 +9,21 @@ inputs:
   upstream:
     description: 'Upstream repository owner/name. For example, exions/merge-upstream'
     required: true
+  email:
+    description: 'User email for git commits'
+    default: '[email protected]'
+  name:
+    description: 'User name for git commits'
+    default: 'Merge Upstream Action'
   upstream-branch:
     description: 'Upstream branch to merge from. For example, master'
     default: 'master'
   branch:
     description: 'Branch to merge to. For example, master'
     default: 'master'
+  repository:
+    description: 'Repository to merge from. For example, https://github.com/'
+    default: 'https://github.com/'
   token:
     description: >
       Personal access token (PAT) used to fetch the repository. The PAT is configured
@@ -27,13 +36,13 @@ inputs:
 
 runs:
   using: "composite"
-  steps: 
-    - run: | 
-        git remote add -f upstream "https://github.com/${{ inputs.upstream }}.git"
-        git remote -v
-        git branch --all
-        git config --list
-        git checkout ${{ inputs.branch }}
-        git merge --ff-only upstream/${{ inputs.upstream-branch }}
-        git push 
-      shell: bash
+  steps:
+    - run: |
+        set -eux
+        git checkout "${{ inputs.branch }}"
+        git remote add --fetch --track "${{ inputs.upstream-branch }}" upstream "${{ inputs.repository }}${{ inputs.upstream }}.git"
+        git config user.email "${{ inputs.email }}"
+        git config user.name "${{ inputs.name }}"
+        git merge "upstream/${{ inputs.upstream-branch }}"
+        git push
+      shell: sh

Not maintained - forked, fixed, and published new GitHub Action

Leaving this here for folks trying to use this extension. Thank you for making this action! Unfortunately, this action doesn't appear to be maintained.

I have forked this repo and updated and published an action at https://github.com/marketplace/actions/merge-from-upstream-repo

Adding this GitHub Action would always cause the action to fail because unrelated histories cannot fast forward merge.

As suggested in Issue #11 by @lcenchew, getting the username and email and changing the merge command solved the problem in the action. The action now allows unrelated histories.

I fixed the README instructions and simplified them.

error

[Error: .github#L1]
Invalid type for on

I am getting this error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.