| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- name: Sync release branch
- concurrency:
- group: sync-release-branch-${{ github.event_name }}-${{ github.ref }}
- cancel-in-progress: true
- on:
- schedule:
- - cron: '0 2 * * *'
- workflow_dispatch:
- permissions:
- contents: read
- jobs:
- create-pr:
- runs-on: ${{ endsWith(github.repository, '/emqx') && 'ubuntu-22.04' || fromJSON('["self-hosted","ephemeral","linux","x64"]') }}
- strategy:
- fail-fast: false
- matrix:
- branch:
- - release-58
- env:
- SYNC_BRANCH: ${{ matrix.branch }}
- defaults:
- run:
- shell: bash
- permissions:
- contents: write
- pull-requests: write
- steps:
- - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- with:
- fetch-depth: 0
- - name: merge and create PR
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
- set -euxo pipefail
- DIFF=$(git rev-list --count HEAD...origin/${SYNC_BRANCH})
- if [ $DIFF -eq 0 ]; then
- echo "No changes in ${SYNC_BRANCH}"
- exit 0
- fi
- NEW_BRANCH_NAME=sync-${SYNC_BRANCH}-$(date +"%Y%m%d-%H%M%S")
- git config --global user.name "${GITHUB_ACTOR}"
- git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- git checkout -b ${NEW_BRANCH_NAME}
- git merge origin/${SYNC_BRANCH} 2>&1 | tee merge.log
- git push origin ${NEW_BRANCH_NAME}:${NEW_BRANCH_NAME}
- 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
- gh pr close $pr --repo ${{ github.repository }} --delete-branch || true
- done
- gh pr create --title "Sync ${SYNC_BRANCH}" --body "Sync ${SYNC_BRANCH}" --base master --head ${NEW_BRANCH_NAME} --label sync-release-branch --repo ${{ github.repository }}
- - name: Send notification to Slack
- if: failure()
- env:
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- run: |
- awk '{printf "%s\\n", $0}' merge.log > merge.log.1
- cat <<EOF > payload.json
- {
- "blocks": [
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "Automatic sync of ${SYNC_BRANCH} branch failed: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "\`\`\`$(cat merge.log.1)\`\`\`"
- }
- }
- ]
- }
- EOF
- curl -X POST -H 'Content-type: application/json' --data @payload.json "$SLACK_WEBHOOK_URL"
|