backport.yml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. - run: |
  13. if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
  14. echo this workflow should only be run against release branches
  15. exit 1
  16. fi
  17. - uses: actions/checkout@v3
  18. with:
  19. # history is needed to run git cherry-pick below
  20. fetch-depth: 0
  21. - name: Set git user
  22. run: .github/scripts/set-git-user.sh
  23. - name: Create pull request
  24. env:
  25. NUMBER: ${{ github.event.inputs.number }}
  26. # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
  27. GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
  28. run: |
  29. commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
  30. title=$(gh pr view $NUMBER --json title --jq .title)
  31. branch="backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
  32. git cherry-pick $commit
  33. git push origin HEAD:$branch
  34. gh pr create --title "[$GITHUB_REF_NAME] $title" \
  35. --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
  36. --head $branch \
  37. --base $GITHUB_REF_NAME