forked from exions/merge-upstream
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "[email protected]" | ||
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 |
This file was deleted.
Oops, something went wrong.