seqpulse 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CI_CD_SNIPPETS_MULTI-PLATFORM.md +66 -27
- package/README.md +13 -4
- package/index.js +11 -1
- package/package.json +1 -1
|
@@ -6,7 +6,11 @@ Snippets de reference pour integrer `SeqPulse` avec la meme logique sur plusieur
|
|
|
6
6
|
2. deploy applicatif
|
|
7
7
|
3. `finish` toujours execute, meme en cas d'echec
|
|
8
8
|
|
|
9
|
-
Tous les snippets ci-dessous utilisent le package publie `seqpulse@0.5.
|
|
9
|
+
Tous les snippets ci-dessous utilisent le package publie `seqpulse@0.5.2` et une logique defensive:
|
|
10
|
+
|
|
11
|
+
- `trigger` avec `--timeout-ms 15000`
|
|
12
|
+
- capture du `deploymentId` dans une variable CI
|
|
13
|
+
- `finish` execute seulement si un vrai `deploymentId` existe
|
|
10
14
|
|
|
11
15
|
## Variables requises
|
|
12
16
|
|
|
@@ -53,10 +57,11 @@ jobs:
|
|
|
53
57
|
- name: SeqPulse Trigger
|
|
54
58
|
id: seqpulse_trigger
|
|
55
59
|
run: |
|
|
56
|
-
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.
|
|
60
|
+
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.2 ci trigger \
|
|
57
61
|
--env prod \
|
|
58
62
|
--branch "${GITHUB_REF_NAME}" \
|
|
59
63
|
--non-blocking true \
|
|
64
|
+
--timeout-ms 15000 \
|
|
60
65
|
--output deploymentId)"
|
|
61
66
|
echo "deployment_id=${DEPLOYMENT_ID}" >> "$GITHUB_OUTPUT"
|
|
62
67
|
|
|
@@ -66,10 +71,15 @@ jobs:
|
|
|
66
71
|
- name: SeqPulse Finish
|
|
67
72
|
if: ${{ always() }}
|
|
68
73
|
run: |
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
if [ -n "${{ steps.seqpulse_trigger.outputs.deployment_id }}" ]; then
|
|
75
|
+
npx -y seqpulse@0.5.2 ci finish \
|
|
76
|
+
--deployment-id "${{ steps.seqpulse_trigger.outputs.deployment_id }}" \
|
|
77
|
+
--job-status "${{ job.status }}" \
|
|
78
|
+
--timeout-ms 15000 \
|
|
79
|
+
--non-blocking true
|
|
80
|
+
else
|
|
81
|
+
echo "Skipping SeqPulse finish: no deployment id available."
|
|
82
|
+
fi
|
|
73
83
|
```
|
|
74
84
|
|
|
75
85
|
## GitLab CI
|
|
@@ -81,20 +91,26 @@ deploy_prod:
|
|
|
81
91
|
script:
|
|
82
92
|
- npm ci
|
|
83
93
|
- |
|
|
84
|
-
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.
|
|
94
|
+
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.2 ci trigger \
|
|
85
95
|
--env prod \
|
|
86
96
|
--branch "${CI_COMMIT_REF_NAME}" \
|
|
87
97
|
--non-blocking true \
|
|
98
|
+
--timeout-ms 15000 \
|
|
88
99
|
--output deploymentId)"
|
|
89
100
|
printf 'SEQPULSE_DEPLOYMENT_ID=%s\n' "$DEPLOYMENT_ID" > .seqpulse.env
|
|
90
101
|
- ./deploy.sh
|
|
91
102
|
after_script:
|
|
92
103
|
- . ./.seqpulse.env 2>/dev/null || true
|
|
93
104
|
- |
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
if [ -n "${SEQPULSE_DEPLOYMENT_ID}" ]; then
|
|
106
|
+
npx -y seqpulse@0.5.2 ci finish \
|
|
107
|
+
--deployment-id "${SEQPULSE_DEPLOYMENT_ID}" \
|
|
108
|
+
--job-status "${CI_JOB_STATUS}" \
|
|
109
|
+
--timeout-ms 15000 \
|
|
110
|
+
--non-blocking true
|
|
111
|
+
else
|
|
112
|
+
echo "Skipping SeqPulse finish: no deployment id available."
|
|
113
|
+
fi
|
|
98
114
|
```
|
|
99
115
|
|
|
100
116
|
## CircleCI
|
|
@@ -116,10 +132,11 @@ jobs:
|
|
|
116
132
|
- run:
|
|
117
133
|
name: SeqPulse Trigger
|
|
118
134
|
command: |
|
|
119
|
-
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.
|
|
135
|
+
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.2 ci trigger \
|
|
120
136
|
--env prod \
|
|
121
137
|
--branch "${CIRCLE_BRANCH}" \
|
|
122
138
|
--non-blocking true \
|
|
139
|
+
--timeout-ms 15000 \
|
|
123
140
|
--output deploymentId)"
|
|
124
141
|
echo "export SEQPULSE_DEPLOYMENT_ID=${DEPLOYMENT_ID}" >> "$BASH_ENV"
|
|
125
142
|
|
|
@@ -141,10 +158,15 @@ jobs:
|
|
|
141
158
|
when: always
|
|
142
159
|
command: |
|
|
143
160
|
. "$BASH_ENV"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
if [ -n "${SEQPULSE_DEPLOYMENT_ID}" ]; then
|
|
162
|
+
npx -y seqpulse@0.5.2 ci finish \
|
|
163
|
+
--deployment-id "${SEQPULSE_DEPLOYMENT_ID}" \
|
|
164
|
+
--job-status "${SEQPULSE_JOB_STATUS:-failed}" \
|
|
165
|
+
--timeout-ms 15000 \
|
|
166
|
+
--non-blocking true
|
|
167
|
+
else
|
|
168
|
+
echo "Skipping SeqPulse finish: no deployment id available."
|
|
169
|
+
fi
|
|
148
170
|
```
|
|
149
171
|
|
|
150
172
|
## Jenkins
|
|
@@ -176,17 +198,28 @@ pipeline {
|
|
|
176
198
|
stage('SeqPulse Trigger') {
|
|
177
199
|
steps {
|
|
178
200
|
script {
|
|
179
|
-
def branch = env.CHANGE_BRANCH ?: env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'main'
|
|
180
|
-
|
|
201
|
+
def branch = (env.CHANGE_BRANCH ?: env.BRANCH_NAME ?: env.GIT_BRANCH ?: 'main')
|
|
202
|
+
.replaceFirst(/^origin\//, '')
|
|
203
|
+
def triggerRaw = sh(
|
|
181
204
|
script: """
|
|
182
|
-
npx -y seqpulse@0.5.
|
|
205
|
+
npx -y seqpulse@0.5.2 ci trigger \
|
|
183
206
|
--env prod \
|
|
184
207
|
--branch "${branch}" \
|
|
185
208
|
--non-blocking true \
|
|
186
|
-
--
|
|
209
|
+
--timeout-ms 15000 \
|
|
210
|
+
--output json
|
|
187
211
|
""",
|
|
188
212
|
returnStdout: true
|
|
189
213
|
).trim()
|
|
214
|
+
|
|
215
|
+
def triggerResult = new groovy.json.JsonSlurperClassic().parseText(triggerRaw ?: "{}")
|
|
216
|
+
if (triggerResult?.ok && triggerResult?.deploymentId) {
|
|
217
|
+
env.SEQPULSE_DEPLOYMENT_ID = String.valueOf(triggerResult.deploymentId)
|
|
218
|
+
echo "SeqPulse trigger accepted for deployment ${env.SEQPULSE_DEPLOYMENT_ID}"
|
|
219
|
+
} else {
|
|
220
|
+
env.SEQPULSE_DEPLOYMENT_ID = ''
|
|
221
|
+
echo "SeqPulse trigger skipped: ${triggerResult?.error ?: 'unknown error'}"
|
|
222
|
+
}
|
|
190
223
|
}
|
|
191
224
|
}
|
|
192
225
|
}
|
|
@@ -202,12 +235,17 @@ pipeline {
|
|
|
202
235
|
always {
|
|
203
236
|
script {
|
|
204
237
|
def jobStatus = (currentBuild.currentResult ?: 'SUCCESS').toLowerCase()
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
238
|
+
if (env.SEQPULSE_DEPLOYMENT_ID?.trim()) {
|
|
239
|
+
sh """
|
|
240
|
+
npx -y seqpulse@0.5.2 ci finish \
|
|
241
|
+
--deployment-id "${env.SEQPULSE_DEPLOYMENT_ID}" \
|
|
242
|
+
--job-status "${jobStatus}" \
|
|
243
|
+
--timeout-ms 15000 \
|
|
244
|
+
--non-blocking true
|
|
245
|
+
"""
|
|
246
|
+
} else {
|
|
247
|
+
echo 'Skipping SeqPulse finish: no deployment id available.'
|
|
248
|
+
}
|
|
211
249
|
}
|
|
212
250
|
}
|
|
213
251
|
}
|
|
@@ -216,6 +254,7 @@ pipeline {
|
|
|
216
254
|
|
|
217
255
|
## Notes pratiques
|
|
218
256
|
|
|
219
|
-
- Si le package est deja installe dans le projet, vous pouvez remplacer `npx -y seqpulse@0.5.
|
|
257
|
+
- Si le package est deja installe dans le projet, vous pouvez remplacer `npx -y seqpulse@0.5.2` par `npx seqpulse`.
|
|
258
|
+
- Pour Jenkins, preferer `--output json` si vous voulez logguer clairement un `trigger skipped`.
|
|
220
259
|
- Pour les deploys `prod`, ajoutez un gate explicite sur `main`/tag si votre pipeline est multi-branches.
|
|
221
260
|
- Le pattern recommande est toujours le meme: `trigger -> deploy -> finish`.
|
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ seqpulse.init({
|
|
|
27
27
|
hmacSecret: process.env.SEQPULSE_HMAC_SECRET,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
// Note: hmacEnabled accepts booleans or strings ("true"/"false").
|
|
31
|
+
|
|
30
32
|
app.use(seqpulse.metrics());
|
|
31
33
|
|
|
32
34
|
app.get("/", (_req, res) => res.send("ok"));
|
|
@@ -85,14 +87,20 @@ async function runDeployment() {
|
|
|
85
87
|
|
|
86
88
|
```bash
|
|
87
89
|
# Trigger
|
|
88
|
-
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.
|
|
90
|
+
DEPLOYMENT_ID="$(npx -y seqpulse@0.5.2 ci trigger \
|
|
89
91
|
--env prod \
|
|
92
|
+
--timeout-ms 15000 \
|
|
90
93
|
--output deploymentId)"
|
|
91
94
|
|
|
92
95
|
# Finish
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
if [ -n "$DEPLOYMENT_ID" ]; then
|
|
97
|
+
npx -y seqpulse@0.5.2 ci finish \
|
|
98
|
+
--deployment-id "$DEPLOYMENT_ID" \
|
|
99
|
+
--job-status "$JOB_STATUS" \
|
|
100
|
+
--timeout-ms 15000
|
|
101
|
+
else
|
|
102
|
+
echo "Skipping SeqPulse finish: no deployment id available."
|
|
103
|
+
fi
|
|
96
104
|
```
|
|
97
105
|
|
|
98
106
|
Notes:
|
|
@@ -101,6 +109,7 @@ Notes:
|
|
|
101
109
|
- `--github-output` ecrit `deployment_id`, `status`, `http_status`.
|
|
102
110
|
- mode par defaut: non-bloquant (`--non-blocking true`).
|
|
103
111
|
- pour mode strict: `--blocking`.
|
|
112
|
+
- pour CI distante, `--timeout-ms 15000` est recommande.
|
|
104
113
|
|
|
105
114
|
## Documentation
|
|
106
115
|
|
package/index.js
CHANGED
|
@@ -71,6 +71,16 @@ function buildSignature(secret, timestamp, method, path, nonce) {
|
|
|
71
71
|
return `sha256=${digest}`;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
function toBoolean(value) {
|
|
75
|
+
if (typeof value === "boolean") return value;
|
|
76
|
+
if (typeof value === "string") {
|
|
77
|
+
const normalized = value.trim().toLowerCase();
|
|
78
|
+
if (["true", "1", "yes", "on"].includes(normalized)) return true;
|
|
79
|
+
if (["false", "0", "no", "off", ""].includes(normalized)) return false;
|
|
80
|
+
}
|
|
81
|
+
return Boolean(value);
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
function rejectHmac(res, message) {
|
|
75
85
|
res.status(401).json({ error: message || "Unauthorized" });
|
|
76
86
|
}
|
|
@@ -149,7 +159,7 @@ function init(config) {
|
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
const endpoint = canonicalizePath(config.endpoint || DEFAULT_ENDPOINT);
|
|
152
|
-
const hmacEnabled =
|
|
162
|
+
const hmacEnabled = toBoolean(config.hmacEnabled);
|
|
153
163
|
const hmacSecret = String(config.hmacSecret || "");
|
|
154
164
|
|
|
155
165
|
if (hmacEnabled && !hmacSecret) {
|