файл пакета→ .shtukbase/packages/blueprint-software-factory/actions/nightly.ts
actions/nightly.ts
49 строк, 2.6 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // `shtuk run blueprint-software-factory nightly` (the action /actions/sf-nightly-check of the nightly automation):
- // runs the test command from /base/software-factory.md and every check of the project (what `shtuk check` runs).
- // Red: opens the alarm of watch `nightly` (one open at a time) and exits 1, so the run is `failed`. Green: closes an
- // open `nightly` alarm and exits 0.
- import { spawnSync } from 'node:child_process';
- import { findings, runChecks } from '../../hooks/lib/hooklib.ts';
- import { factory, pkgAction, str } from '../lib/factory.ts';
- const root = process.cwd();
- const WATCH = 'nightly';
- const BY = '/automations/sf-nightly-check';
- const tail = (s: string, n: number) => s.trimEnd().split('\n').slice(-n).join('\n');
- const test = str(factory(root).test);
- let testsOk = true;
- let testOut = '';
- if (!test) console.log('tests: no command — write test into the head of /base/software-factory.md');
- else {
- const t0 = Date.now();
- const r = spawnSync('sh', ['-c', test], { cwd: root, encoding: 'utf8', timeout: 20 * 60_000, maxBuffer: 64 * 1024 * 1024 });
- testOut = `${r.stdout ?? ''}${r.stderr ?? ''}`;
- testsOk = !r.error && r.status === 0;
- console.log(`tests: ${test} → ${testsOk ? 'green' : `red (code ${r.status ?? r.error?.message})`}, ${Math.round((Date.now() - t0) / 100) / 10} s`);
- console.log(tail(testOut, 40));
- }
- const results = runChecks(root);
- const red = findings(results);
- console.log(`checks: ${results.length}, red ${results.filter((r) => !r.ok).length}`);
- if (red.length) console.log(red.slice(0, 40).join('\n'));
- if (testsOk && !red.length) {
- const c = pkgAction('alarms', 'actions/close.ts', ['--watch', WATCH, '--by', `${BY}: the run is green again`]);
- if (c.stdout?.trim()) console.log(`alarm closed: ${c.stdout.trim()}`);
- console.log('result: green');
- process.exit(0);
- }
- const what = [!testsOk ? 'tests failed' : '', red.length ? `red checks ${results.filter((r) => !r.ok).length}` : ''].filter(Boolean).join(', ');
- const body = [
- `Nightly run: ${what}.`, '',
- ...(testsOk ? [] : ['Tests (the tail of the output):', '', '```', tail(testOut, 30), '```', '']),
- ...(red.length ? ['Checks:', '', ...red.slice(0, 20).map((l) => `- ${l}`), ''] : []),
- 'To sort out: the tester — /actions/sf-triage-failure.md; the full log is in the run of this night in /runs.',
- ].join('\n');
- const a = pkgAction('alarms', 'actions/raise.ts', ['--watch', WATCH, '--title', `The nightly run is red: ${what}`, '--by', BY, '--severity', testsOk ? 'slows' : 'stops', '--body', body]);
- console.log(`alarm: ${a.stdout?.trim() || a.stderr?.trim()}`);
- console.log(`result: red — ${what}`);
- process.exit(1);