-
Notifications
You must be signed in to change notification settings - Fork 41
209 lines (165 loc) · 7.37 KB
/
sync-from-public.yml
File metadata and controls
209 lines (165 loc) · 7.37 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Sync from Public Repo
on:
schedule:
- cron: '0 */6 * * *' # Every 6 hours
workflow_dispatch: # Manual trigger via Actions tab
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch public main
run: |
git remote add public https://github.com/aws/agentcore-cli.git
git fetch public main
- name: Sync main with public/main
run: |
git checkout -B main origin/main
# Check if public/main is already merged
if git merge-base --is-ancestor public/main HEAD; then
echo "✅ main is already up to date with public/main"
exit 0
fi
# Merge but exclude .github/workflows/ (GITHUB_TOKEN lacks workflow permission)
if git merge public/main --no-commit --no-ff; then
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git commit -m "chore: sync main with public/main"
git push origin main
echo "✅ main synced successfully"
else
echo "⚠️ Conflict detected in main"
# Capture conflicted files before aborting
conflicted_files=$(git diff --name-only --diff-filter=U 2>/dev/null || echo "Unable to determine conflicted files")
git merge --abort
# Check if a sync PR already exists
existing_pr=$(gh pr list --base "main" --search "Merge public/main" --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$existing_pr" ]; then
echo "ℹ️ PR #$existing_pr already exists, skipping"
exit 0
fi
conflict_branch="sync-conflict-main-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$conflict_branch"
git merge public/main --no-commit --no-ff || true
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git add -A
git commit -m "chore: sync main with public/main (conflicts present)
This automated sync detected merge conflicts that require manual resolution.
Source: public/main (https://github.com/aws/agentcore-cli)
Target: main
Please resolve conflicts and merge this PR." || true
git push origin "$conflict_branch"
gh pr create \
--title "🔀 [Sync Conflict] Merge public/main → main" \
--body "## Automated Sync Conflict
This PR was automatically created because merging \`public/main\` into \`main\` encountered conflicts.
**Source:** \`main\` from [aws/agentcore-cli](https://github.com/aws/agentcore-cli)
**Target:** \`main\`
### Action Required
1. \`git fetch origin && git checkout $conflict_branch\`
2. Resolve merge conflicts
3. \`git add . && git commit\`
4. \`git push origin $conflict_branch\`
5. Merge this PR
### Files with Conflicts
\`\`\`
$conflicted_files
\`\`\`" \
--base "main" \
--head "$conflict_branch" || echo "⚠️ Failed to create PR"
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
sync-preview:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch public preview
run: |
git remote add public https://github.com/aws/agentcore-cli.git
git fetch public preview
- name: Sync preview with public/preview
run: |
git checkout -B preview origin/preview
# Check if public/preview is already merged
if git merge-base --is-ancestor public/preview HEAD; then
echo "✅ preview is already up to date with public/preview"
exit 0
fi
# Merge but exclude .github/workflows/ (GITHUB_TOKEN lacks workflow permission)
if git merge public/preview --no-commit --no-ff; then
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git commit -m "chore: sync preview with public/preview"
git push origin preview
echo "✅ preview synced successfully"
else
echo "⚠️ Conflict detected in preview"
# Capture conflicted files before aborting
conflicted_files=$(git diff --name-only --diff-filter=U 2>/dev/null || echo "Unable to determine conflicted files")
git merge --abort
# Check if a sync PR already exists
existing_pr=$(gh pr list --base "preview" --search "Merge public/preview" --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$existing_pr" ]; then
echo "ℹ️ PR #$existing_pr already exists, skipping"
exit 0
fi
conflict_branch="sync-conflict-preview-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$conflict_branch"
git merge public/preview --no-commit --no-ff || true
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git add -A
git commit -m "chore: sync preview with public/preview (conflicts present)
This automated sync detected merge conflicts that require manual resolution.
Source: public/preview (https://github.com/aws/agentcore-cli)
Target: preview
Please resolve conflicts and merge this PR." || true
git push origin "$conflict_branch"
gh pr create \
--title "🔀 [Sync Conflict] Merge public/preview → preview" \
--body "## Automated Sync Conflict
This PR was automatically created because merging \`public/preview\` into \`preview\` encountered conflicts.
**Source:** \`preview\` from [aws/agentcore-cli](https://github.com/aws/agentcore-cli)
**Target:** \`preview\`
### Action Required
1. \`git fetch origin && git checkout $conflict_branch\`
2. Resolve merge conflicts
3. \`git add . && git commit\`
4. \`git push origin $conflict_branch\`
5. Merge this PR
### Files with Conflicts
\`\`\`
$conflicted_files
\`\`\`" \
--base "preview" \
--head "$conflict_branch" || echo "⚠️ Failed to create PR"
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}