backport.yml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. name: Backport
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. number:
  6. description: "The pull request # to backport"
  7. required: true
  8. permissions:
  9. contents: read
  10. jobs:
  11. backport:
  12. permissions:
  13. contents: write # for Git to git push
  14. runs-on: ubuntu-latest
  15. steps:
  16. - run: |
  17. if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then
  18. echo this workflow should only be run against release branches
  19. exit 1
  20. fi
  21. - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
  22. with:
  23. # history is needed to run git cherry-pick below
  24. fetch-depth: 0
  25. - name: Use CLA approved github bot
  26. run: .github/scripts/use-cla-approved-github-bot.sh
  27. - name: Create pull request
  28. env:
  29. NUMBER: ${{ github.event.inputs.number }}
  30. # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
  31. GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
  32. run: |
  33. commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
  34. title=$(gh pr view $NUMBER --json title --jq .title)
  35. branch="opentelemetrybot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
  36. git checkout -b $branch
  37. git cherry-pick $commit
  38. git push --set-upstream origin $branch
  39. gh pr create --title "[$GITHUB_REF_NAME] $title" \
  40. --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
  41. --base $GITHUB_REF_NAME