forked from Scaffold-Stark/scaffold-stark-2
-
Notifications
You must be signed in to change notification settings - Fork 28
176 lines (145 loc) · 6.71 KB
/
Copy pathsync_other_challenges.yaml
File metadata and controls
176 lines (145 loc) · 6.71 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
name: Sync other challenges
on:
push:
branches:
- base-challenge-template
jobs:
sync:
runs-on: ubuntu-22.04
steps:
- name: Checkout Source Repository
uses: actions/checkout@v4
with:
repository: Scaffold-Stark/speedrunstark
token: ${{ secrets.ORG_GITHUB_TOKEN }}
ref: base-challenge-template
path: source_repo
- name: Checkout Repo
uses: actions/checkout@v4
with:
repository: Scaffold-Stark/speedrunstark
token: ${{ secrets.ORG_GITHUB_TOKEN }}
fetch-depth: 0
path: speedrun_repo
- name: Setup Git
run: |
cd speedrun_repo
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --local merge.ours.driver true
git config --local merge.theirs.driver true
- name: Checkout Base Challenge Template
run: |
cd speedrun_repo
git checkout base-challenge-template
git pull origin base-challenge-template
git rm -f .github/workflows/sync_other_challenges.yaml
git rm -f ./packages/snfoundry/contracts/src/your_contract.cairo
git commit -m "chore: remove sync_other_challenges.yml and your_contract.cairo to avoid unexpected conflicts"
- name: Update Challenge Branches
run: |
cd speedrun_repo
CHALLENGE_BRANCHES=(
"challenge-0-simple-nft"
"challenge-1-decentralized-staking"
"challenge-2-token-vendor"
"challenge-3-dice-game"
"challenge-4-build-a-dex"
"challenge-5-multisig-wallet"
)
echo "Merging base-challenge-template into challenge branches..."
for branch in "${CHALLENGE_BRANCHES[@]}"; do
echo "Processing branch: $branch"
git checkout $branch
git pull origin $branch
# Try to merge first
if git merge base-challenge-template --no-edit; then
echo "Merge successful for $branch"
echo "Syncing Compatible versions section for $branch..."
python3 -c "
import re
# Read source and destination READMEs
with open('../source_repo/README.md', 'r') as f:
source = f.read()
with open('README.md', 'r') as f:
dest = f.read()
# Extract versions list from source (## Compatible versions)
source_match = re.search(r'## Compatible versions\s*\n(.*?)(?=\n##|\Z)', source, re.DOTALL)
if not source_match:
print('Could not find Compatible versions in source README')
exit(1)
versions_list = source_match.group(1).strip()
print('Found versions:', versions_list[:50] + '...')
# Replace versions in destination (### Compatible versions)
dest_pattern = r'(### Compatible versions\s*\n)(.*?)(?=\n###|\Z)'
dest_match = re.search(dest_pattern, dest, re.DOTALL)
if not dest_match:
print('Could not find Compatible versions in destination README')
exit(1)
# Keep the requirements link if it exists
old_content = dest_match.group(2)
requirements_link = ''
if 'Make sure you have the compatible versions' in old_content:
req_match = re.search(r'(Make sure you have.*?)(?=\n###|\Z)', old_content, re.DOTALL)
if req_match:
requirements_link = '\n\n' + req_match.group(1).strip()
# Replace the section
new_section = dest_match.group(1) + versions_list + requirements_link
new_dest = re.sub(dest_pattern, new_section, dest, flags=re.DOTALL)
# Write updated README
with open('README.md', 'w') as f:
f.write(new_dest)
print('Successfully updated Compatible versions section for $branch')
"
if git diff --quiet README.md; then
echo "No changes to README.md, skipping commit"
else
echo "README.md was modified, committing changes"
git add README.md
git commit -m "chore: sync compatible versions from base README"
fi
echo "Pushing changes for $branch"
git push origin $branch
else
echo "Merge conflict detected in $branch, creating PR"
# Abort the current merge
git merge --abort
# Create a new branch for the PR
CONFLICT_BRANCH="fix-conflicts-$branch-$(date +%s)"
git checkout -b $CONFLICT_BRANCH
# Try merge again but allow it to record conflicts
git merge base-challenge-template || true
# Commit the conflicts
git add .
git commit -m "Auto-commit merge conflicts between base-challenge-template and $branch"
# Push the branch with conflicts
git push origin $CONFLICT_BRANCH
# Create PR using GitHub CLI if available, otherwise use API
PR_TITLE="Fix merge conflicts in $branch"
PR_BODY="This PR was automatically created to resolve merge conflicts between base-challenge-template and $branch."
# Using GitHub API to create PR
curl -X POST \
-H "Authorization: token ${{ secrets.ORG_GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/Scaffold-Stark/speedrunstark/pulls \
-d "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$CONFLICT_BRANCH\",\"base\":\"$branch\"}"
# Return to original branch
git checkout $branch
fi
done
- name: Notify Slack on Success
if: success()
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "Successfully processed sync operation for speedrunstark repository. Check for any PRs that may have been created for conflict resolution."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
- name: Notify Slack on Failure
if: failure()
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: "Failed to sync scaffold-stark-2 changes to speedrunstark repository."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}