Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: imba-tjd/rebase-upstream-action
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.3
Choose a base ref
...
head repository: imba-tjd/rebase-upstream-action
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 2 files changed
  • 4 contributors

Commits on Feb 20, 2021

  1. doc update

    imba-tjd committed Feb 20, 2021
    Copy the full SHA
    044d1f7 View commit details
  2. use set -ex

    imba-tjd committed Feb 20, 2021
    Copy the full SHA
    4997d09 View commit details

Commits on Feb 21, 2021

  1. Copy the full SHA
    54b4e25 View commit details

Commits on Mar 16, 2021

  1. Copy the full SHA
    6b74a3d View commit details
  2. doc update

    imba-tjd committed Mar 16, 2021
    Copy the full SHA
    3727d50 View commit details
  3. doc update

    imba-tjd committed Mar 16, 2021
    Copy the full SHA
    d5dc619 View commit details

Commits on Jun 8, 2022

  1. Copy the full SHA
    0c97174 View commit details

Commits on Oct 21, 2024

  1. Allow users to specify custom tokens (#5)

    * chore(actions): allow user specified tokens
    
    * feat: set token for `git` too
    
    * feat: use bash substitution instead of plaintext token storage
    
    * fix: invalid bash substitution syntax
    
    * fix: actually do the substitution lol
    
    * chore: semicolons for style
    CompeyDev authored Oct 21, 2024
    Copy the full SHA
    696d229 View commit details

Commits on Oct 28, 2024

  1. Fixed token login (#6)

    Echo $GITHUB_TOKEN env var instead of GITHUB_TOKEN string literal
    robvanhout authored Oct 28, 2024
    Copy the full SHA
    592f63f View commit details
Showing with 46 additions and 34 deletions.
  1. +8 −11 Readme.md
  2. +38 −23 action.yml
19 changes: 8 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ This Action is suitable if you:
* have changes that are not going to be merged into upstream
* want to keep changes based on the latest upstream

Basically this is doing `git rebase upstream master`. If there are conflicts, it simply fails.
Basically this is doing `git rebase upstream master && git push -f`. If there are conflicts, it simply fails.

## Typical usage

@@ -16,28 +16,25 @@ name: Rebase Upstream
on:
schedule:
- cron: "0 0 * * 0" # run once a week
workflow_dispatch: # run manually

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 10 # larger than the number of commits you made
fetch-depth: 10 # greater than the number of commits you made
- uses: imba-tjd/rebase-upstream-action@master
id: rebase
with:
upstream: https://github.com/<user>/<repo>.git
- uses: ad-m/github-push-action@master
if: steps.rebase.outputs.needs-push
with:
force: true
github_token: ${{ github.token }}
# with: # all args are optional
# upstream: <user>/<repo>
# branch: master
```

## Comparison

* tgymnich/fork-sync and apps/pull: I don't want PRs. Besides there is not way to do a `git rebase` on GitHub website
* repo-sync/github-sync: It's not using rebase or merge. It completely mirrors the upstream. And it can't sync current branch
* repo-sync/github-sync: It's not using rebase or merge. It completely mirrors the upstream so that it can't sync current branch
* wei/git-sync: Very complicated and have the same issue as github-sync. After all its aim is "syncing between two independent repo"
* aormsby/Fork-Sync-With-Upstream-action: If set `git_pull_rebase_config: true`, it's similar. But it tries to be configurable so that looks complex
* This one: Not widely tested. Use with caution
61 changes: 38 additions & 23 deletions action.yml
Original file line number Diff line number Diff line change
@@ -7,41 +7,56 @@ branding:

inputs:
upstream:
description: The full HTTPS upstream URL.
required: true
description: <user>/<repo> or the full HTTP URL
required: false
branch:
description: The upstream branch that is rebased on.
description: The upstream branch that is rebased on
required: false
default: master
default: master
depth:
description: The fetch depth
description: Greater than the number of commits the upstream made in a period
required: false
default: 100
push:
description: Do the force push in this action
required: false
default: true
token:
description: GitHub token to access to API and git
required: false
default: 100
outputs:
needs-push:
description: Whether push is needed.
value: ${{ steps.set-output.outputs.needs-push }}
default: ${{ github.token }}

runs:
using: composite
steps:
- run: |
echo adding ${{ inputs.upstream }} && \
git remote add upstream ${{ inputs.upstream }};
set -ex;
UPSTREAM=${{ inputs.upstream }};
GITHUB_TOKEN=${{ inputs.token }};
if [ -z $UPSTREAM ]; then
echo $GITHUB_TOKEN | gh auth login --with-token;
UPSTREAM=$(gh api repos/:owner/:repo --jq .parent.full_name);
if [ -z $UPSTREAM ]; then echo "Can't find upstream" >&2 && exit 1; fi;
fi;
if [ ! $(echo $UPSTREAM | egrep '^(http|git@)') ]; then
UPSTREAM=https://github.com/$UPSTREAM.git
fi;
if [ ${{ inputs.depth }} -ne 0 ]; then
DEPTH=--depth=${{ inputs.depth }}
fi;
git remote add upstream $UPSTREAM;
echo fetching... && \
git fetch upstream ${{ inputs.branch }} --depth=${{ inputs.depth }};
git fetch upstream ${{ inputs.branch }} $DEPTH;
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com";
git config --local user.name "GitHub Action";
git config --local user.name "GitHub Actions";
echo rebasing... && \
git rebase upstream/${{ inputs.branch }};
shell: bash
- id: set-output
shell: bash
run: |
if [ "$(git status | grep diverged)" ]; then
echo push is needed.
echo ::set-output name=needs-push::1
if [ "${{ inputs.push }}" = "true" -a "$(git status | grep diverged)" ]; then
ORIGIN_URL=$(git remote get-url origin);
git push "${ORIGIN_URL/https:\/\//https:\/\/$GITHUB_TOKEN@}" $(git branch --show-current) --force-with-lease;
fi;
shell: bash