-
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (76 loc) · 2.82 KB
/
Copy pathsync-main-to-dev.yml
File metadata and controls
92 lines (76 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Sync Main to Dev
on:
push:
branches: [main]
jobs:
sync-to-dev:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync main to dev
env:
GH_TOKEN: ${{ github.token }}
run: |
git checkout dev
git reset --hard origin/dev
# Check if merge would include workflow file changes
# GITHUB_TOKEN cannot push workflow changes (security restriction)
WORKFLOW_CHANGES=$(git diff --name-only origin/dev origin/main -- '.github/workflows/' || true)
if [ -n "$WORKFLOW_CHANGES" ]; then
echo "Workflow file changes detected:"
echo "$WORKFLOW_CHANGES"
echo ""
echo "Creating PR instead of direct push (GITHUB_TOKEN cannot modify workflow files)"
EXISTING_PR=$(gh pr list --base dev --head main --state open --json number --jq '.[0].number')
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already exists for main -> dev"
else
gh pr create \
--base dev \
--head main \
--title "Sync main into dev" \
--body "$(cat <<'EOF'
## Automated Sync
This sync includes workflow file changes which require manual merge:
```
$WORKFLOW_CHANGES
```
GITHUB_TOKEN cannot modify workflow files due to security restrictions.
Please merge this PR manually to keep `dev` up to date with `main`.
EOF
)"
fi
exit 0
fi
if git merge origin/main --no-edit; then
echo "Merge successful, pushing to dev"
git push origin dev
else
echo "Merge conflict detected, aborting merge and creating PR"
git merge --abort
EXISTING_PR=$(gh pr list --base dev --head main --state open --json number --jq '.[0].number')
if [ -n "$EXISTING_PR" ]; then
echo "PR #$EXISTING_PR already exists for main -> dev"
else
gh pr create \
--base dev \
--head main \
--title "Sync main into dev" \
--body "$(cat <<'EOF'
## Automated Sync
Merge conflicts were detected when trying to sync `main` into `dev`.
Please resolve the conflicts manually and merge this PR to keep `dev` up to date with `main`.
EOF
)"
fi
fi