ShtukbaseStandard
файл пакета→ .shtukbase/packages/blueprint-software-factory/actions/nightly.ts

actions/nightly.ts

49 строк, 2.6 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // `shtuk run blueprint-software-factory nightly` (the action /actions/sf-nightly-check of the nightly automation):
  2. // runs the test command from /base/software-factory.md and every check of the project (what `shtuk check` runs).
  3. // Red: opens the alarm of watch `nightly` (one open at a time) and exits 1, so the run is `failed`. Green: closes an
  4. // open `nightly` alarm and exits 0.
  5. import { spawnSync } from 'node:child_process';
  6. import { findings, runChecks } from '../../hooks/lib/hooklib.ts';
  7. import { factory, pkgAction, str } from '../lib/factory.ts';
  8. const root = process.cwd();
  9. const WATCH = 'nightly';
  10. const BY = '/automations/sf-nightly-check';
  11. const tail = (s: string, n: number) => s.trimEnd().split('\n').slice(-n).join('\n');
  12. const test = str(factory(root).test);
  13. let testsOk = true;
  14. let testOut = '';
  15. if (!test) console.log('tests: no command — write test into the head of /base/software-factory.md');
  16. else {
  17. const t0 = Date.now();
  18. const r = spawnSync('sh', ['-c', test], { cwd: root, encoding: 'utf8', timeout: 20 * 60_000, maxBuffer: 64 * 1024 * 1024 });
  19. testOut = `${r.stdout ?? ''}${r.stderr ?? ''}`;
  20. testsOk = !r.error && r.status === 0;
  21. console.log(`tests: ${test} → ${testsOk ? 'green' : `red (code ${r.status ?? r.error?.message})`}, ${Math.round((Date.now() - t0) / 100) / 10} s`);
  22. console.log(tail(testOut, 40));
  23. }
  24. const results = runChecks(root);
  25. const red = findings(results);
  26. console.log(`checks: ${results.length}, red ${results.filter((r) => !r.ok).length}`);
  27. if (red.length) console.log(red.slice(0, 40).join('\n'));
  28. if (testsOk && !red.length) {
  29. const c = pkgAction('alarms', 'actions/close.ts', ['--watch', WATCH, '--by', `${BY}: the run is green again`]);
  30. if (c.stdout?.trim()) console.log(`alarm closed: ${c.stdout.trim()}`);
  31. console.log('result: green');
  32. process.exit(0);
  33. }
  34. const what = [!testsOk ? 'tests failed' : '', red.length ? `red checks ${results.filter((r) => !r.ok).length}` : ''].filter(Boolean).join(', ');
  35. const body = [
  36. `Nightly run: ${what}.`, '',
  37. ...(testsOk ? [] : ['Tests (the tail of the output):', '', '```', tail(testOut, 30), '```', '']),
  38. ...(red.length ? ['Checks:', '', ...red.slice(0, 20).map((l) => `- ${l}`), ''] : []),
  39. 'To sort out: the tester — /actions/sf-triage-failure.md; the full log is in the run of this night in /runs.',
  40. ].join('\n');
  41. const a = pkgAction('alarms', 'actions/raise.ts', ['--watch', WATCH, '--title', `The nightly run is red: ${what}`, '--by', BY, '--severity', testsOk ? 'slows' : 'stops', '--body', body]);
  42. console.log(`alarm: ${a.stdout?.trim() || a.stderr?.trim()}`);
  43. console.log(`result: red — ${what}`);
  44. process.exit(1);