Skip to content

Commit

Permalink
use rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangnew committed Feb 17, 2023
1 parent f319e34 commit 65060a2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 145 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Release
on:
push:
branches:
- master
- main

jobs:
release:
Expand All @@ -17,7 +17,7 @@ jobs:
release-version-minor: ${{ steps.release.outputs.release-version-minor }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- id: release
name: semantic-release
uses: ahmadnassri/action-semantic-release@v1
Expand All @@ -44,4 +44,5 @@ jobs:
repo: context.repo.repo
}
await github.git.deleteRef({ ...repo, ref: tag }).catch(() => {})
await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA })
await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA })
25 changes: 25 additions & 0 deletions .github/workflows/sync-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Sync Upstream

permissions: write-all # grant write permission

on:
schedule:
- cron: '0 0 * * 1' # scheduled for 00:00 every Monday
workflow_dispatch: # trigger manually

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

35 changes: 0 additions & 35 deletions .releaserc

This file was deleted.

98 changes: 21 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,65 @@
# 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.
# Sync Upstream

Sync 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)
- command is `git rebase upstream/branch`

To merge multiple branches, create multiple jobs.

To run action for another repository, create a [personal access token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
```yaml
- 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 }}
```
To sync multiple branches, create multiple jobs.

## Usage

### Set up for scheduled trigger

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

```yaml
name: Scheduled Merge Remote Action
name: Sync Upstream

permissions: write-all # grant write permission

on:
schedule:
- cron: '0 0 * * 1'
# scheduled for 00:00 every Monday
- cron: '0 0 * * 1' # scheduled for 00:00 every Monday
workflow_dispatch: # trigger manually

jobs:
merge-upstream:
sync-upstream:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: upstream # set the branch to merge to
fetch-depth: 0
- name: Merge Upstream
uses: exions/merge-upstream@v1
- name: Sync Upstream
uses: zhangnew/sync-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:
sync-upstream-another-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: another-branch # set the branch to merge to
fetch-depth: 0
- name: Merge Upstream
uses: exions/merge-upstream@v1
- name: Sync Upstream
uses: zhangnew/sync-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:
- [Triggering a workflow with events](https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#triggering-a-workflow-with-events)
- [Creating a composite run steps action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action)

## 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.

```yaml
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 }}
```
42 changes: 27 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
name: "Merge Upstream"
description: "Merge changes from the uppstream repo you had forked from."
author: "eXions"
name: "Sync Upstream"
description: "Sync changes from the uppstream repo you had forked from."
author: "zhangnew"
branding:
icon: git-merge
color: black
color: green

inputs:
username:
description: "User name - required for git commits"
default: "sync-upstream-bot"
useremail:
description: "User email - required for git commits"
default: "bot@github.com"
upstream:
description: 'Upstream repository owner/name. For example, exions/merge-upstream'
description: "Upstream repository owner/name. For example, zhangnew/sync-upstream"
default: "master"
required: true
upstream-branch:
description: 'Upstream branch to merge from. For example, master'
default: 'master'
description: "Upstream branch to merge from. For example, master"
default: "master"
required: true
branch:
description: 'Branch to merge to. For example, master'
default: 'master'
description: "Branch to merge to. For example, master"
default: "master"
required: true
token:
description: >
Personal access token (PAT) used to fetch the repository. The PAT is configured
with the local git config, which enables your scripts to run authenticated git
commands. The post-job step removes the PAT.
with the local git config, which enables your scripts to run authenticated git commands. The post-job step removes the PAT.
We recommend using a service account with the least permissions necessary.
Also when generating a new PAT, select the least scopes necessary.
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
default: ${{ github.token }}

runs:
using: "composite"
steps:
- run: |
steps:
- run: |
set -x
git remote add -f upstream "https://github.com/${{ inputs.upstream }}.git"
git remote -v
git branch --all
git config user.email "${{ inputs.useremail }}"
git config user.name "${{ inputs.username }}"
git config --list
git checkout ${{ inputs.branch }}
git merge --ff-only upstream/${{ inputs.upstream-branch }}
git push
git rebase upstream/${{ inputs.upstream-branch }}
git pull --rebase
git push
shell: bash
15 changes: 0 additions & 15 deletions package.json

This file was deleted.

0 comments on commit 65060a2

Please sign in to comment.