backport.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. name: Backport merged pull request
  2. on:
  3. pull_request_target:
  4. # Run on merge (close) or if label is added after merging
  5. types: [closed, labeled]
  6. # Set concurrency limit to a single backport workflow per branch
  7. concurrency:
  8. group: ${{ github.workflow }}-${{ github.ref }}
  9. cancel-in-progress: true
  10. jobs:
  11. backport:
  12. permissions:
  13. contents: write # so it can comment
  14. pull-requests: write # so it can create pull requests
  15. name: Backport pull request
  16. runs-on: ubuntu-latest
  17. # Don't run on closed unmerged pull requests or if a non-backport label is added
  18. if: |
  19. github.event.pull_request.merged &&
  20. (
  21. github.event.action != 'labeled' ||
  22. contains(github.event.label.name, 'backport')
  23. )
  24. outputs:
  25. was_successful: ${{ steps.create-pr.outputs.was_successful }}
  26. steps:
  27. - uses: actions/checkout@v4
  28. - id: create-pr
  29. name: Create backport pull requests
  30. uses: korthout/backport-action@v3
  31. with:
  32. repo-token: ${{ secrets.GITHUB_TOKEN }}
  33. open-issue:
  34. permissions:
  35. contents: read
  36. issues: write
  37. name: Open issue for failed backports
  38. runs-on: ubuntu-latest
  39. needs: backport
  40. # Open an issue only if the backport job failed
  41. if: ${{ needs.backport.outputs.was_successful == 'false' }}
  42. steps:
  43. - uses: actions/checkout@v4
  44. - name: Set SHORT_PR_TITLE env
  45. run: |
  46. SHORT_PR_TITLE=$(
  47. echo '${{ github.event.pull_request.title }}' \
  48. | awk '{print (length($0) > 40) ? substr($0, 1, 40) "..." : $0}'
  49. )
  50. echo "SHORT_PR_TITLE=$SHORT_PR_TITLE" >> "$GITHUB_ENV"
  51. - name: Create issue
  52. uses: JasonEtco/create-an-issue@v2
  53. env:
  54. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  55. PR_NUMBER: ${{ github.event.number }}
  56. PR_TITLE: ${{ github.event.pull_request.title }}
  57. SHORT_PR_TITLE: ${{ env.SHORT_PR_TITLE }}
  58. with:
  59. filename: .github/templates/failed-backport-issue.md