-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (115 loc) · 5.23 KB
/
sync-contract-versions.yml
File metadata and controls
130 lines (115 loc) · 5.23 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
name: Sync Contract Versions
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
# - dev
permissions:
contents: write
pull-requests: write
jobs:
sync-contract-versions:
# Only run on PRs created by release-please
if: "contains(github.event.pull_request.head.ref, 'release-please') || contains(github.event.pull_request.title, 'chore: release')"
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Check for uncommitted changes in version files
id: check-uncommitted
run: |
SOL_CHANGED=false
TSX_CHANGED=false
if ! git diff --quiet HEAD -- contracts/core/lib/EngineBlox.sol; then
SOL_CHANGED=true
fi
if ! git diff --quiet HEAD -- sdk/typescript/lib/EngineBlox.tsx; then
TSX_CHANGED=true
fi
if [ "$SOL_CHANGED" = true ] || [ "$TSX_CHANGED" = true ]; then
echo "❌ ERROR: Version files have uncommitted changes!"
echo ""
echo "The workflow cannot safely update version constants when there are uncommitted changes."
echo "Please commit or stash your changes before this workflow runs."
echo ""
if [ "$SOL_CHANGED" = true ]; then
echo "Uncommitted changes in contracts/core/lib/EngineBlox.sol:"
git diff HEAD -- contracts/core/lib/EngineBlox.sol
fi
if [ "$TSX_CHANGED" = true ]; then
echo "Uncommitted changes in sdk/typescript/lib/EngineBlox.tsx:"
git diff HEAD -- sdk/typescript/lib/EngineBlox.tsx
fi
exit 1
else
echo "✓ EngineBlox.sol and EngineBlox.tsx are clean, safe to proceed with version sync"
echo "uncommitted=false" >> $GITHUB_OUTPUT
fi
- name: Sync versions (including contract constants)
run: npm run release:sync-versions
- name: Check for contract version changes
id: check-changes
run: |
SOL_CHANGED=false
TSX_CHANGED=false
if ! git diff --quiet contracts/core/lib/EngineBlox.sol; then
SOL_CHANGED=true
fi
if ! git diff --quiet sdk/typescript/lib/EngineBlox.tsx; then
TSX_CHANGED=true
fi
if [ "$SOL_CHANGED" = true ] || [ "$TSX_CHANGED" = true ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changes detected:"
[ "$SOL_CHANGED" = true ] && git diff contracts/core/lib/EngineBlox.sol
[ "$TSX_CHANGED" = true ] && git diff sdk/typescript/lib/EngineBlox.tsx
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "✓ Contract and SDK version constants already in sync"
fi
- name: Verify only version constants changed
if: steps.check-changes.outputs.changed == 'true'
id: verify-changes
run: |
# Get the diff for both version files
DIFF_OUTPUT=$(git diff contracts/core/lib/EngineBlox.sol sdk/typescript/lib/EngineBlox.tsx)
# All added/removed lines must be a VERSION constant change (.sol: constant VERSION = ... or .tsx: static readonly VERSION: string = ...)
ADDED_OR_REMOVED=$(echo "$DIFF_OUTPUT" | grep -E "^[-+]" | grep -v -E "^\+\+\+|^---")
OTHER_CHANGES=$(echo "$ADDED_OR_REMOVED" | grep -v -E "constant\s+VERSION\s*=" | grep -v -E "static readonly VERSION: string =")
if [ -n "$OTHER_CHANGES" ]; then
echo "❌ ERROR: Changes are not limited to VERSION constants!"
echo ""
echo "The workflow detected changes beyond the VERSION constant in EngineBlox.sol or EngineBlox.VERSION in EngineBlox.tsx."
echo "This could indicate uncommitted changes were accidentally included."
echo ""
echo "Full diff:"
echo "$DIFF_OUTPUT"
exit 1
fi
# Require at least one VERSION change (sol or tsx)
if ! echo "$DIFF_OUTPUT" | grep -qE "^[-+].*constant\s+VERSION\s*=" && \
! echo "$DIFF_OUTPUT" | grep -qE "^[-+].*static readonly VERSION: string ="; then
echo "❌ ERROR: No VERSION constant changes found in diff."
exit 1
fi
echo "✓ Only version constants changed (contract + SDK), safe to commit"
echo "safe=true" >> $GITHUB_OUTPUT
- name: Commit and push contract version updates
if: steps.check-changes.outputs.changed == 'true' && steps.verify-changes.outputs.safe == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add contracts/core/lib/EngineBlox.sol sdk/typescript/lib/EngineBlox.tsx
git commit -m "chore: sync contract version constants with package version"
git push