Skip to content

Commit

Permalink
fix upstream detect, allow fetch all and not push
Browse files Browse the repository at this point in the history
  • Loading branch information
imba-tjd committed Mar 16, 2021
1 parent 54b4e25 commit 6b74a3d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ branding:

inputs:
upstream:
description: <user>/<repo>
description: <user>/<repo> or the full HTTP URL
required: false
branch:
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
default: 100
push:
description: Do the force push in this action
required: false
default: true

runs:
using: composite
Expand All @@ -26,21 +30,27 @@ runs:
UPSTREAM=${{ inputs.upstream }};
if [ -z $UPSTREAM ]; then
echo ${{ inputs.token }} | gh auth login --with-token;
UPSTREAM=$(a.json | jq .parent.full_name);
if [ -z $UPSTREAM ]; then echo "Can't find upstream" && exit 1; fi;
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 https://github.com/$UPSTREAM.git;
git remote add upstream $UPSTREAM;
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 Actions";
git rebase upstream/${{ inputs.branch }};
if [ "$(git status | grep diverged)" ]; then
git push origin $(git branch --show-current) --force-with-lease;
if [ "${{ inputs.push }}" = "true" -a "$(git status | grep diverged)" ]; then
git push origin $(git branch --show-current) --force-with-lease;
fi;
shell: bash

0 comments on commit 6b74a3d

Please sign in to comment.