@scrymore/scry-deployer 0.6.1 → 0.7.0-next.20260926193255

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/lib/templates.js CHANGED
@@ -57,32 +57,87 @@ function getCacheValue(packageManager) {
57
57
  }
58
58
 
59
59
  /**
60
- * Generate main deployment workflow
60
+ * The deployer version range every generated workflow installs.
61
+ *
62
+ * A floor, not a pin and not @latest: every 0.x fix, never a version without
63
+ * the "nothing will be indexed" guards (0.7.0), never a surprise major. The
64
+ * repo's own package.json cannot lower it, because the deployer is installed
65
+ * into its own folder (ISSUES.md #50: a repo pinned to 0.2.2 ran it for seven
66
+ * weeks through a bare `npx @scrymore/scry-deployer`).
67
+ */
68
+ const DEPLOYER_RANGE = '^0.7.0';
69
+
70
+ /**
71
+ * Where the deployer is installed on the runner: outside the checkout, so
72
+ * `npm i` never touches a pnpm or yarn node_modules and the repo's lockfile
73
+ * or pin cannot choose the version. Shell form for `run:`, expression form
74
+ * for `working-directory:`.
61
75
  */
76
+ const TOOLS_DIR_SHELL = '"$RUNNER_TEMP/scry"';
77
+ const TOOLS_DIR_EXPR = '${{ runner.temp }}/scry';
78
+ const DEPLOYER_BIN = '"$RUNNER_TEMP/scry/node_modules/.bin/scry-deployer"';
79
+
62
80
  /**
63
- * The command that fetches and runs a package that is not a project dependency.
81
+ * Steps that install the deployer, then the browser its analyzer drives.
64
82
  *
65
- * `npx` cannot be assumed. In a pnpm workflow it resolves against the
66
- * pnpm-managed environment and reports "playwright: not found" — exit 127 —
67
- * even with --yes. Each package manager has its own equivalent, so use it.
83
+ * Order matters. The browser is installed by the Playwright inside the
84
+ * deployer's own dependency tree (the one scry-sbcov loads), after the
85
+ * deployer exists. A floating `npx playwright install` before it resolved
86
+ * whatever Playwright was newest (or the repo's own) and could fetch a
87
+ * browser build the analyzer does not look for; every story then failed, no
88
+ * metadata was written and nothing was indexed (scry-link #44).
89
+ *
90
+ * Package-manager independent on purpose: npm ships with setup-node, and the
91
+ * install goes to a separate prefix, so pnpm, yarn and bun repos get the same
92
+ * steps.
68
93
  */
