-
Notifications
You must be signed in to change notification settings - Fork 25
/
action.yml
62 lines (54 loc) · 1.88 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
57
58
59
60
61
62
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
token:
description: GitHub token to access to API and git
required: false
default: ${{ github.token }}
runs:
using: composite
steps:
- run: |
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;
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
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