12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- name: Rebase Upstream
- description: Use git rebase to sync with upstream
- author: imba-tjd
- branding:
- icon: git-pull-request
- color: blue
- 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 Access Token
- required: true
- default: ${{ github.token }}
- runs:
- using: composite
- steps:
- - run: |
- set -ex;
- UPSTREAM=${{ inputs.upstream }};
- if [ -z $UPSTREAM ]; then
- echo ${{ inputs.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
|