-
Notifications
You must be signed in to change notification settings - Fork 212
272 lines (236 loc) · 9.51 KB
/
sync-more-logins-e2e.yml
File metadata and controls
272 lines (236 loc) · 9.51 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Sync More Logins E2E Branch with Develop
on:
# Trigger when develop branch is updated
push:
branches:
- develop
- W-18685522-reset-and-passwordless-integration-test # TODO: remove this branch after testing
# Run daily at 2 AM UTC to catch any missed syncs
schedule:
- cron: '0 2 * * *'
# Allow manual triggering with options
workflow_dispatch:
inputs:
force_sync:
description: 'Force sync even if conflicts exist (overwrites E2E branch)'
required: false
default: false
type: boolean
sync_strategy:
description: 'Sync strategy to use'
required: false
default: 'merge'
type: choice
options:
- merge
- rebase
- reset
permissions:
contents: write
issues: write
pull-requests: read
jobs:
sync-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config --global user.name ${{ secrets.GIT_CONFIG_USERNAME }}
git config --global user.email ${{ secrets.GIT_CONFIG_EMAIL }}
- name: Sync more-logins-e2e-test with develop
id: sync
run: |
set -e
# Fetch all branches
git fetch origin
# Check if the target branch exists
if ! git show-ref --verify --quiet refs/remotes/origin/more-logins-e2e-test; then
echo "Branch more-logins-e2e-test does not exist. Creating it from develop..."
git checkout -b more-logins-e2e-test origin/develop
git push origin more-logins-e2e-test
echo "✅ Created more-logins-e2e-test branch from develop"
echo "status=created" >> $GITHUB_OUTPUT
exit 0
fi
# Switch to the target branch
git checkout more-logins-e2e-test
git reset --hard origin/more-logins-e2e-test
# Check if we're already up to date
if git merge-base --is-ancestor origin/develop HEAD; then
echo "✅ more-logins-e2e-test is already up to date with develop"
echo "status=up-to-date" >> $GITHUB_OUTPUT
exit 0
fi
STRATEGY="${{ github.event.inputs.sync_strategy || 'merge' }}"
echo "🔄 Attempting to sync using strategy: $STRATEGY"
if [ "${{ github.event.inputs.force_sync }}" = "true" ]; then
echo "🔧 Force sync requested. Resetting to develop..."
git reset --hard origin/develop
git push --force origin more-logins-e2e-test
echo "⚠️ Force synced more-logins-e2e-test with develop (all conflicts overwritten)"
echo "status=force-synced" >> $GITHUB_OUTPUT
elif [ "$STRATEGY" = "rebase" ]; then
if git rebase origin/develop; then
echo "✅ Successfully rebased more-logins-e2e-test onto develop"
git push --force-with-lease origin more-logins-e2e-test
echo "status=rebased" >> $GITHUB_OUTPUT
else
echo "❌ Rebase conflicts detected!"
git rebase --abort
echo "status=conflict" >> $GITHUB_OUTPUT
exit 1
fi
elif [ "$STRATEGY" = "reset" ]; then
git reset --hard origin/develop
git push --force origin more-logins-e2e-test
echo "✅ Reset more-logins-e2e-test to match develop"
echo "status=reset" >> $GITHUB_OUTPUT
else
# Default merge strategy
if git merge origin/develop --no-edit; then
echo "✅ Successfully merged develop into more-logins-e2e-test"
git push origin more-logins-e2e-test
echo "status=merged" >> $GITHUB_OUTPUT
else
echo "❌ Merge conflicts detected!"
echo "📋 Files with conflicts:"
git diff --name-only --diff-filter=U || true
git merge --abort
echo "status=conflict" >> $GITHUB_OUTPUT
exit 1
fi
fi
- name: Create conflict resolution issue
if: steps.sync.outputs.status == 'conflict'
uses: actions/github-script@v7
with:
script: |
const conflictFiles = `${{ steps.sync.outputs.conflict_files || 'Unknown files' }}`;
const issueBody = `
## 🚨 Automatic Sync Failed - Merge Conflicts Detected
The automatic sync from \`develop\` to \`more-logins-e2e-test\` failed due to merge conflicts.
### Conflicting Files:
\`\`\`
${conflictFiles}
\`\`\`
### Resolution Options:
#### Option 1: Manual Resolution
\`\`\`bash
git checkout more-logins-e2e-test
git pull origin more-logins-e2e-test
git merge develop
# Resolve conflicts manually
git add .
git commit -m "Resolve merge conflicts from develop"
git push origin more-logins-e2e-test
\`\`\`
#### Option 2: Force Sync (Overwrites E2E changes)
Go to [Actions](../../actions/workflows/sync-more-logins-e2e.yml) and run the workflow manually with "Force sync" enabled.
#### Option 3: Reset Strategy
Go to [Actions](../../actions/workflows/sync-more-logins-e2e.yml) and run the workflow manually with "reset" strategy.
### Auto-close
This issue will be automatically closed when the sync succeeds.
`;
// Check if issue already exists
const existingIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'sync-conflict'
});
if (existingIssues.data.length === 0) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚨 E2E Branch Sync Conflict - Manual Resolution Required',
body: issueBody,
labels: ['sync-conflict', 'automation']
});
}
- name: Close conflict resolution issues
if: steps.sync.outputs.status != 'conflict'
uses: actions/github-script@v7
with:
script: |
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'sync-conflict'
});
for (const issue of issues.data) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: '✅ Sync conflict resolved automatically. Closing this issue.'
});
}
deploy:
needs: sync-branch
if: needs.sync-branch.outputs.status != 'conflict' && needs.sync-branch.outputs.status != 'up-to-date'
runs-on: ubuntu-latest
environment: more-logins-e2e
steps:
- name: Checkout more-logins-e2e-test branch
uses: actions/checkout@v4
with:
ref: more-logins-e2e-test
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
- name: Install Monorepo Dependencies
run: |
# Install node dependencies
node ./scripts/gtime.js monorepo_install npm ci
- name: Build project
run: |
cd packages/template-retail-react-app
npm run build
- name: Create MRT credentials file
uses: "./.github/actions/create_mrt"
with:
mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }}
mobify_api_key: ${{ secrets.MOBIFY_CLIENT_API_KEY }}
- name: Deploy to MRT
uses: "./.github/actions/push_to_mrt"
with:
CWD: "./packages/template-retail-react-app"
TARGET: more-logins-e2e
PROJECT: pwa-kit
MESSAGE: "Auto-sync from develop - build ${{ github.run_id }} (${{ github.sha }})"
FLAGS: --wait
- name: Get deployment URL
id: deployment-url
run: |
URL="https://scaffold-pwa-more-logins-e2e.mobify-storefront.com"
echo "url=${URL}" >> $GITHUB_OUTPUT
echo "🚀 Deployment URL: ${URL}"
- name: Wait for deployment to be ready
run: |
URL="${{ steps.deployment-url.outputs.url }}"
echo "⏳ Waiting for deployment to be ready at: $URL"
for i in {1..30}; do
if curl -f -s "$URL" > /dev/null; then
echo "✅ Deployment is ready!"
exit 0
fi
echo "Attempt $i/30: Site not ready yet, waiting 30 seconds..."
sleep 30
done
echo "❌ Deployment did not become ready within 15 minutes"
exit 1
# Removed notify job - no notifications needed