action.yml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. name: Rebase Upstream
  2. description: Use git rebase to sync with upstream
  3. author: imba-tjd
  4. branding:
  5. icon: git-pull-request
  6. color: blue
  7. inputs:
  8. upstream:
  9. description: <user>/<repo> or the full HTTP URL
  10. required: false
  11. branch:
  12. description: The upstream branch that is rebased on
  13. required: false
  14. default: master
  15. depth:
  16. description: Greater than the number of commits the upstream made in a period
  17. required: false
  18. default: 100
  19. push:
  20. description: Do the force push in this action
  21. required: false
  22. default: true
  23. token:
  24. description: GitHub Access Token
  25. required: true
  26. default: ${{ github.token }}
  27. runs:
  28. using: composite
  29. steps:
  30. - run: |
  31. set -ex;
  32. UPSTREAM=${{ inputs.upstream }};
  33. if [ -z $UPSTREAM ]; then
  34. echo ${{ inputs.token }} | gh auth login --with-token;
  35. UPSTREAM=$(gh api repos/:owner/:repo --jq .parent.full_name);
  36. if [ -z $UPSTREAM ]; then echo "Can't find upstream" >&2 && exit 1; fi;
  37. fi;
  38. if [ ! $(echo $UPSTREAM | egrep '^(http|git@)') ]; then
  39. UPSTREAM=https://github.com/$UPSTREAM.git
  40. fi;
  41. if [ ${{ inputs.depth }} -ne 0 ]; then
  42. DEPTH=--depth=${{ inputs.depth }}
  43. fi;
  44. git remote add upstream $UPSTREAM;
  45. git fetch upstream ${{ inputs.branch }} $DEPTH;
  46. git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com";
  47. git config --local user.name "GitHub Actions";
  48. git rebase upstream/${{ inputs.branch }};
  49. if [ "${{ inputs.push }}" = "true" -a "$(git status | grep diverged)" ]; then
  50. git push origin $(git branch --show-current) --force-with-lease;
  51. fi;
  52. shell: bash