-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathJenkinsfile
More file actions
129 lines (121 loc) · 4.38 KB
/
Copy pathJenkinsfile
File metadata and controls
129 lines (121 loc) · 4.38 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
pipeline {
agent any
options {
disableConcurrentBuilds()
timestamps()
timeout(time: 45, unit: 'MINUTES')
}
parameters {
choice(name: 'ACTION', choices: ['verify', 'deploy', 'rollback'], description: 'Pipeline action')
choice(name: 'TARGET_ENVIRONMENT', choices: ['staging', 'production'], description: 'Deployment target')
string(name: 'WASM_PATH', defaultValue: '', description: 'Optional: path to compiled WASM for contract tests')
string(name: 'CONTRACT_ID', defaultValue: '', description: 'Optional: contract ID for post-deploy monitoring')
}
stages {
stage('Quality gate') {
steps {
sh '''#!/usr/bin/env bash
set -euo pipefail
rustup component add rustfmt clippy
cargo fmt --all --check
cargo build --locked
cargo clippy --all-features --locked -- -D warnings
cargo test --test cli_smoke --locked
git diff --exit-code Cargo.lock
'''
}
}
stage('Contract tests') {
steps {
sh '''#!/usr/bin/env bash
set -euo pipefail
cargo test --locked -- --test-threads=1
'''
}
}
stage('Contract lint & audit') {
when { expression { params.WASM_PATH != '' } }
steps {
sh '''#!/usr/bin/env bash
set -euo pipefail
cargo build --locked --release
./target/release/starforge lint --wasm "$WASM_PATH" || true
./target/release/starforge audit --wasm "$WASM_PATH" --output json > audit-results.json || true
'''
archiveArtifacts artifacts: 'audit-results.json', allowEmptyArchive: true
}
}
stage('Deploy or rollback') {
when { expression { params.ACTION != 'verify' } }
steps {
script {
if (params.TARGET_ENVIRONMENT == 'production') {
input message: "Approve production ${params.ACTION}?", ok: 'Approve'
}
}
withCredentials([
string(credentialsId: 'starforge-deploy-command', variable: 'STARFORGE_DEPLOY_COMMAND'),
string(credentialsId: 'starforge-rollback-command', variable: 'STARFORGE_ROLLBACK_COMMAND'),
string(credentialsId: 'starforge-healthcheck-url', variable: 'STARFORGE_HEALTHCHECK_URL'),
string(credentialsId: 'starforge-notify-webhook', variable: 'STARFORGE_NOTIFY_WEBHOOK')
]) {
sh '''#!/usr/bin/env bash
set -euo pipefail
export STARFORGE_DEPLOY_ENVIRONMENT="$TARGET_ENVIRONMENT"
export STARFORGE_NOTIFY_ACTOR="${BUILD_USER:-Jenkins}"
export STARFORGE_NOTIFY_URL="${BUILD_URL}"
if [ "$TARGET_ENVIRONMENT" = production ]; then
export STARFORGE_DEPLOY_APPROVED=true STARFORGE_ROLLBACK_APPROVED=true
fi
if [ "$ACTION" = deploy ]; then
bash scripts/ci-deploy.sh
else
bash scripts/ci-rollback.sh
fi
'''
}
}
}
stage('Post-deploy monitoring') {
when {
allOf {
expression { params.ACTION == 'deploy' }
expression { params.CONTRACT_ID != '' }
}
}
steps {
sh '''#!/usr/bin/env bash
set -euo pipefail
./target/release/starforge inspect state "$CONTRACT_ID" \
--network "${TARGET_ENVIRONMENT == 'production' ? 'mainnet' : 'testnet'}" \
--json > monitor-snapshot.json || true
'''
archiveArtifacts artifacts: 'monitor-snapshot.json', allowEmptyArchive: true
}
}
}
post {
success {
withCredentials([string(credentialsId: 'starforge-notify-webhook', variable: 'STARFORGE_NOTIFY_WEBHOOK')]) {
sh '''#!/usr/bin/env bash
STARFORGE_NOTIFY_STATUS=success \
STARFORGE_NOTIFY_ENV="$TARGET_ENVIRONMENT" \
STARFORGE_NOTIFY_ACTOR="${BUILD_USER:-Jenkins}" \
STARFORGE_NOTIFY_URL="$BUILD_URL" \
bash scripts/ci-notify.sh || true
'''
}
}
failure {
withCredentials([string(credentialsId: 'starforge-notify-webhook', variable: 'STARFORGE_NOTIFY_WEBHOOK')]) {
sh '''#!/usr/bin/env bash
STARFORGE_NOTIFY_STATUS=failure \
STARFORGE_NOTIFY_ENV="$TARGET_ENVIRONMENT" \
STARFORGE_NOTIFY_ACTOR="${BUILD_USER:-Jenkins}" \
STARFORGE_NOTIFY_URL="$BUILD_URL" \
bash scripts/ci-notify.sh || true
'''
}
}
}
}