forked from imba-tjd/rebase-upstream-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
56 lines (48 loc) · 1.64 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: Rebase Upstream
description: Use git rebase to sync with upstream
author: imba-tjd
branding:
icon: git-pull-request
color: green
inputs:
upstream:
description: <user>/<repo> or the full HTTP URL
required: false
branch:
description: The upstream branch that is rebased on
required: false
default: master
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
runs:
using: composite
steps:
- run: |
set -ex;
UPSTREAM=${{ inputs.upstream }};
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;
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 Actions";
git rebase upstream/${{ inputs.branch }};
if [ "${{ inputs.push }}" = "true" -a "$(git status | grep diverged)" ]; then
git push origin $(git branch --show-current) --force-with-lease;
fi;
shell: bash