climaybe 3.1.4 → 3.3.0
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/README.md +14 -8
- package/bin/version.txt +1 -1
- package/package.json +1 -1
- package/src/index.js +6 -2
- package/src/lib/config.js +17 -0
- package/src/lib/dev-runtime.js +35 -8
- package/src/lib/prompts.js +22 -0
- package/src/lib/serve-multi-store.js +81 -0
- package/src/workflows/preview/cleanup-orphan-preview-themes.yml +59 -0
- package/src/workflows/preview/pr-close.yml +105 -61
- package/src/workflows/preview/pr-update.yml +87 -76
- package/src/workflows/preview/reusable-cleanup-themes.yml +220 -14
- package/src/workflows/preview/reusable-comment-on-pr.yml +83 -19
- package/src/workflows/preview/reusable-publish-pr-preview-store.yml +162 -0
package/README.md
CHANGED
|
@@ -94,7 +94,11 @@ Switch your local dev environment to a specific store (multi-store only).
|
|
|
94
94
|
npx climaybe switch voldt-norway
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
Copies `stores/<alias>/` JSON files to the repo root so you can preview that store locally, and sets `default_store` in `climaybe.config.json` so `climaybe serve` / `shopify theme dev` targets that store. If your current git branch is `staging-<alias>` or `live-<alias>`, `climaybe serve`
|
|
97
|
+
Copies `stores/<alias>/` JSON files to the repo root so you can preview that store locally, and sets `default_store` in `climaybe.config.json` so `climaybe serve` / `shopify theme dev` targets that store. If your current git branch is `staging-<alias>` or `live-<alias>`, `climaybe serve` still passes that branch’s store to Shopify for `--store` (even if `default_store` differs), matching CI preview behavior.
|
|
98
|
+
|
|
99
|
+
### `climaybe serve` / `climaybe theme serve`
|
|
100
|
+
|
|
101
|
+
Runs Tailwind/scripts/schema watchers and `shopify theme dev` (see the theme dev kit section for flags). In **multi-store** mode, the first step asks **which store to serve** (interactive terminal); the default choice is the store matching `default_store` (same as after `climaybe switch`). If you pick a **different** store, the CLI saves the current root `config/`, `templates/`, and `sections/` JSON files into `stores/<previous-alias>/` (same paths as `climaybe sync`), then copies the selected store’s JSONs to the root and updates `default_store`, so work in progress is not lost. In **CI** or when **stdin is not a TTY**, there is no prompt: it uses `default_store` unless you set **`CLIMAYBE_SERVE_STORE=<alias>`** to a configured alias.
|
|
98
102
|
|
|
99
103
|
### `climaybe sync [alias]` / `climaybe theme sync`
|
|
100
104
|
|
|
@@ -227,12 +231,14 @@ Enabled via `climaybe init` prompt (`Enable preview + cleanup workflows?`; defau
|
|
|
227
231
|
|
|
228
232
|
| Workflow | Trigger | What it does |
|
|
229
233
|
|----------|---------|-------------|
|
|
230
|
-
| `pr-update.yml` | PR opened/synchronize/reopened (base: main, staging, develop, staging-*, live-*) | Shares draft theme, renames with `-PR<number>`, comments preview + customize URLs
|
|
231
|
-
| `pr-close.yml` | PR closed (same branch set) | Deletes
|
|
232
|
-
| `
|
|
233
|
-
| `reusable-
|
|
234
|
-
| `reusable-
|
|
235
|
-
| `reusable-
|
|
234
|
+
| `pr-update.yml` | PR opened/synchronize/reopened (base: main, staging, develop, staging-*, live-*) | Shares draft theme, renames with `-PR<number>`, comments preview + customize URLs. **Multi-store + base not** `staging-<alias>` **or** `live-<alias>`**:** publishes to **every** configured store (matrix) and posts **all** links in one PR comment. For `staging-<alias>` / `live-<alias>` bases, only that store is used. **Path filter:** theme paths only (`assets/`, `blocks/`, `config/`, `layout/`, `locales/`, `sections/`, `snippets/`, `templates/`, `_scripts/`, `_styles/`, `shopify.theme.toml`, `stores/**`). |
|
|
235
|
+
| `pr-close.yml` | PR closed (same branch set) | Deletes this PR’s preview themes using the **same store matrix rule** as `pr-update`; PR comment shows **total** deleted count across stores. |
|
|
236
|
+
| `cleanup-orphan-preview-themes.yml` | Weekly (Mon 06:00 UTC) + `workflow_dispatch` | Per store: deletes themes ending with `-PR<n>` when PR `#n` is **not** open (merged/closed without cleanup). Uses `gh pr list` (limit 1000 open PRs). |
|
|
237
|
+
| `reusable-publish-pr-preview-store.yml` | workflow_call | Share + rename + upload comment fragment for **one** store (matrix leg in `pr-update`). |
|
|
238
|
+
| `reusable-share-theme.yml` | workflow_call | Shares Shopify draft theme and returns `theme_id` (still available if you call it elsewhere) |
|
|
239
|
+
| `reusable-rename-theme.yml` | workflow_call | Renames shared theme to include `PR<number>` (still available for custom flows) |
|
|
240
|
+
| `reusable-comment-on-pr.yml` | workflow_call | Posts preview comment; aggregates `preview-fragment-*` artifacts when `use_preview_fragments` is true |
|
|
241
|
+
| `reusable-cleanup-themes.yml` | workflow_call | `cleanup_mode: by_pr` deletes names ending with `-PR{padded}`; `orphan_pr` deletes `-PR<n>` when PR `n` is not open. Optional `result_artifact_prefix` for matrix fan-in on `pr-close` |
|
|
236
242
|
| `reusable-extract-pr-number.yml` | workflow_call | Extracts padded/unpadded PR number outputs for naming and API-safe usage |
|
|
237
243
|
|
|
238
244
|
### Optional build + Lighthouse package
|
|
@@ -374,7 +380,7 @@ Add the following secrets to your GitHub repository (or use **GitLab CI/CD varia
|
|
|
374
380
|
|
|
375
381
|
**Store URL:** During `climaybe init` (or `add-store`), store URL secret(s) are set from your configured store domain(s); theme tokens are optional prompts.
|
|
376
382
|
|
|
377
|
-
**Multi-store:** Per-store secrets `SHOPIFY_STORE_URL_<ALIAS>` and `SHOPIFY_THEME_ACCESS_TOKEN_<ALIAS>` — the URL is set from config; you must provide the theme token per store. `<ALIAS>` is uppercase with hyphens as underscores (e.g. `voldt-norway` → `SHOPIFY_STORE_URL_VOLDT_NORWAY`). Preview
|
|
383
|
+
**Multi-store:** Per-store secrets `SHOPIFY_STORE_URL_<ALIAS>` and `SHOPIFY_THEME_ACCESS_TOKEN_<ALIAS>` — the URL is set from config; you must provide the theme token per store. `<ALIAS>` is uppercase with hyphens as underscores (e.g. `voldt-norway` → `SHOPIFY_STORE_URL_VOLDT_NORWAY`). **Preview:** for PRs targeting **staging-<alias>** or **live-<alias>** only that store is used. For **main**, **staging**, **develop**, or other bases with **multiple** stores in `climaybe.config.json`, **pr-update** publishes the preview theme to **every** store (each must have secrets); **pr-close** cleans that PR’s preview themes on **all** stores. For a **single** store in config, behavior matches the default-store case. Optional **cleanup-orphan-preview-themes** (weekly + manual) removes stale `-PR<n>` themes when PR `n` is no longer open.
|
|
378
384
|
|
|
379
385
|
## Directory Structure (Multi-store)
|
|
380
386
|
|
package/bin/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.3.0
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -64,8 +64,12 @@ function registerThemeCommands(cmd) {
|
|
|
64
64
|
.command('serve')
|
|
65
65
|
.description('Run local theme dev (Shopify + assets; Theme Check off by default)')
|
|
66
66
|
.option('--theme-check', 'Enable Theme Check watcher')
|
|
67
|
-
.action((opts) =>
|
|
68
|
-
|
|
67
|
+
.action(async (opts) => {
|
|
68
|
+
await serveAll({ includeThemeCheck: opts.themeCheck === true });
|
|
69
|
+
});
|
|
70
|
+
cmd.command('serve:shopify').description('Run Shopify theme dev server').action(async () => {
|
|
71
|
+
await serveShopify();
|
|
72
|
+
});
|
|
69
73
|
cmd
|
|
70
74
|
.command('serve:assets')
|
|
71
75
|
.description('Run assets watch (Tailwind + scripts; Theme Check off by default)')
|
package/src/lib/config.js
CHANGED
|
@@ -180,6 +180,23 @@ export function getStoreAliases(cwd = process.cwd()) {
|
|
|
180
180
|
return Object.keys(config.stores);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Resolve the store alias for `default_store` (the domain last set by `climaybe switch` or serve).
|
|
185
|
+
* @param {string} [cwd]
|
|
186
|
+
* @returns {string | null}
|
|
187
|
+
*/
|
|
188
|
+
export function getAliasForDefaultStore(cwd = process.cwd()) {
|
|
189
|
+
const config = readConfig(cwd);
|
|
190
|
+
const domain = config?.default_store;
|
|
191
|
+
const stores = config?.stores;
|
|
192
|
+
if (!domain || !stores || typeof stores !== 'object') return null;
|
|
193
|
+
const normalized = String(domain).trim();
|
|
194
|
+
for (const [alias, storeDomain] of Object.entries(stores)) {
|
|
195
|
+
if (String(storeDomain).trim() === normalized) return alias;
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
183
200
|
/**
|
|
184
201
|
* Determine the current mode: 'single' or 'multi'.
|
|
185
202
|
*/
|
package/src/lib/dev-runtime.js
CHANGED
|
@@ -4,6 +4,7 @@ import { watchTree } from './watch.js';
|
|
|
4
4
|
import { isAbsolute, join, relative } from 'node:path';
|
|
5
5
|
import pc from 'picocolors';
|
|
6
6
|
import { readConfig, getStoreDomainFromBranch } from './config.js';
|
|
7
|
+
import { prepareMultiStoreForServe } from './serve-multi-store.js';
|
|
7
8
|
import { buildScripts } from './build-scripts.js';
|
|
8
9
|
import { buildSchemas } from './schema-builder.js';
|
|
9
10
|
import { runShopify } from './shopify-cli.js';
|
|
@@ -209,7 +210,15 @@ function runThemeCheckFiltered({ cwd = process.cwd() } = {}) {
|
|
|
209
210
|
return child;
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
|
|
213
|
+
/**
|
|
214
|
+
* @param {{ cwd?: string; skipMultiStorePrep?: boolean }} [opts]
|
|
215
|
+
* @returns {Promise<import('node:child_process').ChildProcess | null>} Null when multi-store prep failed or was cancelled.
|
|
216
|
+
*/
|
|
217
|
+
export async function serveShopify({ cwd = process.cwd(), skipMultiStorePrep = false } = {}) {
|
|
218
|
+
if (!skipMultiStorePrep) {
|
|
219
|
+
const ok = await prepareMultiStoreForServe(cwd);
|
|
220
|
+
if (!ok) return null;
|
|
221
|
+
}
|
|
213
222
|
const config = readConfig(cwd) || {};
|
|
214
223
|
const branchStore = getStoreDomainFromBranch(cwd);
|
|
215
224
|
const store = branchStore || config.default_store || config.store || '';
|
|
@@ -232,8 +241,14 @@ export function serveAssets({ cwd = process.cwd(), includeThemeCheck = false } =
|
|
|
232
241
|
writeTaggedLine('tailwind', pc.blue, 'watching _styles/main.css -> assets/style.css');
|
|
233
242
|
}
|
|
234
243
|
|
|
235
|
-
// Optional dev MCP (non-blocking if missing)
|
|
236
|
-
|
|
244
|
+
// Optional dev MCP (non-blocking if missing). @shopify/dev-mcp pulls hydrogen (peers react-router 7.12)
|
|
245
|
+
// alongside react-router 7.13 — npm warns with ERESOLVE unless legacy peer resolution is enabled.
|
|
246
|
+
const devMcpEnv = { ...process.env, npm_config_legacy_peer_deps: 'true' };
|
|
247
|
+
const devMcp = spawnLogged('npx', ['-y', '@shopify/dev-mcp@latest'], {
|
|
248
|
+
name: 'dev-mcp',
|
|
249
|
+
cwd,
|
|
250
|
+
env: devMcpEnv,
|
|
251
|
+
});
|
|
237
252
|
|
|
238
253
|
const scriptsDir = join(cwd, '_scripts');
|
|
239
254
|
if (existsSync(scriptsDir)) {
|
|
@@ -359,16 +374,28 @@ export function serveAssets({ cwd = process.cwd(), includeThemeCheck = false } =
|
|
|
359
374
|
return { tailwind, devMcp, scriptsWatch, schemasWatch, themeCheckWatch, cleanup };
|
|
360
375
|
}
|
|
361
376
|
|
|
362
|
-
export function serveAll({ cwd = process.cwd(), includeThemeCheck = false } = {}) {
|
|
377
|
+
export async function serveAll({ cwd = process.cwd(), includeThemeCheck = false } = {}) {
|
|
378
|
+
const prepOk = await prepareMultiStoreForServe(cwd);
|
|
379
|
+
if (!prepOk) {
|
|
380
|
+
const noop = () => {};
|
|
381
|
+
return { cleanup: noop };
|
|
382
|
+
}
|
|
383
|
+
|
|
363
384
|
// Start assets first, then bring up Shopify after a short delay.
|
|
364
385
|
const assets = serveAssets({ cwd, includeThemeCheck });
|
|
365
386
|
let shopify = null;
|
|
366
387
|
const shopifyStartDelayMs = 2500;
|
|
367
388
|
const shopifyTimer = setTimeout(() => {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
389
|
+
void (async () => {
|
|
390
|
+
shopify = await serveShopify({ cwd, skipMultiStorePrep: true });
|
|
391
|
+
if (shopify) {
|
|
392
|
+
shopify.on('exit', () => {
|
|
393
|
+
cleanup();
|
|
394
|
+
});
|
|
395
|
+
} else {
|
|
396
|
+
cleanup();
|
|
397
|
+
}
|
|
398
|
+
})();
|
|
372
399
|
}, shopifyStartDelayMs);
|
|
373
400
|
console.log(pc.dim(` Waiting ${shopifyStartDelayMs}ms before starting Shopify...`));
|
|
374
401
|
|
package/src/lib/prompts.js
CHANGED
|
@@ -229,6 +229,28 @@ export async function promptProjectName(cwd = process.cwd()) {
|
|
|
229
229
|
return String(projectName || '').trim();
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Ask which store to use for local theme dev (multi-store `climaybe serve`).
|
|
234
|
+
* @param {{ aliases: string[]; stores: Record<string, string>; suggestedAlias: string }} opts
|
|
235
|
+
* @returns {Promise<string | null>} Selected alias, or null if cancelled.
|
|
236
|
+
*/
|
|
237
|
+
export async function promptServeStore({ aliases, stores, suggestedAlias }) {
|
|
238
|
+
const sorted = [...aliases].sort();
|
|
239
|
+
const choices = sorted.map((alias) => ({
|
|
240
|
+
title: `${alias} (${stores[alias]})`,
|
|
241
|
+
value: alias,
|
|
242
|
+
}));
|
|
243
|
+
const initialIndex = sorted.indexOf(suggestedAlias);
|
|
244
|
+
const { alias } = await prompts({
|
|
245
|
+
type: 'select',
|
|
246
|
+
name: 'alias',
|
|
247
|
+
message: 'Which store should we serve?',
|
|
248
|
+
choices,
|
|
249
|
+
initial: initialIndex >= 0 ? initialIndex : 0,
|
|
250
|
+
});
|
|
251
|
+
return alias ?? null;
|
|
252
|
+
}
|
|
253
|
+
|
|
232
254
|
/**
|
|
233
255
|
* Prompt for a single new store (used by add-store command).
|
|
234
256
|
* Takes existing aliases to prevent duplicates.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import { readConfig, getMode, getProjectType, getStoreAliases, writeConfig, getAliasForDefaultStore } from './config.js';
|
|
3
|
+
import { rootToStores, storesToRoot } from './store-sync.js';
|
|
4
|
+
import { promptServeStore } from './prompts.js';
|
|
5
|
+
|
|
6
|
+
function readExplicitServeAlias(cwd) {
|
|
7
|
+
const raw = process.env.CLIMAYBE_SERVE_STORE?.trim();
|
|
8
|
+
if (!raw) return { ok: true, alias: null };
|
|
9
|
+
const aliases = getStoreAliases(cwd);
|
|
10
|
+
if (aliases.includes(raw)) return { ok: true, alias: raw };
|
|
11
|
+
console.log(pc.red(` CLIMAYBE_SERVE_STORE="${raw}" is not a known store alias.`));
|
|
12
|
+
console.log(pc.dim(` Available: ${aliases.join(', ')}\n`));
|
|
13
|
+
return { ok: false, alias: null };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isNonInteractiveServe() {
|
|
17
|
+
if (process.env.CLIMAYBE_SERVE_STORE?.trim()) return true;
|
|
18
|
+
if (process.env.CI === 'true') return true;
|
|
19
|
+
return process.stdin.isTTY !== true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* In multi-store theme repos, ensure root JSONs and `default_store` match the store
|
|
24
|
+
* the user wants to serve. If the choice differs from the previous switch target,
|
|
25
|
+
* saves current root → `stores/<previous>/` then loads `stores/<selected>/` → root.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} [cwd]
|
|
28
|
+
* @returns {Promise<boolean>} False if the user cancelled or `CLIMAYBE_SERVE_STORE` is invalid.
|
|
29
|
+
*/
|
|
30
|
+
export async function prepareMultiStoreForServe(cwd = process.cwd()) {
|
|
31
|
+
if (getProjectType(cwd) === 'app') return true;
|
|
32
|
+
if (getMode(cwd) !== 'multi') return true;
|
|
33
|
+
|
|
34
|
+
const config = readConfig(cwd);
|
|
35
|
+
if (!config?.stores || typeof config.stores !== 'object') return true;
|
|
36
|
+
|
|
37
|
+
const aliases = getStoreAliases(cwd);
|
|
38
|
+
if (aliases.length < 2) return true;
|
|
39
|
+
|
|
40
|
+
const stores = config.stores;
|
|
41
|
+
const suggestedAlias = getAliasForDefaultStore(cwd) ?? aliases[0];
|
|
42
|
+
|
|
43
|
+
const explicit = readExplicitServeAlias(cwd);
|
|
44
|
+
if (!explicit.ok) return false;
|
|
45
|
+
|
|
46
|
+
let selected = explicit.alias;
|
|
47
|
+
if (!selected) {
|
|
48
|
+
if (isNonInteractiveServe()) {
|
|
49
|
+
selected = suggestedAlias;
|
|
50
|
+
} else {
|
|
51
|
+
console.log(pc.bold('\n climaybe — serve (store)\n'));
|
|
52
|
+
selected = await promptServeStore({ aliases, stores, suggestedAlias });
|
|
53
|
+
if (!selected) {
|
|
54
|
+
console.log(pc.dim(' Cancelled.\n'));
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const previousAlias = getAliasForDefaultStore(cwd);
|
|
61
|
+
|
|
62
|
+
if (selected === previousAlias) return true;
|
|
63
|
+
|
|
64
|
+
if (previousAlias) {
|
|
65
|
+
rootToStores(previousAlias, cwd);
|
|
66
|
+
} else {
|
|
67
|
+
console.log(
|
|
68
|
+
pc.yellow(
|
|
69
|
+
' Warning: default_store did not match any store alias; current root JSONs are not auto-saved to a store folder.'
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ok = storesToRoot(selected, cwd);
|
|
75
|
+
if (!ok) return false;
|
|
76
|
+
|
|
77
|
+
const domain = stores[selected];
|
|
78
|
+
if (domain) writeConfig({ default_store: domain }, cwd);
|
|
79
|
+
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# climaybe — Cleanup orphan preview themes (optional)
|
|
2
|
+
# Weekly (and manual): on each configured store, delete themes whose name ends with -PR<n>
|
|
3
|
+
# when PR #n is not open in this repo (merged/closed without theme cleanup).
|
|
4
|
+
|
|
5
|
+
name: Cleanup orphan preview themes
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: '0 6 * * 1'
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
pull-requests: read
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
configure:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
outputs:
|
|
20
|
+
preview_targets_json: ${{ steps.cfg.outputs.preview_targets_json }}
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Build store matrix from climaybe.config.json
|
|
25
|
+
id: cfg
|
|
26
|
+
run: |
|
|
27
|
+
if [ ! -f climaybe.config.json ]; then
|
|
28
|
+
{
|
|
29
|
+
echo 'preview_targets_json<<PT_JSON'
|
|
30
|
+
echo '[]'
|
|
31
|
+
echo 'PT_JSON'
|
|
32
|
+
} >> "$GITHUB_OUTPUT"
|
|
33
|
+
exit 0
|
|
34
|
+
fi
|
|
35
|
+
node <<'NODE' >>"$GITHUB_OUTPUT"
|
|
36
|
+
const fs = require('fs');
|
|
37
|
+
const cfg = JSON.parse(fs.readFileSync('climaybe.config.json', 'utf8'));
|
|
38
|
+
const stores = cfg?.stores || {};
|
|
39
|
+
const keys = Object.keys(stores);
|
|
40
|
+
const aliasToSecret = (a) => String(a).toUpperCase().replace(/-/g, '_');
|
|
41
|
+
const targets = keys.map((alias) => ({ alias, alias_secret: aliasToSecret(alias) }));
|
|
42
|
+
console.log('preview_targets_json<<PT_JSON');
|
|
43
|
+
console.log(JSON.stringify(targets));
|
|
44
|
+
console.log('PT_JSON');
|
|
45
|
+
NODE
|
|
46
|
+
|
|
47
|
+
cleanup-orphans:
|
|
48
|
+
needs: [configure]
|
|
49
|
+
if: needs.configure.outputs.preview_targets_json != '[]'
|
|
50
|
+
strategy:
|
|
51
|
+
fail-fast: false
|
|
52
|
+
matrix:
|
|
53
|
+
include: ${{ fromJson(needs.configure.outputs.preview_targets_json) }}
|
|
54
|
+
uses: ./.github/workflows/reusable-cleanup-themes.yml
|
|
55
|
+
with:
|
|
56
|
+
cleanup_mode: orphan_pr
|
|
57
|
+
pr_number: ''
|
|
58
|
+
store_alias_secret: ${{ matrix.alias_secret }}
|
|
59
|
+
secrets: inherit
|
|
@@ -8,6 +8,10 @@ on:
|
|
|
8
8
|
types: [closed]
|
|
9
9
|
branches: [main, staging, develop, 'staging-*', 'live-*']
|
|
10
10
|
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
pull-requests: write
|
|
14
|
+
|
|
11
15
|
jobs:
|
|
12
16
|
extract-pr-number:
|
|
13
17
|
uses: ./.github/workflows/reusable-extract-pr-number.yml
|
|
@@ -15,72 +19,123 @@ jobs:
|
|
|
15
19
|
resolve-store:
|
|
16
20
|
runs-on: ubuntu-latest
|
|
17
21
|
outputs:
|
|
18
|
-
|
|
22
|
+
store_alias: ${{ steps.resolve.outputs.store_alias }}
|
|
23
|
+
store_alias_secret: ${{ steps.resolve.outputs.store_alias_secret }}
|
|
24
|
+
preview_targets_json: ${{ steps.resolve.outputs.preview_targets_json }}
|
|
19
25
|
steps:
|
|
20
26
|
- name: Checkout code
|
|
21
27
|
uses: actions/checkout@v4
|
|
22
28
|
|
|
23
|
-
- name: Resolve store
|
|
29
|
+
- name: Resolve preview store targets from base branch
|
|
24
30
|
id: resolve
|
|
25
31
|
env:
|
|
26
32
|
BASE_REF: ${{ github.event.pull_request.base.ref }}
|
|
27
33
|
run: |
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
node <<'NODE' >>"$GITHUB_OUTPUT"
|
|
35
|
+
const fs = require('fs');
|
|
36
|
+
const cfg = JSON.parse(fs.readFileSync('climaybe.config.json', 'utf8'));
|
|
37
|
+
const stores = cfg?.stores || {};
|
|
38
|
+
const keys = Object.keys(stores);
|
|
39
|
+
const baseRef = process.env.BASE_REF || '';
|
|
40
|
+
const isMulti = keys.length > 1;
|
|
41
|
+
const isStagingLive =
|
|
42
|
+
baseRef && (/^staging-/.test(baseRef) || /^live-/.test(baseRef));
|
|
43
|
+
|
|
44
|
+
const aliasToSecret = (a) => String(a).toUpperCase().replace(/-/g, '_');
|
|
45
|
+
const normalizeDomain = (v) =>
|
|
46
|
+
String(v || '')
|
|
47
|
+
.toLowerCase()
|
|
48
|
+
.replace(/^https?:\/\//, '')
|
|
49
|
+
.replace(/\/.*$/, '');
|
|
50
|
+
|
|
51
|
+
let targets = [];
|
|
52
|
+
if (isMulti && !isStagingLive) {
|
|
53
|
+
targets = keys.map((alias) => ({ alias, alias_secret: aliasToSecret(alias) }));
|
|
54
|
+
} else if (isStagingLive) {
|
|
55
|
+
let a = baseRef.replace(/^staging-/, '').replace(/^live-/, '');
|
|
56
|
+
targets = [{ alias: a, alias_secret: aliasToSecret(a) }];
|
|
57
|
+
} else {
|
|
58
|
+
const defaultStoreNorm = normalizeDomain(cfg?.default_store);
|
|
59
|
+
let alias = '';
|
|
60
|
+
if (defaultStoreNorm) {
|
|
61
|
+
for (const [k, d] of Object.entries(stores)) {
|
|
62
|
+
if (normalizeDomain(d) === defaultStoreNorm) {
|
|
63
|
+
alias = k;
|
|
64
|
+
break;
|
|
49
65
|
}
|
|
50
66
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
process.stdout.write(alias);
|
|
62
|
-
")
|
|
63
|
-
fi
|
|
67
|
+
}
|
|
68
|
+
if (!alias) alias = keys[0] || '';
|
|
69
|
+
if (!alias && cfg?.default_store) {
|
|
70
|
+
const sub = normalizeDomain(cfg.default_store).split('.')[0] || 'default';
|
|
71
|
+
alias = sub.replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-') || 'default';
|
|
72
|
+
}
|
|
73
|
+
if (!alias) alias = 'default';
|
|
74
|
+
targets = [{ alias, alias_secret: aliasToSecret(alias) }];
|
|
75
|
+
}
|
|
64
76
|
|
|
65
|
-
if
|
|
66
|
-
|
|
67
|
-
exit
|
|
68
|
-
|
|
77
|
+
if (targets.length === 0 || targets.some((t) => !t.alias)) {
|
|
78
|
+
console.error('Could not resolve store targets from climaybe.config.json');
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
console.log('preview_targets_json<<PT_JSON');
|
|
83
|
+
console.log(JSON.stringify(targets));
|
|
84
|
+
console.log('PT_JSON');
|
|
85
|
+
console.log(`store_alias=${targets[0].alias}`);
|
|
86
|
+
console.log(`store_alias_secret=${targets[0].alias_secret}`);
|
|
87
|
+
NODE
|
|
73
88
|
|
|
74
89
|
cleanup-theme:
|
|
75
90
|
needs: [extract-pr-number, resolve-store]
|
|
91
|
+
strategy:
|
|
92
|
+
fail-fast: false
|
|
93
|
+
matrix:
|
|
94
|
+
include: ${{ fromJson(needs.resolve-store.outputs.preview_targets_json) }}
|
|
76
95
|
uses: ./.github/workflows/reusable-cleanup-themes.yml
|
|
77
96
|
with:
|
|
97
|
+
cleanup_mode: by_pr
|
|
78
98
|
pr_number: ${{ needs.extract-pr-number.outputs.pr_number }}
|
|
79
|
-
store_alias_secret: ${{
|
|
99
|
+
store_alias_secret: ${{ matrix.alias_secret }}
|
|
100
|
+
result_artifact_prefix: pr-close-cleanup
|
|
80
101
|
secrets: inherit
|
|
81
102
|
|
|
103
|
+
cleanup-totals:
|
|
104
|
+
needs: [cleanup-theme]
|
|
105
|
+
if: always()
|
|
106
|
+
runs-on: ubuntu-latest
|
|
107
|
+
permissions:
|
|
108
|
+
actions: read
|
|
109
|
+
outputs:
|
|
110
|
+
deleted_count: ${{ steps.sum.outputs.deleted_count }}
|
|
111
|
+
steps:
|
|
112
|
+
- name: Download cleanup result fragments
|
|
113
|
+
continue-on-error: true
|
|
114
|
+
uses: actions/download-artifact@v4
|
|
115
|
+
with:
|
|
116
|
+
pattern: pr-close-cleanup-*
|
|
117
|
+
merge-multiple: true
|
|
118
|
+
path: cleanup-counts
|
|
119
|
+
|
|
120
|
+
- name: Sum deleted themes across stores
|
|
121
|
+
id: sum
|
|
122
|
+
run: |
|
|
123
|
+
total=0
|
|
124
|
+
if [ -d cleanup-counts ]; then
|
|
125
|
+
while IFS= read -r -d '' f; do
|
|
126
|
+
[ -z "$f" ] && continue
|
|
127
|
+
[ ! -f "$f" ] && continue
|
|
128
|
+
n="$(tr -d ' \n\r' < "$f" 2>/dev/null || echo 0)"
|
|
129
|
+
n="${n:-0}"
|
|
130
|
+
total=$((total + n))
|
|
131
|
+
done < <(find cleanup-counts -name 'deleted-count.txt' -type f -print0 2>/dev/null || true)
|
|
132
|
+
fi
|
|
133
|
+
echo "deleted_count=$total" >> "$GITHUB_OUTPUT"
|
|
134
|
+
echo "Total deleted across stores: $total"
|
|
135
|
+
|
|
82
136
|
comment-on-pr:
|
|
83
|
-
needs: cleanup-
|
|
137
|
+
needs: [cleanup-totals, resolve-store]
|
|
138
|
+
if: always()
|
|
84
139
|
runs-on: ubuntu-latest
|
|
85
140
|
steps:
|
|
86
141
|
- name: Comment on PR about cleanup
|
|
@@ -88,8 +143,8 @@ jobs:
|
|
|
88
143
|
with:
|
|
89
144
|
script: |
|
|
90
145
|
const prNumber = context.payload.pull_request.number;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
146
|
+
const storeAlias = '${{ needs.resolve-store.outputs.store_alias }}' || '';
|
|
147
|
+
const deletedCount = parseInt('${{ needs.cleanup-totals.outputs.deleted_count }}') || 0;
|
|
93
148
|
|
|
94
149
|
const lines = [
|
|
95
150
|
'## 🧹 Theme Cleanup Complete',
|
|
@@ -98,20 +153,9 @@ jobs:
|
|
|
98
153
|
'',
|
|
99
154
|
`**Branch:** ${context.payload.pull_request.head.ref}`,
|
|
100
155
|
`**PR Status:** ${context.payload.pull_request.state}`,
|
|
101
|
-
`**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (deletedCount > 0 && deletedThemesRaw) {
|
|
105
|
-
const deletedThemeLines = deletedThemesRaw
|
|
106
|
-
.split('\n')
|
|
107
|
-
.map(name => name.trim())
|
|
108
|
-
.filter(Boolean)
|
|
109
|
-
.map(name => `- ${name}`);
|
|
110
|
-
|
|
111
|
-
if (deletedThemeLines.length > 0) {
|
|
112
|
-
lines.push('', '### Deleted Theme Names', ...deletedThemeLines);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
156
|
+
storeAlias ? `**Primary store (config):** ${storeAlias}` : null,
|
|
157
|
+
`**Deleted themes (all preview stores):** ${deletedCount}`
|
|
158
|
+
].filter(Boolean);
|
|
115
159
|
|
|
116
160
|
lines.push('', '---', '*Theme cleanup runs automatically when a PR is closed.*');
|
|
117
161
|
|