Skip to content

Commit a338f32

Browse files
authored
Merge pull request #13 from Emurgo/ruslan/pull-latest-upstream
pull latest upstream (sdk 1.5.1)
2 parents cd5aa43 + bac7e46 commit a338f32

File tree

142 files changed

+5660
-1471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+5660
-1471
lines changed

.github/workflows/deploy-iframe.yml

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/publish.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v4
23+
- name: Debug directory structure
24+
run: |
25+
pwd
26+
ls -la
2327
- uses: actions/setup-node@v4
2428
with:
2529
node-version: 'lts/*'
@@ -31,10 +35,10 @@ jobs:
3135

3236
- name: Create Release Pull Request or Publish
3337
id: changesets
34-
uses: changesets/action@v1
38+
uses: changesets/action@v1.4.9
3539
with:
3640
publish: yarn release
37-
cwd: "./extension-files/bringweb3-sdk"
41+
cwd: "${{ github.workspace }}/extension-files/bringweb3-sdk"
3842
commit: "chore(release): version SDK package"
3943
title: "chore(release): version SDK package"
4044
env:
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
name: Sync Main to Dev Branches
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
target_branches:
7+
description: 'Branches to sync with main (comma-separated)'
8+
required: false
9+
default: 'dev,sandbox'
10+
type: string
11+
12+
# Automatically trigger after SDK publish (when changeset PR is merged to main)
13+
push:
14+
branches:
15+
- main
16+
paths:
17+
- 'extension-files/bringweb3-sdk/package.json'
18+
19+
jobs:
20+
check-version-change:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
version-changed: ${{ steps.check.outputs.changed }}
24+
old-version: ${{ steps.check.outputs.old-version }}
25+
new-version: ${{ steps.check.outputs.new-version }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 2 # Get current and previous commit
30+
31+
- name: Check if SDK version changed
32+
id: check
33+
run: |
34+
# Get current version
35+
CURRENT_VERSION=$(cat extension-files/bringweb3-sdk/package.json | jq -r '.version')
36+
37+
# Get previous version (from previous commit)
38+
PREVIOUS_VERSION=$(git show HEAD~1:extension-files/bringweb3-sdk/package.json | jq -r '.version' 2>/dev/null || echo "")
39+
40+
echo "Current version: $CURRENT_VERSION"
41+
echo "Previous version: $PREVIOUS_VERSION"
42+
43+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ] && [ -n "$PREVIOUS_VERSION" ]; then
44+
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
45+
echo "changed=true" >> $GITHUB_OUTPUT
46+
echo "old-version=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
47+
echo "new-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
48+
else
49+
echo "No version change detected"
50+
echo "changed=false" >> $GITHUB_OUTPUT
51+
fi
52+
53+
create-sync-prs:
54+
needs: check-version-change
55+
if: needs.check-version-change.outputs.version-changed == 'true' || github.event_name == 'workflow_dispatch'
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: write
59+
pull-requests: write
60+
steps:
61+
- uses: actions/checkout@v4
62+
with:
63+
fetch-depth: 0
64+
token: ${{ secrets.GITHUB_TOKEN }}
65+
66+
- name: Configure Git
67+
run: |
68+
git config user.name "github-actions[bot]"
69+
git config user.email "github-actions[bot]@users.noreply.github.com"
70+
71+
- name: Determine target branches
72+
id: branches
73+
run: |
74+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
75+
BRANCHES="${{ github.event.inputs.target_branches }}"
76+
else
77+
# Auto-sync after version change
78+
BRANCHES="dev,sandbox"
79+
fi
80+
echo "branches=$BRANCHES" >> $GITHUB_OUTPUT
81+
echo "Target branches: $BRANCHES"
82+
83+
- name: Create sync PRs
84+
run: |
85+
BRANCHES="${{ steps.branches.outputs.branches }}"
86+
SUCCESS_PRS=""
87+
FAILED_BRANCHES=""
88+
EXISTING_PRS=""
89+
90+
# Convert comma-separated string to array
91+
IFS=',' read -ra BRANCH_ARRAY <<< "$BRANCHES"
92+
93+
for branch in "${BRANCH_ARRAY[@]}"; do
94+
branch=$(echo "$branch" | xargs) # trim whitespace
95+
echo "=== Creating sync PR for branch: $branch ==="
96+
97+
# Check if branch exists
98+
if ! git ls-remote --heads origin "$branch" | grep -q "$branch"; then
99+
echo "Branch $branch does not exist, skipping..."
100+
FAILED_BRANCHES="$FAILED_BRANCHES $branch(not-found)"
101+
continue
102+
fi
103+
104+
# Check if branch is behind main
105+
BEHIND_COUNT=$(git rev-list --count "origin/$branch"..origin/main 2>/dev/null || echo "0")
106+
echo "Branch $branch is $BEHIND_COUNT commits behind main"
107+
108+
if [ "$BEHIND_COUNT" -eq 0 ]; then
109+
echo "Branch $branch is already up to date with main"
110+
SUCCESS_PRS="$SUCCESS_PRS $branch(up-to-date)"
111+
continue
112+
fi
113+
114+
# Create sync branch name
115+
SYNC_BRANCH="sync/main-to-$branch-$(date +%Y%m%d-%H%M%S)"
116+
echo "Creating sync branch: $SYNC_BRANCH"
117+
118+
# Create and checkout sync branch from main
119+
if git checkout -b "$SYNC_BRANCH" origin/main; then
120+
echo "Created sync branch $SYNC_BRANCH"
121+
else
122+
echo "Failed to create sync branch"
123+
FAILED_BRANCHES="$FAILED_BRANCHES $branch(sync-branch-failed)"
124+
continue
125+
fi
126+
127+
# Push sync branch
128+
if git push origin "$SYNC_BRANCH"; then
129+
echo "Pushed sync branch $SYNC_BRANCH"
130+
else
131+
echo "Failed to push sync branch"
132+
FAILED_BRANCHES="$FAILED_BRANCHES $branch(push-failed)"
133+
git checkout main 2>/dev/null || true
134+
continue
135+
fi
136+
137+
# Check for existing sync PR
138+
EXISTING_PR=$(gh pr list --base "$branch" --head "$SYNC_BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "")
139+
140+
if [ -n "$EXISTING_PR" ]; then
141+
echo "PR already exists: #$EXISTING_PR"
142+
EXISTING_PRS="$EXISTING_PRS $branch(#$EXISTING_PR)"
143+
else
144+
# Create PR using gh CLI
145+
VERSION_INFO="${{ needs.check-version-change.outputs.new-version || 'manual sync' }}"
146+
PR_TITLE="🔄 Sync main to $branch after release $VERSION_INFO"
147+
148+
if gh pr create --base "$branch" --head "$SYNC_BRANCH" --title "$PR_TITLE" --body "Sync changes from main branch to $branch after release $VERSION_INFO. This removes processed changesets and prevents accumulation issues. 🤖 Auto-created by GitHub Actions."; then
149+
PR_NUMBER=$(gh pr list --base "$branch" --head "$SYNC_BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "unknown")
150+
echo "Created PR #$PR_NUMBER for $branch"
151+
SUCCESS_PRS="$SUCCESS_PRS $branch(#$PR_NUMBER)"
152+
else
153+
echo "Failed to create PR for $branch"
154+
FAILED_BRANCHES="$FAILED_BRANCHES $branch(pr-creation-failed)"
155+
fi
156+
fi
157+
158+
# Return to main branch
159+
git checkout main 2>/dev/null || true
160+
echo ""
161+
done
162+
163+
# Summary
164+
echo "=== SYNC PR SUMMARY ==="
165+
if [ -n "$SUCCESS_PRS" ]; then
166+
echo "✅ Successfully created PRs: $SUCCESS_PRS"
167+
fi
168+
if [ -n "$EXISTING_PRS" ]; then
169+
echo "ℹ️ Existing PRs found: $EXISTING_PRS"
170+
fi
171+
if [ -n "$FAILED_BRANCHES" ]; then
172+
echo "❌ Failed to create PRs: $FAILED_BRANCHES"
173+
echo "FAILED_BRANCHES=$FAILED_BRANCHES" >> $GITHUB_ENV
174+
fi
175+
176+
echo "SUCCESS_PRS=$SUCCESS_PRS" >> $GITHUB_ENV
177+
echo "EXISTING_PRS=$EXISTING_PRS" >> $GITHUB_ENV
178+
179+
- name: Create summary
180+
run: |
181+
echo "## 🔄 Branch Sync PR Summary" >> $GITHUB_STEP_SUMMARY
182+
183+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
184+
echo "- **Trigger**: Manual workflow dispatch" >> $GITHUB_STEP_SUMMARY
185+
echo "- **Target branches**: ${{ steps.branches.outputs.branches }}" >> $GITHUB_STEP_SUMMARY
186+
else
187+
echo "- **Trigger**: Automatic (SDK version change)" >> $GITHUB_STEP_SUMMARY
188+
echo "- **Version change**: ${{ needs.check-version-change.outputs.old-version }} → ${{ needs.check-version-change.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
189+
echo "- **Target branches**: ${{ steps.branches.outputs.branches }}" >> $GITHUB_STEP_SUMMARY
190+
fi
191+
192+
if [ -n "$SUCCESS_PRS" ]; then
193+
echo "" >> $GITHUB_STEP_SUMMARY
194+
echo "### ✅ Successfully Created PRs" >> $GITHUB_STEP_SUMMARY
195+
for pr in $SUCCESS_PRS; do
196+
echo "- \`$pr\`" >> $GITHUB_STEP_SUMMARY
197+
done
198+
fi
199+
200+
if [ -n "$EXISTING_PRS" ]; then
201+
echo "" >> $GITHUB_STEP_SUMMARY
202+
echo "### ℹ️ Existing PRs Found" >> $GITHUB_STEP_SUMMARY
203+
for pr in $EXISTING_PRS; do
204+
echo "- \`$pr\`" >> $GITHUB_STEP_SUMMARY
205+
done
206+
fi
207+
208+
if [ -n "$FAILED_BRANCHES" ]; then
209+
echo "" >> $GITHUB_STEP_SUMMARY
210+
echo "### ❌ Failed to Create PRs" >> $GITHUB_STEP_SUMMARY
211+
for branch in $FAILED_BRANCHES; do
212+
echo "- \`$branch\`" >> $GITHUB_STEP_SUMMARY
213+
done
214+
echo "" >> $GITHUB_STEP_SUMMARY
215+
echo "**Action required**: Check failed branches and create PRs manually if needed" >> $GITHUB_STEP_SUMMARY
216+
fi
217+
218+
echo "" >> $GITHUB_STEP_SUMMARY
219+
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
220+
echo "1. Review and approve the created PRs" >> $GITHUB_STEP_SUMMARY
221+
echo "2. Merge the PRs to complete the sync" >> $GITHUB_STEP_SUMMARY
222+
echo "3. This will resolve changeset accumulation issues" >> $GITHUB_STEP_SUMMARY
223+
224+
- name: Fail if any PR creation failed
225+
if: env.FAILED_BRANCHES != ''
226+
run: |
227+
echo "Some PRs failed to be created: $FAILED_BRANCHES"
228+
exit 1
229+
230+
notify-completion:
231+
needs: [check-version-change, create-sync-prs]
232+
if: always() && (needs.check-version-change.outputs.version-changed == 'true' || github.event_name == 'workflow_dispatch')
233+
runs-on: ubuntu-latest
234+
steps:
235+
- name: Notification
236+
run: |
237+
if [ "${{ needs.create-sync-prs.result }}" = "success" ]; then
238+
echo "✅ Sync PRs created successfully"
239+
echo "Review and merge the PRs to complete the sync process"
240+
echo "This will resolve changeset accumulation issues"
241+
else
242+
echo "❌ Some sync PRs had issues"
243+
echo "Check the workflow logs and create PRs manually if needed"
244+
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

WORKFLOW.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Branch Sync Workflow
2+
3+
## Problem Solved
4+
5+
Previously, changeset `.md` files accumulated in dev/sandbox branches because they weren't synced back after production releases. This caused incorrect version calculations when deploying to sandbox.
6+
7+
## New Workflow
8+
9+
### Automatic Sync
10+
After each production release (when SDK version changes in main):
11+
1. **Sync workflow automatically triggers**
12+
2. **Merges main → dev** (removes processed changesets)
13+
3. **Merges main → sandbox** (removes processed changesets)
14+
4. **Clean branches** ready for next development cycle
15+
16+
### Manual Sync
17+
You can also manually trigger the sync:
18+
```bash
19+
# Via GitHub Actions UI
20+
Actions → Sync Main to Dev Branches → Run workflow
21+
```
22+
23+
## Branch States
24+
25+
### Before (Problematic)
26+
```
27+
main: v1.2.0 (changesets A,B,C processed & deleted)
28+
sandbox: v1.1.0 + changesets A,B,C,D,E (accumulated!)
29+
↳ Version calculation: v1.2.0 + all 5 changesets = wrong!
30+
```
31+
32+
### After (Clean)
33+
```
34+
main: v1.2.0 (changesets A,B,C processed & deleted)
35+
sandbox: v1.2.0 + changesets D,E (synced from main)
36+
↳ Version calculation: v1.2.0 + 2 new changesets = correct!
37+
```
38+
39+
## Your Development Flow
40+
41+
1. **Develop** on `dev` branch
42+
2. **Test** by pushing to `sandbox`
43+
3. **Release** by pushing to `main`
44+
4. **Auto-sync** happens after main release ✨
45+
5. **Continue** development on clean branches
46+
47+
## Files Changed
48+
49+
-**Reverted** complex changeset filtering in `deploy-iframe.yml`
50+
-**Added** `sync-branches.yml` workflow
51+
-**Updated** test script (can be deleted now)
52+
53+
## Manual Sync Commands
54+
55+
If you need to sync manually:
56+
57+
```bash
58+
# Sync dev branch
59+
git checkout dev
60+
git pull origin main
61+
git push origin dev
62+
63+
# Sync sandbox branch
64+
git checkout sandbox
65+
git pull origin main
66+
git push origin sandbox
67+
```
68+
69+
## Benefits
70+
71+
-**No more changeset accumulation**
72+
-**Accurate version calculations**
73+
-**Cleaner git history**
74+
-**Automated process**
75+
-**Handles merge conflicts gracefully**
76+
-**Manual fallback available**

extension-files/bringweb3-sdk/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ npm-debug.log*
1111

1212
.env
1313

14+
.env.local
15+
1416
coverage

0 commit comments

Comments
 (0)