69
- function getDlxCommand(packageManager) {
70
- switch (packageManager) {
71
- case 'pnpm': return 'pnpm dlx';
72
- case 'yarn': return 'yarn dlx';
73
- default: return 'npx --yes';
74
- }
94
+ function getDeployerSetupSteps() {
95
+ return ` - name: Install the Scry deployer
96
+ id: scry
97
+ # Its own folder and a floor of ${DEPLOYER_RANGE}: the repo's own pin cannot pick an older deployer.
98
+ # --ignore-scripts: nothing in its tree needs an install script, and none runs next to the checkout's token.
99
+ run: |
100
+ set -o pipefail
101
+ mkdir -p ${TOOLS_DIR_SHELL}
102
+ npm i --no-save --no-audit --no-fund --ignore-scripts --prefix ${TOOLS_DIR_SHELL} @scrymore/scry-deployer@${DEPLOYER_RANGE}
103
+ cd ${TOOLS_DIR_SHELL}
104
+ echo "version=$(node -p "require('@scrymore/scry-deployer/package.json').version")" >> "$GITHUB_OUTPUT"
105
+ PW="$(npx --no-install playwright --version | awk '{print $2}')"
106
+ [ -n "$PW" ] || { echo "::error::the deployer's Playwright was not found in $RUNNER_TEMP/scry"; exit 1; }
107
+ echo "playwright=$PW" >> "$GITHUB_OUTPUT"
108
+
109
+ - name: Cache the deployer's Playwright browser
110
+ uses: actions/cache@v4
111
+ with:
112
+ path: ~/.cache/ms-playwright
113
+ key: scry-pw-\${{ runner.os }}-\${{ steps.scry.outputs.playwright }}
114
+
115
+ - name: Install the deployer's Playwright browser
116
+ # The deployer's own Playwright, so the browser build is the one its
117
+ # analyzer launches. Without it every story fails and nothing is indexed.
118
+ working-directory: ${TOOLS_DIR_EXPR}
119
+ run: npx --no-install playwright install --with-deps chromium-headless-shell
120
+ `;
75
121
  }
76
122
 
123
+ /** Deployer flags shared by both workflows. */
124
+ const COMMON_FLAGS = ` \${{ vars.SCRY_COVERAGE_ENABLED == 'false' && '--no-coverage' || '' }} \\
125
+ \${{ vars.SCRY_COVERAGE_FAIL_ON_THRESHOLD == 'true' && '--coverage-fail-on-threshold' || '' }} \\
126
+ \${{ vars.SCRY_COVERAGE_EXECUTE == 'false' && '' || '--coverage-execute' }} \\
127
+ --with-analysis \\`;
128
+
129
+ /**
130
+ * Generate main deployment workflow
131
+ */
77
132
  function generateMainWorkflow(projectId, apiUrl, packageManager, buildCmd) {
78
133
  const pmSetup = getPackageManagerSetup(packageManager);
79
134
  const installCmd = getInstallCommand(packageManager);
80
135
  const cache = getCacheValue(packageManager);
81
136
  const runCmd = packageManager === 'npm' ? `npm run ${buildCmd}` : `${packageManager} run ${buildCmd}`;
82
- const dlx = getDlxCommand(packageManager);
83
137
 
84
138
  return `# Auto-generated by Scry Storybook Deployer
85
139
  # Deploy Storybook to production on push to main branch
140
+ # Regenerate with: npx -y @scrymore/scry-deployer@${DEPLOYER_RANGE} update-workflows
86
141
 
87
142
  name: Deploy Storybook
88
143
 
@@ -99,7 +154,7 @@ jobs:
99
154
  uses: actions/checkout@v4
100
155
  with:
101
156
  fetch-depth: 0 # Required for coverage new-code analysis
102
-
157
+
103
158
  ${pmSetup} - name: Setup Node.js
104
159
  uses: actions/setup-node@v4
105
160
  with:
@@ -112,29 +167,20 @@ ${cache}
112
167
  - name: Build Storybook
113
168
  run: ${runCmd}
114
169
 
115
- - name: Install Playwright browser
116
- # Screenshot capture drives --with-analysis, and without a browser every
117
- # story fails, no metadata archive is produced, and nothing is ever
118
- # indexed — while the deploy still exits 0 and the workflow goes green.
119
- # Chromium headless shell only: a few seconds, versus minutes for the
120
- # full browser set.
121
- # The version is left floating so it tracks sbcov's own playwright
122
- # ^1.41.0 optional dependency and installs a matching browser build.
123
- run: ${dlx} playwright install --with-deps chromium-headless-shell
124
-
170
+ ${getDeployerSetupSteps()}
125
171
  - name: Deploy to Scry
172
+ # Exits 1 when the build was asked to index and nothing will be indexed.
126
173
  run: |
127
- npx @scrymore/scry-deployer \\
174
+ ${DEPLOYER_BIN} \\
128
175
  --dir ./storybook-static \\
129
- \${{ vars.SCRY_COVERAGE_ENABLED == 'false' && '--no-coverage' || '' }} \\
130
- \${{ vars.SCRY_COVERAGE_FAIL_ON_THRESHOLD == 'true' && '--coverage-fail-on-threshold' || '' }} \\
131
- \${{ vars.SCRY_COVERAGE_EXECUTE == 'false' && '' || '--coverage-execute' }} \\
132
- --with-analysis \\
176
+ ${COMMON_FLAGS}
133
177
  --coverage-base \${{ vars.SCRY_COVERAGE_BASE || github.event.before }}
134
178
  env:
135
179
  STORYBOOK_DEPLOYER_API_URL: \${{ vars.SCRY_API_URL }}
136
180
  STORYBOOK_DEPLOYER_PROJECT: \${{ vars.SCRY_PROJECT_ID }}
137
181
  STORYBOOK_DEPLOYER_API_KEY: \${{ secrets.SCRY_API_KEY }}
182
+ # Optional: stories allowed to fail capture before the deploy ends red (default 0).
183
+ SCRY_MAX_DROPPED: \${{ vars.SCRY_MAX_DROPPED }}
138
184
  GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
139
185
  `;
140
186
  }
@@ -147,19 +193,26 @@ function generatePRWorkflow(projectId, apiUrl, packageManager, buildCmd) {
147
193
  const installCmd = getInstallCommand(packageManager);
148
194
  const cache = getCacheValue(packageManager);
149
195
  const runCmd = packageManager === 'npm' ? `npm run ${buildCmd}` : `${packageManager} run ${buildCmd}`;
150
- const dlx = getDlxCommand(packageManager);
151
196
 
152
197
  return `# Auto-generated by Scry Storybook Deployer
153
198
  # Deploy Storybook preview for pull requests
199
+ # Regenerate with: npx -y @scrymore/scry-deployer@${DEPLOYER_RANGE} update-workflows
154
200
 
155
201
  name: Deploy Storybook PR Preview
156
202
 
157
203
  on:
158
204
  pull_request:
159
- types: [opened, synchronize, reopened]
205
+ types: [opened, synchronize, reopened, ready_for_review]
206
+
207
+ # One preview per PR: a new push cancels the run it replaces.
208
+ concurrency:
209
+ group: storybook-pr-\${{ github.event.pull_request.number }}
210
+ cancel-in-progress: true
160
211
 
161
212
  jobs:
162
213
  deploy-preview:
214
+ # Drafts are skipped; marking the PR ready for review deploys it.
215
+ if: github.event.pull_request.draft == false
163
216
  runs-on: ubuntu-latest
164
217
 
165
218
  permissions:
@@ -171,7 +224,7 @@ jobs:
171
224
  uses: actions/checkout@v4
172
225
  with:
173
226
  fetch-depth: 0 # Required for coverage new-code analysis
174
-
227
+
175
228
  ${pmSetup} - name: Setup Node.js
176
229
  uses: actions/setup-node@v4
177
230
  with:
@@ -184,30 +237,17 @@ ${cache}
184
237
  - name: Build Storybook
185
238
  run: ${runCmd}
186
239
 
187
- - name: Install Playwright browser
188
- # Screenshot capture drives --with-analysis, and without a browser every
189
- # story fails, no metadata archive is produced, and nothing is ever
190
- # indexed — while the deploy still exits 0 and the workflow goes green.
191
- # Chromium headless shell only: a few seconds, versus minutes for the
192
- # full browser set.
193
- # The version is left floating so it tracks sbcov's own playwright
194
- # ^1.41.0 optional dependency and installs a matching browser build.
195
- run: ${dlx} playwright install --with-deps chromium-headless-shell
196
-
240
+ ${getDeployerSetupSteps()}
197
241
  - name: Deploy Preview
198
242
  id: deploy
243
+ # Exits 1 when the build was asked to index and nothing will be indexed.
199
244
  run: |
200
- # Deploy with PR-specific version
201
- npx @scrymore/scry-deployer \\
245
+ ${DEPLOYER_BIN} \\
202
246
  --dir ./storybook-static \\
203
247
  --version pr-\${{ github.event.pull_request.number }} \\
204
- \${{ github.event.pull_request.draft == true && '--no-coverage' || '' }} \\
205
- \${{ vars.SCRY_COVERAGE_ENABLED == 'false' && '--no-coverage' || '' }} \\
206
- \${{ vars.SCRY_COVERAGE_FAIL_ON_THRESHOLD == 'true' && '--coverage-fail-on-threshold' || '' }} \\
207
- \${{ vars.SCRY_COVERAGE_EXECUTE == 'false' && '' || '--coverage-execute' }} \\
208
- --with-analysis \\
248
+ ${COMMON_FLAGS}
209
249
  --coverage-base \${{ vars.SCRY_COVERAGE_BASE || format('origin/{0}', github.base_ref) }}
210
-
250
+
211
251
  # Construct deployment URL using VIEW_URL (where users access the deployed Storybook)
212
252
  # Defaults to https://view.scrymore.com if SCRY_VIEW_URL is not set
213
253
  PROJECT_ID="\${{ vars.SCRY_PROJECT_ID }}"
@@ -218,11 +258,14 @@ ${cache}
218
258
  STORYBOOK_DEPLOYER_API_URL: \${{ vars.SCRY_API_URL }}
219
259
  STORYBOOK_DEPLOYER_PROJECT: \${{ vars.SCRY_PROJECT_ID }}
220
260
  STORYBOOK_DEPLOYER_API_KEY: \${{ secrets.SCRY_API_KEY }}
261
+ # Optional: stories allowed to fail capture before the deploy ends red (default 0).
262
+ SCRY_MAX_DROPPED: \${{ vars.SCRY_MAX_DROPPED }}
221
263
  GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
222
264
  `;
223
265
  }
224
266
 
225
267
  module.exports = {
226
268
  generateMainWorkflow,
227
- generatePRWorkflow
269
+ generatePRWorkflow,
270
+ DEPLOYER_RANGE,
228
271
  };
@@ -1,8 +1,8 @@
1
1
  const { createLogger } = require('./logger');
2
- const { generateMainWorkflow, generatePRWorkflow } = require('./templates');
2
+ const { generateMainWorkflow, generatePRWorkflow, DEPLOYER_RANGE } = require('./templates');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
- const { execSync } = require('child_process');
5
+ const { execSync, execFileSync } = require('child_process');
6
6
 
7
7
  /**
8
8
  * Upgrade-only workflow generator.
@@ -41,6 +41,8 @@ async function runUpdateWorkflows(argv) {
41
41
 
42
42
  logger.success(`✅ Updated ${mainWorkflowPath}`);
43
43
  logger.success(`✅ Updated ${prWorkflowPath}`);
44
+ logger.info(` Package manager: ${envInfo.packageManager}; Storybook build script: ${buildCmd}${envInfo.storybookBuildCmd ? '' : ' (not found in package.json; the default name was used, check it)'}`);
45
+ logger.info(` The deployer is installed at @scrymore/scry-deployer@${DEPLOYER_RANGE} in its own folder with its own Playwright browser.`);
44
46
 
45
47
  if (argv.commit) {
46
48
  gitAdd([mainWorkflowPath, prWorkflowPath], logger);
@@ -89,7 +91,7 @@ async function checkEnvironment() {
89
91
  function gitAdd(files, logger) {
90
92
  for (const file of files) {
91
93
  if (fs.existsSync(file)) {
92
- execSync(`git add "${file}"`, { stdio: 'pipe' });
94
+ execFileSync('git', ['add', '--', file], { stdio: 'pipe' });
93
95
  logger.debug(` ✓ Added ${file}`);
94
96
  }
95
97
  }
@@ -102,9 +104,10 @@ function gitCommit(message, logger) {
102
104
  return;
103
105
  }
104
106
 
105
- execSync(`git commit -m "${message}"`, { stdio: 'pipe' });
107
+ // execFile, not a shell string: the message is user input.
108
+ execFileSync('git', ['commit', '-m', String(message)], { stdio: 'pipe' });
106
109
  const sha = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
107
110
  logger.success(`✅ Committed workflow update: ${sha}`);
108
111
  }
109
112
 
110
- module.exports = { runUpdateWorkflows };
113
+ module.exports = { runUpdateWorkflows, checkEnvironment };
@@ -0,0 +1,112 @@
1
+ const axios = require('axios');
2
+
3
+ const PACKAGE_NAME = '@scrymore/scry-deployer';
4
+ const REGISTRY_LATEST_URL = 'https://registry.npmjs.org/@scrymore%2fscry-deployer/latest';
5
+ const DEFAULT_TIMEOUT_MS = 2000;
6
+
7
+ /**
8
+ * Parse "x.y.z" (optionally with a -prerelease / +build suffix) into numbers.
9
+ * @param {string} v
10
+ * @returns {{core:number[], pre:boolean}|null}
11
+ */
12
+ function parseVersion(v) {
13
+ const m = /^v?(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/.exec(String(v || '').trim());
14
+ if (!m) return null;
15
+ return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: Boolean(m[4]) };
16
+ }
17
+
18
+ /**
19
+ * True when `running` is older than `latest`. A prerelease of the same core
20
+ * version (0.7.0-next.x against 0.7.0) counts as older; a prerelease of a
21
+ * newer core (0.7.0-next.x against 0.6.1) does not.
22
+ */
23
+ function isOlder(running, latest) {
24
+ const a = parseVersion(running);
25
+ const b = parseVersion(latest);
26
+ if (!a || !b) return false;
27
+ for (let i = 0; i < 3; i++) {
28
+ if (a.core[i] !== b.core[i]) return a.core[i] < b.core[i];
29
+ }
30
+ return a.pre && !b.pre;
31
+ }
32
+
33
+ /**
34
+ * Compare the running deployer with npm `latest` and warn when it is behind.
35
+ *
36
+ * Advisory only: it never throws and never changes the exit code. 0.2.2 ran
37
+ * for seven weeks after the "NOTHING WILL BE INDEXED" guard shipped, printing
38
+ * "Deployment successful" over empty builds, because nothing told it it was
39
+ * stale (ISSUES.md #50).
40
+ *
41
+ * Skipped with SCRY_NO_UPDATE_CHECK=1. A registry that does not answer within
42
+ * the timeout, or answers something unreadable, is reported in one info line
43
+ * and the deploy continues.
44
+ *
45
+ * @param {{currentVersion:string, logger:{warn:Function,info:Function,debug:Function}, env?:object, timeoutMs?:number, fetchLatest?:Function}} opts
46
+ * @returns {Promise<{status:'behind'|'current'|'skipped'|'unknown', latest?:string, reason?:string}>}
47
+ */
48
+ async function checkForNewerVersion(opts) {
49
+ const {
50
+ currentVersion,
51
+ logger,
52
+ env = process.env,
53
+ timeoutMs = DEFAULT_TIMEOUT_MS,
54
+ fetchLatest = defaultFetchLatest,
55
+ } = opts;
56
+
57
+ if (env.SCRY_NO_UPDATE_CHECK === '1' || env.SCRY_NO_UPDATE_CHECK === 'true') {
58
+ logger.debug('Version check skipped (SCRY_NO_UPDATE_CHECK)');
59
+ return { status: 'skipped', reason: 'SCRY_NO_UPDATE_CHECK' };
60
+ }
61
+
62
+ let latest;
63
+ try {
64
+ latest = await withTimeout(fetchLatest(timeoutMs), timeoutMs);
65
+ } catch (err) {
66
+ const reason = err && err.message ? err.message : String(err);
67
+ logger.info(`ℹ️ Could not check for a newer scry-deployer (${reason}); continuing.`);
68
+ return { status: 'unknown', reason };
69
+ }
70
+
71
+ if (!parseVersion(latest)) {
72
+ logger.info(`ℹ️ Could not check for a newer scry-deployer (registry answered ${JSON.stringify(latest)}); continuing.`);
73
+ return { status: 'unknown', reason: 'unreadable registry answer' };
74
+ }
75
+
76
+ if (isOlder(currentVersion, latest)) {
77
+ logger.warn(
78
+ `⚠️ scry-deployer ${currentVersion} is running; ${latest} is current. ` +
79
+ 'Older versions can report success while indexing nothing.'
80
+ );
81
+ return { status: 'behind', latest };
82
+ }
83
+ logger.debug(`scry-deployer ${currentVersion} is current (npm latest ${latest})`);
84
+ return { status: 'current', latest };
85
+ }
86
+
87
+ async function defaultFetchLatest(timeoutMs) {
88
+ const res = await axios.get(REGISTRY_LATEST_URL, {
89
+ timeout: timeoutMs,
90
+ headers: { Accept: 'application/json' },
91
+ // No credentials, no proxy config from the project: this is a public read.
92
+ validateStatus: (s) => s === 200,
93
+ });
94
+ return res.data && res.data.version;
95
+ }
96
+
97
+ function withTimeout(promise, ms) {
98
+ let timer;
99
+ const timeout = new Promise((_, reject) => {
100
+ timer = setTimeout(() => reject(new Error(`no answer from npm in ${ms} ms`)), ms);
101
+ if (typeof timer.unref === 'function') timer.unref();
102
+ });
103
+ return Promise.race([Promise.resolve(promise), timeout]).finally(() => clearTimeout(timer));
104
+ }
105
+
106
+ module.exports = {
107
+ checkForNewerVersion,
108
+ isOlder,
109
+ parseVersion,
110
+ PACKAGE_NAME,
111
+ REGISTRY_LATEST_URL,
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrymore/scry-deployer",
3
- "version": "0.6.1",
3
+ "version": "0.7.0-next.20260926193255",
4
4
  "description": "A CLI to automate the deployment of Storybook static builds.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ // Rewrites templates/workflows/*.yml from lib/templates.js (npm, build-storybook).
3
+ // These copies are documentation only (not shipped); test/templates.test.js
4
+ // fails when they drift from the generator, which is how they went stale
5
+ // before (ISSUES.md #50).
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { generateMainWorkflow, generatePRWorkflow } = require('../lib/templates.js');
9
+
10
+ const dir = path.join(__dirname, '..', 'templates', 'workflows');
11
+ const files = {
12
+ 'deploy-storybook.yml': generateMainWorkflow('', '', 'npm', 'build-storybook'),
13
+ 'deploy-pr-preview.yml': generatePRWorkflow('', '', 'npm', 'build-storybook'),
14
+ };
15
+
16
+ if (require.main === module) {
17
+ for (const [name, body] of Object.entries(files)) {
18
+ fs.writeFileSync(path.join(dir, name), body, 'utf8');
19
+ console.log(`wrote templates/workflows/${name}`);
20
+ }
21
+ }
22
+
23
+ module.exports = { files, dir };