backport.yml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. name: Backport
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. number:
  6. description: "The pull request # to backport"
  7. required: true
  8. jobs:
  9. backport:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - uses: actions/checkout@v3
  13. with:
  14. # history is needed to run git cherry-pick below
  15. fetch-depth: 0
  16. - name: Set git user
  17. run: .github/scripts/set-git-user.sh
  18. - name: Create pull request
  19. env:
  20. NUMBER: ${{ github.event.inputs.number }}
  21. # not using the default GITHUB_TOKEN because pull requests generated by it do not run any workflows
  22. GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
  23. run: |
  24. commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
  25. title=$(gh pr view $NUMBER --json title --jq .title)
  26. url=$(gh pr view $NUMBER --json url --jq .url)
  27. branch="backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
  28. git cherry-pick $commit
  29. git push origin HEAD:$branch
  30. gh pr create --title "[$GITHUB_REF_NAME] $title" \
  31. --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
  32. --head $branch \
  33. --base $GITHUB_REF_NAME