From cbe449e3704fd594de0acf6b4a598e16698d6cff Mon Sep 17 00:00:00 2001
From: HyuuNyackman <107097515+HyuuNyackman@users.noreply.github.com>
Date: Sun, 29 Nov 2026 22:30:22 +0900
Subject: [PATCH 1/3] =?UTF-8?q?[xcl-193]=20feat:=20=E3=83=AA=E3=83=AA?=
=?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=20PR=20=E3=81=AE=E8=A6=81=E7=B4=84?=
=?UTF-8?q?=E3=81=A8=E3=83=9E=E3=83=BC=E3=82=AB=E3=83=BC=E3=81=AE=E5=B7=AE?=
=?UTF-8?q?=E3=81=97=E6=9B=BF=E3=81=88=E3=81=AE=E3=82=B9=E3=82=AF=E3=83=AA?=
=?UTF-8?q?=E3=83=97=E3=83=88=E3=82=92=E8=B6=B3=E3=81=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
scripts/ci/release-summary.mjs | 309 +++++++++++++++++++++
scripts/ci/release-summary.test.mjs | 240 ++++++++++++++++
scripts/ci/update-summary-section.mjs | 35 +++
scripts/ci/update-summary-section.test.mjs | 31 +++
templates/.github/release-summary.json | 17 ++
5 files changed, 632 insertions(+)
create mode 100644 scripts/ci/release-summary.mjs
create mode 100644 scripts/ci/release-summary.test.mjs
create mode 100644 scripts/ci/update-summary-section.mjs
create mode 100644 scripts/ci/update-summary-section.test.mjs
create mode 100644 templates/.github/release-summary.json
diff --git a/scripts/ci/release-summary.mjs b/scripts/ci/release-summary.mjs
new file mode 100644
index 0000000..a81e3c7
--- /dev/null
+++ b/scripts/ci/release-summary.mjs
@@ -0,0 +1,309 @@
+// リリースの PR (develop → main) に載せる、確認事項の要約を作る。
+//
+// node release-summary.mjs
[設定ファイル] Markdown を標準出力に出す
+//
+// 人が見るべき点を、変更されたファイルの種類から機械的に選ぶ。文章の要約はしない
+// (毎回同じ基準で、ローカルでテストでき、利用枠も使わないため)。
+// リポジトリに固有の点 (Issue のキー、マイグレーション、認証のパスなど) は設定ファイルで渡す。
+// 設定ファイルがなければ、汎用の部分 (Issue、ワークフロー、依存) だけを出す。形は docs/SETUP.md。
+import { execFileSync } from 'node:child_process';
+import { existsSync, readFileSync } from 'node:fs';
+import { pathToFileURL } from 'node:url';
+
+// ===== 設定 =====
+
+export const DEFAULT_DEPENDENCY_FILES = [
+ 'package.json',
+ 'package-lock.json',
+ 'pnpm-lock.yaml',
+ 'yarn.lock',
+ 'bun.lock',
+];
+
+const CONFIG_KEYS = {
+ issueKey: 'string',
+ migrations: 'object',
+ authPaths: 'array',
+ configFiles: 'array',
+ dependencyFiles: 'array',
+ checks: 'array',
+ sections: 'array',
+};
+
+// 設定のオブジェクトを確かめ、既定の値で埋める。null は設定ファイルなし。
+export function normalizeConfig(raw) {
+ const config = raw ?? {};
+ if (typeof config !== 'object' || Array.isArray(config)) throw new Error('設定はオブジェクトにする');
+ for (const [key, value] of Object.entries(config)) {
+ const type = CONFIG_KEYS[key];
+ if (!type) throw new Error(`設定に知らないキーがある: ${key}`);
+ const actual = Array.isArray(value) ? 'array' : typeof value;
+ if (actual !== type) throw new Error(`設定の ${key} は ${type} にする`);
+ }
+ const strings = (key) => {
+ const list = config[key] ?? [];
+ if (!list.every((s) => typeof s === 'string')) throw new Error(`設定の ${key} は文字列の配列にする`);
+ return list;
+ };
+ if (config.issueKey !== undefined && !/^[A-Za-z][A-Za-z0-9]*$/.test(config.issueKey)) {
+ throw new Error('設定の issueKey は英数字にする (例: ABC)');
+ }
+ let migrations = null;
+ if (config.migrations) {
+ const { dir, riskySql = true, ...rest } = config.migrations;
+ if (Object.keys(rest).length) throw new Error(`設定の migrations に知らないキーがある: ${Object.keys(rest)}`);
+ if (typeof dir !== 'string' || dir === '') throw new Error('設定の migrations.dir は文字列にする');
+ if (typeof riskySql !== 'boolean') throw new Error('設定の migrations.riskySql は true か false にする');
+ migrations = { dir: dir.replace(/\/+$/, ''), riskySql };
+ }
+ const sections = config.sections ?? [];
+ for (const s of sections) {
+ if (typeof s?.title !== 'string' || typeof s?.body !== 'string') {
+ throw new Error('設定の sections は { "title": 文字列, "body": 文字列 } の配列にする');
+ }
+ }
+ return {
+ issueKey: config.issueKey?.toUpperCase() ?? null,
+ migrations,
+ authPaths: strings('authPaths'),
+ configFiles: strings('configFiles'),
+ dependencyFiles: config.dependencyFiles ? strings('dependencyFiles') : DEFAULT_DEPENDENCY_FILES,
+ checks: strings('checks'),
+ sections,
+ };
+}
+
+// パスのパターン: `/` で終われば、その下のすべて。`*` は `/` 以外の 0 文字以上、`**` は `/` を含む 0 文字以上。
+export function matchPath(pattern, path) {
+ if (pattern.endsWith('/')) return path.startsWith(pattern);
+ const source = pattern
+ .split(/(\*\*\/?|\*)/)
+ .map((part) => {
+ if (part === '**/') return '(?:.*/)?';
+ if (part === '**') return '.*';
+ if (part === '*') return '[^/]*';
+ return part.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
+ })
+ .join('');
+ return new RegExp(`^${source}$`).test(path);
+}
+
+// ===== 含まれる Issue =====
+
+const TYPES = 'feat|fix|docs|style|refactor|perf|test|build|ci|chore';
+
+// キーがあれば、件名のどこかの `ABC-12`・`abc-12` を拾う。
+// なければ、先頭の `[abc-12]` か `ABC-12` だけを拾う (`utf-8` のような語を拾わないため)。
+export function parseIssues(subjects, issueKey = null) {
+ const issues = new Map();
+ for (const subject of subjects) {
+ let match;
+ if (issueKey) {
+ match = subject.match(new RegExp(`\\b(${issueKey}|${issueKey.toLowerCase()})-(\\d+)\\b`));
+ } else {
+ match = subject.match(/^\[([a-z][a-z0-9]*)-(\d+)\]/) ?? subject.match(/^([A-Z][A-Z0-9]*)-(\d+)\b/);
+ }
+ if (!match) continue;
+ const id = `${match[1].toUpperCase()}-${match[2]}`;
+ const pr = subject.match(/\(#(\d+)\)\s*$/)?.[1];
+ const title = subject
+ .replace(/^\[[^\]]+\]\s*/, '') // [abc-12] を除く
+ .replace(/^[A-Za-z][A-Za-z0-9]*-\d+\s*/, '') // ABC-12 を除く
+ .replace(new RegExp(`^(?:${TYPES})(?:\\([^)]*\\))?:\\s*`), '')
+ .replace(/\s*\(#\d+\)\s*$/, '');
+ if (!issues.has(id)) issues.set(id, { title, prs: [] });
+ if (pr) issues.get(id).prs.push(pr);
+ }
+ return issues;
+}
+
+// ===== マイグレーション =====
+
+// 破壊的、または、データに依存して失敗しうる SQL。
+const RISKY = [
+ [
+ /\bdrop\s+(table|column|schema|policy|function|trigger|index|view|type|constraint)\b/i,
+ '削除 (drop)',
+ ],
+ [/\btruncate\b/i, 'truncate'],
+ [/\bdelete\s+from\b/i, 'delete'],
+ [/\balter\s+table\b[^;]*\balter\s+column\b[^;]*\btype\b/i, '列の型の変更'],
+ [/\brename\s+(to|column)\b/i, '名前の変更 (rename)'],
+ [/\bset\s+not\s+null\b/i, 'not null の追加 (既存の行が違反すると失敗する)'],
+ [/\badd\s+constraint\b/i, '制約の追加 (既存の行が違反すると失敗する)'],
+ [/\bdisable\s+row\s+level\s+security\b/i, 'RLS の無効化'],
+ [
+ /\bgrant\s+(all|insert|update|delete|truncate)\b[^;]*\bto\b[^;]*\b(anon|public)\b/i,
+ 'anon / public への書き込み系の権限の付与',
+ ],
+];
+
+// コメントの行を除いて見る。
+export function riskySql(sql) {
+ const code = sql
+ .split('\n')
+ .filter((line) => !line.trim().startsWith('--'))
+ .join('\n');
+ return RISKY.filter(([pattern]) => pattern.test(code)).map(([, label]) => label);
+}
+
+// ===== 要約 =====
+
+// subjects: base に無く head にある、コミットの件名。
+// changes: 共通の祖先からの変更ファイル ({ status: 'A' | 'M' | 'D' | ..., path })。
+// readHead(path): head での中身。diffOf(path): `git diff -U0` の出力。
+export function buildSummary({ subjects, changes, readHead, diffOf, config: rawConfig = null }) {
+ const config = normalizeConfig(rawConfig);
+ const paths = (predicate) => changes.filter((c) => predicate(c.path));
+ const matchesAny = (patterns) => (p) => patterns.some((pattern) => matchPath(pattern, p));
+
+ const issues = parseIssues(subjects, config.issueKey);
+
+ let addedMigrations = [];
+ let touchedExisting = [];
+ const warnings = [];
+ if (config.migrations) {
+ const { dir, riskySql: check } = config.migrations;
+ const migrations = paths((p) => p.startsWith(`${dir}/`) && p.endsWith('.sql'));
+ addedMigrations = migrations.filter((c) => c.status === 'A');
+ touchedExisting = migrations.filter((c) => c.status !== 'A');
+ if (check) {
+ for (const { path } of addedMigrations) {
+ for (const label of riskySql(readHead(path))) warnings.push(`\`${path}\`: ${label}`);
+ }
+ }
+ }
+
+ const workflows = paths((p) => p.startsWith('.github/'));
+ const deps = paths(matchesAny(config.dependencyFiles));
+ const configs = paths(matchesAny(config.configFiles));
+ const authAndRls = paths(matchesAny(config.authPaths));
+
+ const depLines = deps
+ .filter((c) => c.status !== 'D' && /(^|\/)package\.json$/.test(c.path))
+ .flatMap((c) => diffOf(c.path).split('\n'))
+ .filter((l) => /^[+-]\s+"[^"]+":/.test(l))
+ .slice(0, 30);
+
+ const list = (items) => items.map((c) => `\`${c.path}\``).join('、');
+ const lines = [];
+ const out = (line = '') => lines.push(line);
+
+ out('## リリースの確認事項');
+ out();
+ out(`${subjects.length} 件のコミット、${changes.length} 個のファイルの変更を、本番に反映する。`);
+ out();
+
+ out('### 含まれる Issue');
+ out();
+ if (issues.size === 0) {
+ out('- (件名から Issue を読み取れたものはなし)');
+ } else {
+ for (const [id, { title, prs }] of issues) {
+ const refs = prs.length ? ` (${prs.map((n) => `#${n}`).join(', ')})` : '';
+ out(`- ${id} ${title}${refs}`);
+ }
+ }
+ out();
+
+ if (warnings.length > 0) {
+ out('### ⚠️ 破壊的、またはデータに依存して失敗しうる SQL');
+ out();
+ for (const w of warnings) out(`- ${w}`);
+ out();
+ out('マージすると、本番の DB に適用される。内容を読んでから、バックアップを取ること。');
+ out();
+ }
+
+ out('### 確認すること');
+ out();
+ const checks = [];
+ if (addedMigrations.length > 0) {
+ checks.push(
+ `**マイグレーション (${addedMigrations.length} 件)**: ${list(addedMigrations)}。内容を読み、本番の DB のバックアップを取ってから、マージする。`,
+ );
+ }
+ if (touchedExisting.length > 0) {
+ checks.push(
+ `**⚠️ 既存のマイグレーションが変更・削除されている**: ${list(touchedExisting)}。適用済みの履歴は変えてはいけない。意図したものか確かめる。`,
+ );
+ }
+ if (authAndRls.length > 0) {
+ checks.push(`**認証・RLS に関わる変更**: ${list(authAndRls)}。ログインとアクセス制御を試す。`);
+ }
+ if (deps.length > 0) {
+ checks.push(
+ `**依存・スクリプトの変更**: ${list(deps)}。` +
+ (depLines.length
+ ? `\n \`\`\`diff\n${depLines.map((l) => ` ${l}`).join('\n')}\n \`\`\``
+ : ''),
+ );
+ }
+ if (workflows.length > 0) {
+ checks.push(`**CI・ワークフローの変更**: ${list(workflows)}。意図したものか確かめる。`);
+ }
+ if (configs.length > 0) {
+ checks.push(`**設定ファイルの変更**: ${list(configs)}。本番の設定との差がないか確かめる。`);
+ }
+ if (checks.length === 0) {
+ checks.push('特に注意が必要な領域の変更はない。画面の動作を確かめる。');
+ }
+ checks.push(...config.checks);
+ for (const c of checks) out(`- [ ] ${c}`);
+
+ for (const { title, body } of config.sections) {
+ out();
+ out(`### ${title}`);
+ out();
+ out(body.trim());
+ }
+
+ return `${lines.join('\n')}\n`;
+}
+
+// ===== git から集める =====
+
+export function collect(base, head, { cwd } = {}) {
+ const git = (...args) =>
+ execFileSync('git', args, { cwd, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
+ const subjects = git('log', '--format=%s', `${base}..${head}`).split('\n').filter(Boolean);
+ const changes = git('diff', '--name-status', '--no-renames', `${base}...${head}`)
+ .split('\n')
+ .filter(Boolean)
+ .map((line) => {
+ const [status, ...rest] = line.split('\t');
+ return { status, path: rest.join('\t') };
+ });
+ return {
+ subjects,
+ changes,
+ readHead: (path) => git('show', `${head}:${path}`),
+ diffOf: (path) => git('diff', '--no-color', '-U0', `${base}...${head}`, '--', path),
+ };
+}
+
+export function readConfig(file) {
+ if (!file || !existsSync(file)) return null;
+ try {
+ return JSON.parse(readFileSync(file, 'utf8'));
+ } catch (error) {
+ throw new Error(`設定ファイル ${file} を読めない: ${error.message}`);
+ }
+}
+
+function main() {
+ const [base, head, configFile] = process.argv.slice(2);
+ if (!base || !head) {
+ console.error('使い方: release-summary.mjs [設定ファイル]');
+ process.exit(1);
+ }
+ try {
+ const config = readConfig(configFile);
+ process.stdout.write(buildSummary({ ...collect(base, head), config }));
+ } catch (error) {
+ console.error(error.message);
+ process.exit(1);
+ }
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) main();
diff --git a/scripts/ci/release-summary.test.mjs b/scripts/ci/release-summary.test.mjs
new file mode 100644
index 0000000..75c161c
--- /dev/null
+++ b/scripts/ci/release-summary.test.mjs
@@ -0,0 +1,240 @@
+// node --test scripts/ci/ で実行する。
+import assert from 'node:assert/strict';
+import { execFileSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import { fileURLToPath } from 'node:url';
+
+import {
+ buildSummary,
+ collect,
+ matchPath,
+ normalizeConfig,
+ parseIssues,
+ readConfig,
+ riskySql,
+} from './release-summary.mjs';
+
+const SUPABASE = {
+ issueKey: 'ABC',
+ migrations: { dir: 'supabase/migrations', riskySql: true },
+ authPaths: ['src/features/auth/', 'supabase/tests/', '**/*rls*'],
+ configFiles: ['supabase/config.toml', 'app.json'],
+ dependencyFiles: ['package.json', 'pnpm-lock.yaml'],
+ checks: ['統合後の状態を、Preview で確かめた'],
+ sections: [{ title: '確認用アカウント', body: '確認は、確認用のアカウントだけで行う。' }],
+};
+
+function summary({ subjects = [], changes = [], files = {}, diffs = {}, config = null }) {
+ return buildSummary({
+ subjects,
+ changes: changes.map(([status, path]) => ({ status, path })),
+ readHead: (path) => files[path] ?? '',
+ diffOf: (path) => diffs[path] ?? '',
+ config,
+ });
+}
+
+test('設定ファイルなし: Issue の一覧、ワークフローと依存の変更だけが出る', () => {
+ const md = summary({
+ subjects: ['[abc-12] feat: ログイン画面を追加', 'ABC-13 投稿の修正 (#34)', 'utf-8 の扱いを直す'],
+ changes: [
+ ['M', '.github/workflows/ci.yml'],
+ ['M', 'package.json'],
+ ['A', 'supabase/migrations/001_drop.sql'],
+ ['M', 'src/features/auth/login.ts'],
+ ['M', 'app.json'],
+ ],
+ files: { 'supabase/migrations/001_drop.sql': 'drop table posts;' },
+ diffs: { 'package.json': '+ "zod": "^4.0.0",\n- "yup": "^1.0.0",' },
+ });
+ assert.match(md, /3 件のコミット、5 個のファイルの変更/);
+ assert.match(md, /^- ABC-12 ログイン画面を追加$/m);
+ assert.match(md, /^- ABC-13 投稿の修正 \(#34\)$/m);
+ assert.doesNotMatch(md, /UTF-8/);
+ assert.match(md, /CI・ワークフローの変更\*\*: `\.github\/workflows\/ci\.yml`/);
+ assert.match(md, /依存・スクリプトの変更\*\*: `package\.json`/);
+ assert.match(md, /\+ {4}"zod"/);
+ assert.doesNotMatch(md, /マイグレーション|SQL|認証|設定ファイルの変更/);
+});
+
+test('設定ファイルなし: 注意の要る変更がなければ、その旨を出す', () => {
+ const md = summary({ subjects: ['typo'], changes: [['M', 'README.md']] });
+ assert.match(md, /- \(件名から Issue を読み取れたものはなし\)/);
+ assert.match(md, /- \[ \] 特に注意が必要な領域の変更はない/);
+});
+
+test('Issue のキーを ABC にすると、[abc-12]・ABC-12 ... (#34) の件名から Issue を拾う', () => {
+ const issues = parseIssues(
+ [
+ '[abc-12] feat: ログイン画面を追加',
+ 'ABC-12 ログイン画面 (#34)',
+ 'Merge pull request #35 from me/feature/abc-14',
+ '[xyz-1] fix: 別のチーム',
+ ],
+ 'ABC',
+ );
+ assert.deepEqual([...issues.keys()], ['ABC-12', 'ABC-14']);
+ assert.deepEqual(issues.get('ABC-12'), { title: 'ログイン画面を追加', prs: ['34'] });
+
+ const md = summary({ subjects: ['ABC-12 ログイン画面 (#34)'], config: { issueKey: 'ABC' } });
+ assert.match(md, /^- ABC-12 ログイン画面 \(#34\)$/m);
+});
+
+test('マイグレーションのディレクトリを設定し、drop table を含む SQL を足すと、警告が出る', () => {
+ const md = summary({
+ changes: [
+ ['A', 'supabase/migrations/002_drop.sql'],
+ ['A', 'supabase/migrations/003_safe.sql'],
+ ],
+ files: {
+ 'supabase/migrations/002_drop.sql': 'drop table posts;',
+ 'supabase/migrations/003_safe.sql': '-- drop table posts;\ncreate table likes (id int);',
+ },
+ config: SUPABASE,
+ });
+ assert.match(md, /### ⚠️ 破壊的、またはデータに依存して失敗しうる SQL/);
+ assert.match(md, /^- `supabase\/migrations\/002_drop\.sql`: 削除 \(drop\)$/m);
+ assert.doesNotMatch(md, /003_safe\.sql`: /);
+ assert.match(md, /\*\*マイグレーション \(2 件\)\*\*/);
+});
+
+test('riskySql を false にすると、SQL を読まない', () => {
+ const md = summary({
+ changes: [['A', 'db/migrate/002.sql']],
+ files: { 'db/migrate/002.sql': 'drop table posts;' },
+ config: { migrations: { dir: 'db/migrate/', riskySql: false } },
+ });
+ assert.doesNotMatch(md, /⚠️ 破壊的/);
+ assert.match(md, /\*\*マイグレーション \(1 件\)\*\*: `db\/migrate\/002\.sql`/);
+});
+
+test('既存のマイグレーションの変更・削除は、警告の項目になる', () => {
+ const md = summary({
+ changes: [
+ ['M', 'supabase/migrations/001_init.sql'],
+ ['D', 'supabase/migrations/000_old.sql'],
+ ],
+ config: SUPABASE,
+ });
+ assert.match(
+ md,
+ /- \[ \] \*\*⚠️ 既存のマイグレーションが変更・削除されている\*\*: `supabase\/migrations\/001_init\.sql`、`supabase\/migrations\/000_old\.sql`/,
+ );
+ assert.doesNotMatch(md, /\*\*マイグレーション \(/);
+});
+
+test('設定: 認証・設定ファイル・依存のパスと、最後の確認の項目と文', () => {
+ const md = summary({
+ changes: [
+ ['M', 'src/features/auth/login.ts'],
+ ['A', 'supabase/policies/posts_rls.sql'],
+ ['M', 'app.json'],
+ ['M', 'pnpm-lock.yaml'],
+ ['M', 'yarn.lock'],
+ ],
+ config: SUPABASE,
+ });
+ assert.match(md, /認証・RLS に関わる変更\*\*: `src\/features\/auth\/login\.ts`、`supabase\/policies\/posts_rls\.sql`/);
+ assert.match(md, /設定ファイルの変更\*\*: `app\.json`/);
+ assert.match(md, /依存・スクリプトの変更\*\*: `pnpm-lock\.yaml`。/);
+ assert.doesNotMatch(md, /yarn\.lock/);
+ assert.match(md, /- \[ \] 統合後の状態を、Preview で確かめた\n\n### 確認用アカウント\n\n確認は、確認用のアカウントだけで行う。\n$/);
+});
+
+test('matchPath: / で終わるパターン、*、**', () => {
+ assert.ok(matchPath('src/auth/', 'src/auth/a/b.ts'));
+ assert.ok(!matchPath('src/auth/', 'src/authx.ts'));
+ assert.ok(matchPath('package.json', 'package.json'));
+ assert.ok(!matchPath('package.json', 'apps/web/package.json'));
+ assert.ok(matchPath('**/package.json', 'apps/web/package.json'));
+ assert.ok(matchPath('**/package.json', 'package.json'));
+ assert.ok(matchPath('apps/*/app.json', 'apps/web/app.json'));
+ assert.ok(!matchPath('apps/*/app.json', 'apps/web/x/app.json'));
+ assert.ok(matchPath('**/*rls*', 'supabase/tests/posts_rls_test.sql'));
+ assert.ok(!matchPath('a.json', 'axjson'));
+});
+
+test('riskySql: コメントの行は見ない', () => {
+ assert.deepEqual(riskySql('-- truncate posts;\nselect 1;'), []);
+ assert.deepEqual(riskySql('alter table posts alter column id set not null;'), [
+ 'not null の追加 (既存の行が違反すると失敗する)',
+ ]);
+});
+
+test('normalizeConfig: 知らないキーや、型の違いは失敗にする', () => {
+ assert.throws(() => normalizeConfig({ issuekey: 'ABC' }), /知らないキー/);
+ assert.throws(() => normalizeConfig({ authPaths: 'src/' }), /authPaths/);
+ assert.throws(() => normalizeConfig({ migrations: {} }), /migrations\.dir/);
+ assert.throws(() => normalizeConfig({ issueKey: 'A.C' }), /issueKey/);
+ assert.throws(() => normalizeConfig({ sections: [{ title: 'x' }] }), /sections/);
+ assert.equal(normalizeConfig({ issueKey: 'abc' }).issueKey, 'ABC');
+});
+
+test('collect: git の履歴から、件名・変更・中身を集める', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'release-summary-'));
+ try {
+ const git = (...args) =>
+ execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.com', ...args], {
+ cwd: dir,
+ encoding: 'utf8',
+ }).trim();
+ const write = (path, text) => {
+ mkdirSync(dirname(join(dir, path)), { recursive: true });
+ writeFileSync(join(dir, path), text);
+ };
+ git('init', '-q', '-b', 'main');
+ write('db/001.sql', 'create table a (id int);\n');
+ write('package.json', '{\n "dependencies": {}\n}\n');
+ git('add', '.');
+ git('commit', '-qm', 'init');
+ const base = git('rev-parse', 'HEAD');
+ write('db/001.sql', 'create table a (id bigint);\n');
+ write('db/002.sql', 'drop table a;\n');
+ write('package.json', '{\n "dependencies": {\n "zod": "^4.0.0"\n }\n}\n');
+ git('add', '.');
+ git('commit', '-qm', '[abc-7] feat: テーブルを消す');
+ const head = git('rev-parse', 'HEAD');
+
+ const md = buildSummary({
+ ...collect(base, head, { cwd: dir }),
+ config: { issueKey: 'ABC', migrations: { dir: 'db' } },
+ });
+ assert.match(md, /1 件のコミット、3 個のファイルの変更/);
+ assert.match(md, /^- ABC-7 テーブルを消す$/m);
+ assert.match(md, /`db\/002\.sql`: 削除 \(drop\)/);
+ assert.match(md, /既存のマイグレーションが変更・削除されている\*\*: `db\/001\.sql`/);
+ assert.match(md, /\+ {4}"zod": "\^4\.0\.0"/);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('CLI: 設定ファイルがなくても動き、壊れた設定は失敗にする', () => {
+ const script = fileURLToPath(new URL('./release-summary.mjs', import.meta.url));
+ const dir = mkdtempSync(join(tmpdir(), 'release-summary-cli-'));
+ try {
+ const run = (...args) => execFileSync('node', [script, ...args], { cwd: dir, encoding: 'utf8', stdio: 'pipe' });
+ execFileSync('git', ['init', '-q'], { cwd: dir });
+ const commit = (msg) =>
+ execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.com', 'commit', '-q', '--allow-empty', '-m', msg], {
+ cwd: dir,
+ });
+ commit('init');
+ commit('ABC-1 何か');
+ assert.match(run('HEAD~1', 'HEAD', join(dir, 'missing.json')), /^- ABC-1 何か$/m);
+ writeFileSync(join(dir, 'bad.json'), '{');
+ assert.throws(() => run('HEAD~1', 'HEAD', join(dir, 'bad.json')), /設定ファイル/);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('例の設定ファイル (templates/.github/release-summary.json) は、正しい形', () => {
+ const file = fileURLToPath(new URL('../../templates/.github/release-summary.json', import.meta.url));
+ const config = normalizeConfig(readConfig(file));
+ assert.equal(config.issueKey, 'ABC');
+ assert.equal(config.migrations.dir, 'supabase/migrations');
+});
diff --git a/scripts/ci/update-summary-section.mjs b/scripts/ci/update-summary-section.mjs
new file mode 100644
index 0000000..604ad76
--- /dev/null
+++ b/scripts/ci/update-summary-section.mjs
@@ -0,0 +1,35 @@
+// PR 本文の、マーカーで囲んだ部分だけを、要約に置き換える。マーカーがなければ、本文の末尾に足す。
+// 本文のそれ以外の部分 (人が書いた説明) は変えない。
+//
+// node update-summary-section.mjs <本文のファイル> <要約のファイル> 新しい本文を標準出力に出す
+import { readFileSync } from 'node:fs';
+import { pathToFileURL } from 'node:url';
+
+export const START = '';
+export const END = '';
+
+export function updateSection(rawBody, rawSummary) {
+ const body = rawBody.replace(/\r\n/g, '\n');
+ const section = `${START}\n${rawSummary.trim()}\n${END}`;
+ const start = body.indexOf(START);
+ const end = start === -1 ? -1 : body.indexOf(END, start);
+
+ let next;
+ if (start !== -1 && end !== -1) {
+ next = body.slice(0, start) + section + body.slice(end + END.length);
+ } else {
+ next = body.trimEnd() === '' ? section : `${body.trimEnd()}\n\n${section}`;
+ }
+ return `${next.trimEnd()}\n`;
+}
+
+function main() {
+ const [bodyFile, summaryFile] = process.argv.slice(2);
+ if (!bodyFile || !summaryFile) {
+ console.error('使い方: update-summary-section.mjs <本文のファイル> <要約のファイル>');
+ process.exit(1);
+ }
+ process.stdout.write(updateSection(readFileSync(bodyFile, 'utf8'), readFileSync(summaryFile, 'utf8')));
+}
+
+if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) main();
diff --git a/scripts/ci/update-summary-section.test.mjs b/scripts/ci/update-summary-section.test.mjs
new file mode 100644
index 0000000..c279d1a
--- /dev/null
+++ b/scripts/ci/update-summary-section.test.mjs
@@ -0,0 +1,31 @@
+// node --test scripts/ci/ で実行する。
+import assert from 'node:assert/strict';
+import { test } from 'node:test';
+
+import { END, START, updateSection } from './update-summary-section.mjs';
+
+test('マーカーがない本文には、末尾に足す', () => {
+ assert.equal(updateSection('人が書いた説明\n\n', '## 要約\n'), `人が書いた説明\n\n${START}\n## 要約\n${END}\n`);
+});
+
+test('本文が空なら、要約だけにする', () => {
+ assert.equal(updateSection('', '## 要約'), `${START}\n## 要約\n${END}\n`);
+});
+
+test('マーカーがある本文では、その間だけを替え、人が書いた部分は変えない', () => {
+ const body = `前の説明\r\n\r\n${START}\r\n古い要約\r\n${END}\r\n\r\n後ろの説明\r\n- [x] 人が付けた印\r\n`;
+ assert.equal(
+ updateSection(body, '新しい要約'),
+ `前の説明\n\n${START}\n新しい要約\n${END}\n\n後ろの説明\n- [x] 人が付けた印\n`,
+ );
+});
+
+test('同じ要約で 2 回替えても、本文は変わらない', () => {
+ const once = updateSection('説明', '要約');
+ assert.equal(updateSection(once, '要約'), once);
+});
+
+test('終わりのマーカーが始まりより前にしかなければ、末尾に足す', () => {
+ const body = `${END}\n説明\n${START}`;
+ assert.equal(updateSection(body, '要約'), `${body}\n\n${START}\n要約\n${END}\n`);
+});
diff --git a/templates/.github/release-summary.json b/templates/.github/release-summary.json
new file mode 100644
index 0000000..e3dffaa
--- /dev/null
+++ b/templates/.github/release-summary.json
@@ -0,0 +1,17 @@
+{
+ "issueKey": "ABC",
+ "migrations": { "dir": "supabase/migrations", "riskySql": true },
+ "authPaths": ["src/features/auth/", "supabase/tests/", "**/*rls*", "**/*polic*"],
+ "configFiles": ["supabase/config.toml", "app.json"],
+ "dependencyFiles": ["package.json", "pnpm-lock.yaml"],
+ "checks": [
+ "統合後の状態を、Preview で確かめた",
+ "必須のチェック (E2E・DB のテスト) が通っている"
+ ],
+ "sections": [
+ {
+ "title": "確認用アカウント",
+ "body": "Preview が本番の DB に繋がるなら、確認は確認用のアカウントだけで行い、作ったデータは確認用だと分かる名前にして、後で消す。"
+ }
+ ]
+}
From d2343b6d6d3650268cb8e0c4415f1def99a594b6 Mon Sep 17 00:00:00 2001
From: HyuuNyackman <107097515+HyuuNyackman@users.noreply.github.com>
Date: Sun, 29 Nov 2026 22:30:22 +0900
Subject: [PATCH 2/3] =?UTF-8?q?[xcl-193]=20ci:=20=E3=83=AA=E3=83=AA?=
=?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=20PR=20=E3=81=AE=E8=A6=81=E7=B4=84?=
=?UTF-8?q?=E3=81=AE=E5=86=8D=E5=88=A9=E7=94=A8=E3=83=AF=E3=83=BC=E3=82=AF?=
=?UTF-8?q?=E3=83=95=E3=83=AD=E3=83=BC=E3=82=92=E8=B6=B3=E3=81=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/workflows/agent-release-summary.yml | 94 +++++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 .github/workflows/agent-release-summary.yml
diff --git a/.github/workflows/agent-release-summary.yml b/.github/workflows/agent-release-summary.yml
new file mode 100644
index 0000000..6ee3c8b
--- /dev/null
+++ b/.github/workflows/agent-release-summary.yml
@@ -0,0 +1,94 @@
+name: Agent Release Summary
+
+# 再利用ワークフロー。リリースの PR (develop → main) の本文に、確認すべき点の要約を書く。
+# 本文のマーカー ( と ) の間だけを更新し、人が書いた部分は変えない。
+# 要約を作るスクリプト (scripts/ci/release-summary.mjs・update-summary-section.mjs) は、呼ばれたこのリポジトリの同じコミットから取る。
+# リポジトリに固有の点 (Issue のキー、マイグレーションなど) は、呼ぶ側の設定ファイルで渡す (形は docs/SETUP.md)。
+# 設定ファイルがなければ、汎用の部分 (Issue、ワークフロー、依存) だけを出す。
+#
+# 呼び出し側の例 (.github/workflows/release-summary.yml):
+#
+# on:
+# pull_request:
+# branches: [main]
+# types: [opened, synchronize, reopened, ready_for_review]
+# jobs:
+# release-summary:
+# # タグは動かせるので、完全なコミット SHA で固定する (docs/SETUP.md の 4)。
+# uses: HyuuNyackman/agent-dev-kit/.github/workflows/agent-release-summary.yml@<コミット SHA> # v1
+# # with:
+# # config-path: .github/release-summary.json
+# permissions:
+# contents: read
+# pull-requests: write
+
+on:
+ workflow_call:
+ inputs:
+ config-path:
+ description: 設定ファイルのパス (呼ぶ側のリポジトリの中)。なければ汎用の部分だけで動く。
+ type: string
+ default: .github/release-summary.json
+
+jobs:
+ summary:
+ # main 宛てで head が develop の、同じリポジトリの PR だけ。
+ if: |
+ github.event_name == 'pull_request' &&
+ github.base_ref == 'main' &&
+ github.head_ref == 'develop' &&
+ github.event.pull_request.head.repo.full_name == github.repository
+ concurrency:
+ group: release-summary-${{ github.repository }}-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ permissions:
+ contents: read
+ pull-requests: write
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ PR: ${{ github.event.pull_request.number }}
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+ fetch-depth: 0
+
+ - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
+ with:
+ node-version: 24
+
+ - name: Load summary tools
+ env:
+ KIT_REPO: ${{ job.workflow_repository }}
+ KIT_SHA: ${{ job.workflow_sha }}
+ run: |
+ if [ -z "$KIT_REPO" ] || [ -z "$KIT_SHA" ]; then
+ echo "::error::job.workflow_repository か job.workflow_sha が取れません。" && exit 1
+ fi
+ get() { gh api -H 'Accept: application/vnd.github.raw' "repos/$KIT_REPO/contents/$1?ref=$KIT_SHA"; }
+ mkdir -p "$RUNNER_TEMP/summary"
+ get scripts/ci/release-summary.mjs > "$RUNNER_TEMP/summary/release-summary.mjs"
+ get scripts/ci/update-summary-section.mjs > "$RUNNER_TEMP/summary/update-summary-section.mjs"
+
+ - name: Build summary
+ env:
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ CONFIG_PATH: ${{ inputs.config-path }}
+ run: |
+ if [ ! -f "$CONFIG_PATH" ]; then
+ echo "::notice::設定ファイル $CONFIG_PATH がないので、汎用の部分だけで要約を作ります。"
+ fi
+ node "$RUNNER_TEMP/summary/release-summary.mjs" "$BASE_SHA" "$HEAD_SHA" "$CONFIG_PATH" > "$RUNNER_TEMP/summary/summary.md"
+
+ - name: Update PR body
+ run: |
+ dir="$RUNNER_TEMP/summary"
+ gh pr view "$PR" --repo "$REPO" --json body --jq .body > "$dir/body.md"
+ node "$dir/update-summary-section.mjs" "$dir/body.md" "$dir/summary.md" > "$dir/new-body.md"
+ gh pr edit "$PR" --repo "$REPO" --body-file "$dir/new-body.md"
From 71e7f8db2eb78ec61ab90f6892bd5e34d9e8f09e Mon Sep 17 00:00:00 2001
From: HyuuNyackman <107097515+HyuuNyackman@users.noreply.github.com>
Date: Sun, 29 Nov 2026 22:30:23 +0900
Subject: [PATCH 3/3] =?UTF-8?q?[xcl-193]=20docs:=20=E3=83=AA=E3=83=AA?=
=?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=E8=A6=81=E7=B4=84=E3=81=AE=E8=A8=AD?=
=?UTF-8?q?=E5=AE=9A=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE=E5=BD=A2?=
=?UTF-8?q?=E3=81=A8=E3=80=81README=20=E3=81=AE=E8=A1=A8=E3=82=92=E6=9B=B8?=
=?UTF-8?q?=E3=81=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 1 +
docs/SETUP.md | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/README.md b/README.md
index ef93e01..14dc75e 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ AI が実装し、人が承認する。`develop` へは必須チェックが通
| `skills/commit-rules/`、`skills/pr-rules/` | コミット・ブランチ・PR の規約 (`agent/-`) | APM |
| `.github/workflows/agent-auto-merge.yml` | エージェントの PR に自動マージを設定する再利用ワークフロー | `uses: ...@` |
| `.github/workflows/agent-claude-review.yml` | Claude で PR をレビューし、結果を必須チェックにする再利用ワークフロー (手順は `skills/ci-code-review/`、判定は `scripts/ci/review-state.mjs`) | `uses: ...@` |
+| `.github/workflows/agent-release-summary.yml` | リリースの PR (`develop → main`) の本文に、確認事項の要約 (含まれる Issue、マイグレーション、認証・依存・CI の変更) を書く再利用ワークフロー (要約は `scripts/ci/release-summary.mjs`、設定の例は `templates/.github/release-summary.json`) | `uses: ...@` |
| `actions/changed/` | 指定したパスに変更があるかを返すアクション (変更がないときに重いジョブを飛ばす) | `uses: ...@` |
| `templates/AGENTS.section.md` | `AGENTS.md` に貼る運用の節 | コピー |
| `templates/.claude/settings.json` | 危険なコマンドの deny | コピー |
diff --git a/docs/SETUP.md b/docs/SETUP.md
index a1929d5..5bf555b 100644
--- a/docs/SETUP.md
+++ b/docs/SETUP.md
@@ -34,6 +34,25 @@ dependencies:
- 呼ぶときは、タグ (`@v1`) ではなく、完全なコミット SHA で固定する (例: `agent-auto-merge.yml@ # v1.x.y`)。タグは後から動かせるため。Dependabot (`package-ecosystem: github-actions`) で、SHA の更新の PR を作らせる。
- 必須チェックにするもの: lint・型・テスト、(DB があれば) DB のテスト、AI のレビュー (`<呼ぶ側のジョブ名> / claude-review`)。
- リポジトリの設定で「Allow auto-merge」を有効にする。
+- リリースの PR (`develop → main`) の本文に確認事項の要約を書くなら、`agent-release-summary.yml` を呼ぶ (書き方はファイルの先頭のコメント)。下の設定ファイルを置く。
+
+### リリースの要約の設定ファイル
+
+既定のパスは `.github/release-summary.json` (input の `config-path` で変えられる)。例は `templates/.github/release-summary.json` (Supabase を使う場合)。
+ファイルがなければ、汎用の部分 (含まれる Issue、コミットとファイルの数、ワークフロー (`.github/`) と依存の変更) だけを出す。知らないキーや型の違いがあると、ジョブを失敗にする。
+
+| キー | 型 | 既定 | 内容 |
+|---|---|---|---|
+| `issueKey` | 文字列 | なし | Issue のキー (例: `ABC`)。件名のどこかの `ABC-12`・`abc-12` を拾う。なければ、件名の先頭の `[abc-12]` か `ABC-12` だけを拾う |
+| `migrations.dir` | 文字列 | なし | マイグレーションのディレクトリ (例: `supabase/migrations`)。下の `.sql` の追加を数え、既存のファイルの変更・削除を警告にする |
+| `migrations.riskySql` | 真偽 | `true` | 足した SQL から、危ない文 (`drop`・`truncate`・`delete`・型の変更・`not null` の追加・RLS の無効化など) を探して警告にする |
+| `authPaths` | パターンの配列 | `[]` | 認証・RLS とみなすパス |
+| `configFiles` | パターンの配列 | `[]` | 本番の設定との差を確かめる設定ファイル (例: `app.json`) |
+| `dependencyFiles` | パターンの配列 | `package.json` と主なロックファイル | 依存のファイル。`package.json` は、変わった行も載せる |
+| `checks` | 文字列の配列 | `[]` | 確認の項目の最後に足す項目 (例: 「Preview で確かめた」) |
+| `sections` | `{ "title", "body" }` の配列 | `[]` | 最後に足す節 (例: 確認用のアカウントの注意) |
+
+パターンは、`/` で終わればその下のすべて、`*` は `/` 以外の 0 文字以上、`**` は `/` を含む 0 文字以上 (例: `src/features/auth/`、`**/*rls*`)。それ以外は、リポジトリのルートからのパスとの完全一致。
## 5. GitHub のブランチ保護 (AI にマージさせないための本体)