sync-release-branch.yaml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: Sync release branch
  2. concurrency:
  3. group: sync-release-branch-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. schedule:
  7. - cron: '0 2 * * *'
  8. workflow_dispatch:
  9. permissions:
  10. contents: read
  11. jobs:
  12. create-pr:
  13. runs-on: ${{ endsWith(github.repository, '/emqx') && 'ubuntu-22.04' || fromJSON('["self-hosted","ephemeral","linux","x64"]') }}
  14. strategy:
  15. fail-fast: false
  16. matrix:
  17. branch:
  18. - release-57
  19. env:
  20. SYNC_BRANCH: ${{ matrix.branch }}
  21. defaults:
  22. run:
  23. shell: bash
  24. permissions:
  25. contents: write
  26. pull-requests: write
  27. steps:
  28. - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
  29. with:
  30. fetch-depth: 0
  31. - name: create new branch
  32. run: |
  33. set -euxo pipefail
  34. NEW_BRANCH_NAME=sync-${SYNC_BRANCH}-$(date +"%Y%m%d-%H%M%S")
  35. echo "NEW_BRANCH_NAME=${NEW_BRANCH_NAME}" >> $GITHUB_ENV
  36. git config --global user.name "${GITHUB_ACTOR}"
  37. git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
  38. git checkout -b ${NEW_BRANCH_NAME}
  39. git merge origin/${SYNC_BRANCH} 2>&1 | tee merge.log
  40. git push origin ${NEW_BRANCH_NAME}:${NEW_BRANCH_NAME}
  41. - name: create pull request
  42. env:
  43. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  44. run: |
  45. set -euxo pipefail
  46. for pr in $(gh pr list --state open --base master --label sync-release-branch --search "Sync ${SYNC_BRANCH} in:title" --repo ${{ github.repository }} --json number --jq '.[] | .number'); do
  47. gh pr close $pr --repo ${{ github.repository }} --delete-branch || true
  48. done
  49. gh pr create --title "Sync ${SYNC_BRANCH}" --body "Sync ${SYNC_BRANCH}" --base master --head ${NEW_BRANCH_NAME} --label sync-release-branch --repo ${{ github.repository }}
  50. - name: Send notification to Slack
  51. if: failure()
  52. env:
  53. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  54. run: |
  55. awk '{printf "%s\\n", $0}' merge.log > merge.log.1
  56. cat <<EOF > payload.json
  57. {
  58. "blocks": [
  59. {
  60. "type": "section",
  61. "text": {
  62. "type": "mrkdwn",
  63. "text": "Automatic sync of ${SYNC_BRANCH} branch failed: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
  64. }
  65. },
  66. {
  67. "type": "section",
  68. "text": {
  69. "type": "mrkdwn",
  70. "text": "\`\`\`$(cat merge.log.1)\`\`\`"
  71. }
  72. }
  73. ]
  74. }
  75. EOF
  76. curl -X POST -H 'Content-type: application/json' --data @payload.json "$SLACK_WEBHOOK_URL"