-
Notifications
You must be signed in to change notification settings - Fork 118
322 lines (281 loc) · 10.5 KB
/
Copy pathcontract-deployment.yml
File metadata and controls
322 lines (281 loc) · 10.5 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: Contract Deployment Pipeline
on:
push:
branches: [main, develop]
paths:
- 'contracts/predict-iq/**'
- '.github/workflows/contract-deployment.yml'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'testnet'
type: choice
options:
- testnet
- mainnet
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
build-and-test:
name: Build and Test Contracts
runs-on: ubuntu-latest
outputs:
wasm-path: ${{ steps.build.outputs.wasm-path }}
contract-hash: ${{ steps.build.outputs.contract-hash }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: wasm32-unknown-unknown
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v5
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v5
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install Soroban CLI
run: cargo install --locked soroban-cli --features opt
- name: Run unit tests
run: cargo test --lib --workspace
working-directory: contracts/predict-iq
- name: Run integration tests
run: cargo test --test '*' --workspace
working-directory: contracts/predict-iq
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: contracts/predict-iq
- name: Check formatting
run: cargo fmt --all -- --check
working-directory: contracts/predict-iq
- name: Build optimized WASM
id: build
run: |
cargo build --target wasm32-unknown-unknown --release
soroban contract optimize \
--wasm target/wasm32-unknown-unknown/release/predict_iq.wasm \
--wasm-out target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm
# Output paths for artifact upload
echo "wasm-path=target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm" >> $GITHUB_OUTPUT
# Calculate contract hash for versioning
CONTRACT_HASH=$(sha256sum target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm | cut -d' ' -f1)
echo "contract-hash=${CONTRACT_HASH}" >> $GITHUB_OUTPUT
echo "Contract hash: ${CONTRACT_HASH}"
working-directory: contracts/predict-iq
- name: Verify WASM size
run: |
size=$(wc -c < target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm)
echo "Optimized WASM size: $size bytes"
max_size=65536
if [ $size -gt $max_size ]; then
echo "WASM size $size exceeds limit of $max_size bytes"
exit 1
fi
working-directory: contracts/predict-iq
- name: Upload WASM artifact
uses: actions/upload-artifact@v7
with:
name: contract-wasm
path: contracts/predict-iq/target/wasm32-unknown-unknown/release/predict_iq_optimized.wasm
retention-days: 30
deploy-testnet:
name: Deploy to Testnet
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' || github.event.inputs.environment == 'testnet'
environment:
name: testnet
steps:
- uses: actions/checkout@v4
- name: Download WASM artifact
uses: actions/download-artifact@v4
with:
name: contract-wasm
path: ./artifacts
- name: Install Soroban CLI
run: |
cargo install --locked soroban-cli --features opt
- name: Configure Soroban for Testnet
run: |
soroban config network add testnet \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"
- name: Deploy contract to Testnet
env:
SOROBAN_ACCOUNT: ${{ secrets.SOROBAN_TESTNET_ACCOUNT }}
SOROBAN_SECRET_KEY: ${{ secrets.SOROBAN_TESTNET_SECRET_KEY }}
run: |
soroban contract deploy \
--wasm ./artifacts/predict_iq_optimized.wasm \
--source-account $SOROBAN_ACCOUNT \
--network testnet
- name: Create deployment artifact
run: |
cat > deployment-info.json <<EOF
{
"environment": "testnet",
"timestamp": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')",
"commit": "${{ github.sha }}",
"contract_hash": "${{ needs.build-and-test.outputs.contract-hash }}",
"deployed_by": "${{ github.actor }}"
}
EOF
- name: Upload deployment info
uses: actions/upload-artifact@v7
with:
name: testnet-deployment-${{ github.run_id }}
path: deployment-info.json
retention-days: 90
- name: Comment on PR with deployment info
if: github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `✅ Contract deployed to **Testnet**\n\n- Commit: ${context.sha.substring(0, 7)}\n- Contract Hash: ${{ needs.build-and-test.outputs.contract-hash }}\n- Timestamp: ${new Date().toISOString()}`
})
deploy-mainnet:
name: Deploy to Mainnet
needs: build-and-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: mainnet
# Require manual approval for mainnet deployments
steps:
- uses: actions/checkout@v4
- name: Download WASM artifact
uses: actions/download-artifact@v4
with:
name: contract-wasm
path: ./artifacts
- name: Install Soroban CLI
run: |
cargo install --locked soroban-cli --features opt
- name: Configure Soroban for Mainnet
run: |
soroban config network add mainnet \
--rpc-url https://soroban-mainnet.stellar.org:443 \
--network-passphrase "Public Global Stellar Network ; September 2015"
- name: Deploy contract to Mainnet
env:
SOROBAN_ACCOUNT: ${{ secrets.SOROBAN_MAINNET_ACCOUNT }}
SOROBAN_SECRET_KEY: ${{ secrets.SOROBAN_MAINNET_SECRET_KEY }}
run: |
soroban contract deploy \
--wasm ./artifacts/predict_iq_optimized.wasm \
--source-account $SOROBAN_ACCOUNT \
--network mainnet
- name: Create deployment artifact
run: |
cat > deployment-info.json <<EOF
{
"environment": "mainnet",
"timestamp": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')",
"commit": "${{ github.sha }}",
"contract_hash": "${{ needs.build-and-test.outputs.contract-hash }}",
"deployed_by": "${{ github.actor }}"
}
EOF
- name: Upload deployment info
uses: actions/upload-artifact@v7
with:
name: mainnet-deployment-${{ github.run_id }}
path: deployment-info.json
retention-days: 90
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: contract-${{ needs.build-and-test.outputs.contract-hash }}
release_name: Contract Deployment ${{ needs.build-and-test.outputs.contract-hash }}
body: |
Mainnet deployment of PredictIQ contract
- Commit: ${{ github.sha }}
- Contract Hash: ${{ needs.build-and-test.outputs.contract-hash }}
- Timestamp: ${{ github.event.head_commit.timestamp }}
draft: false
prerelease: false
version-artifacts:
name: Version and Archive Artifacts
needs: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download WASM artifact
uses: actions/download-artifact@v4
with:
name: contract-wasm
path: ./artifacts
- name: Create versioned artifact
run: |
VERSION=$(git describe --tags --always)
mkdir -p versioned-artifacts
cp ./artifacts/predict_iq_optimized.wasm versioned-artifacts/predict_iq_${VERSION}.wasm
cat > versioned-artifacts/manifest.json <<EOF
{
"version": "${VERSION}",
"commit": "${{ github.sha }}",
"contract_hash": "${{ needs.build-and-test.outputs.contract-hash }}",
"build_timestamp": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')",
"filename": "predict_iq_${VERSION}.wasm"
}
EOF
- name: Upload versioned artifacts
uses: actions/upload-artifact@v7
with:
name: versioned-contract-artifacts
path: versioned-artifacts/
retention-days: 365
notify-deployment:
name: Notify Deployment Status
needs: [build-and-test, deploy-testnet]
runs-on: ubuntu-latest
if: always()
steps:
- name: Determine deployment status
run: |
if [ "${{ needs.deploy-testnet.result }}" == "success" ]; then
echo "DEPLOYMENT_STATUS=✅ Success" >> $GITHUB_ENV
else
echo "DEPLOYMENT_STATUS=❌ Failed" >> $GITHUB_ENV
fi
- name: Send Slack notification
if: vars.SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@v3.0.3
with:
payload: |
{
"text": "Contract Deployment ${{ env.DEPLOYMENT_STATUS }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Contract Deployment ${{ env.DEPLOYMENT_STATUS }}*\n*Commit:* ${{ github.sha }}\n*Contract Hash:* ${{ needs.build-and-test.outputs.contract-hash }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}