cherrypick.yml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. name: Create Cherrypick PR
  2. on:
  3. pull_request:
  4. types:
  5. - closed
  6. branches:
  7. # TODO: Extract this to an env variable?
  8. - 'master'
  9. env:
  10. # TODO: Add a way to handle multiple potential cherrypick targets.
  11. TARGET_BRANCH: '4.3'
  12. USERNAME: 'Godot Organization'
  13. EMAIL: 'noreply@godotengine.org'
  14. jobs:
  15. Create-cherrypick-PR:
  16. # The cherrypick label is hardcoded because `contains()` doesn't seem to be able to use an environment variable as a second argument.
  17. if: ${{ github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'cherrypick:4.3' ) }}
  18. runs-on: ubuntu-24.04
  19. timeout-minutes: 10
  20. env:
  21. # "Ternary" hack featured in the official docs.
  22. # When using "Squash and merge", the commit hash is the last merge commit of the pull request merge branch.
  23. # When using "Merge", the commit hash is the last commit to the head branch of the pull request.
  24. # This is mildly error-prone, since in theory we could merge multiple commits without squashing.
  25. # We are relying on human review of the generated PRs to catch that.
  26. COMMIT_HASH: ${{ github.event.pull_request.commits > 1 && github.sha || github.event.pull_request.head.sha }}
  27. PR_NUMBER: ${{ github.event.number }}
  28. permissions:
  29. contents: write
  30. pull-requests: write
  31. steps:
  32. - name: Checkout
  33. uses: actions/checkout@v4
  34. with:
  35. ref: ${{ env.TARGET_BRANCH }}
  36. - name: Cherrypick Commit
  37. id: cherrypick_commit
  38. continue-on-error: true
  39. # TODO: Maybe only fetch some branches?
  40. run: |
  41. git config user.name "${{ env.USERNAME }}"
  42. git config user.email "${{ env.EMAIL }}"
  43. git fetch
  44. git cherry-pick -m 1 ${{ env.COMMIT_HASH }}
  45. - name: Create Pull Request
  46. if: steps.cherrypick_commit.outcome == 'success'
  47. uses: peter-evans/create-pull-request@v7
  48. with:
  49. commit-message: 'Cherrypick to ${{ env.TARGET_BRANCH }}'
  50. branch: 'cherrypick-${{ env.PR_NUMBER }}-${{ env.TARGET_BRANCH }}'
  51. delete-branch: true
  52. # Configure the commit author.
  53. author: '${{ env.USERNAME }} <${{ env.EMAIL }}>'
  54. committer: '${{ env.USERNAME }} <${{ env.EMAIL }}>'
  55. # Configure the pull request.
  56. title: 'Cherrypick ${{ env.PR_NUMBER }} to ${{ env.TARGET_BRANCH }}'
  57. body: 'Cherrypick #${{ env.PR_NUMBER }} to ${{ env.TARGET_BRANCH }}.'
  58. # TODO: Only add the bug or enhancement label, depending on which the original PR uses.
  59. labels: 'bug,enhancement'
  60. - name: Handle failure
  61. if: steps.cherrypick_commit.outcome == 'failure'
  62. run: |
  63. echo "Can't automatically cherrypick. Potential causes:"
  64. echo "- PR has multiple commits. Did you squash and merge?"
  65. echo "- Cherrypick did not apply cleanly and can't be auto-merged."