Folo/.github/workflows/sync.yaml

50 lines
1.7 KiB
YAML

name: 🔄 Sync Release Branches To Dev
on:
push:
branches:
- main
- mobile-main
permissions:
contents: write
pull-requests: write
jobs:
sync-to-dev:
runs-on: ubuntu-latest
if: |
(github.ref == 'refs/heads/main' && contains(github.event.head_commit.message || '', 'release(desktop):')) ||
(github.ref == 'refs/heads/mobile-main' && contains(github.event.head_commit.message || '', 'release(mobile):'))
steps:
- name: Create or update sync pull request
env:
GH_TOKEN: ${{ github.token }}
run: |
source_branch="${GITHUB_REF_NAME}"
title="chore(sync): merge ${source_branch} into dev"
body=$(cat <<EOF
This pull request was created automatically after a release branch update.
- Source branch: \`${source_branch}\`
- Target branch: \`dev\`
EOF
)
pr_number="$(gh pr list --base dev --head "${source_branch}" --state open --json number --jq '.[0].number')"
if [ -z "${pr_number}" ]; then
pr_url="$(gh pr create --base dev --head "${source_branch}" --title "${title}" --body "${body}")"
pr_number="$(gh pr view "${pr_url}" --json number --jq '.number')"
echo "Created sync PR: ${pr_url}"
else
gh pr edit "${pr_number}" --title "${title}" --body "${body}"
echo "Updated existing sync PR: #${pr_number}"
fi
if gh pr merge "${pr_number}" --auto --merge; then
echo "Enabled auto-merge for sync PR #${pr_number}"
else
echo "Could not enable auto-merge for sync PR #${pr_number}. Merge it manually after required checks pass."
fi