@seangalie/precast 0.1.0 → 0.2.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/CHANGELOG.md +36 -0
- package/README.md +64 -7
- package/dist/bin.js +1 -1
- package/dist/cli.d.ts +7 -1
- package/dist/cli.js +161 -50
- package/dist/context.d.ts +9 -3
- package/dist/context.js +62 -15
- package/dist/generate.d.ts +6 -0
- package/dist/generate.js +18 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/platforms.d.ts +5 -0
- package/dist/platforms.js +20 -1
- package/dist/profiles.d.ts +23 -0
- package/dist/profiles.js +79 -0
- package/dist/prompts.d.ts +30 -0
- package/dist/prompts.js +103 -0
- package/dist/style.d.ts +14 -0
- package/dist/style.js +34 -0
- package/package.json +1 -1
- package/platforms/forgejo/files/.forgejo/SETUP.md.tmpl +6 -2
- package/platforms/forgejo/platform.json +1 -1
- package/platforms/gitlab/files/.gitlab/SETUP.md.tmpl +13 -10
- package/platforms/gitlab/files/.gitlab-ci.yml.tmpl +4 -2
- package/platforms/gitlab/platform.json +7 -3
- package/template/.pre-commit-config.yaml.tmpl +13 -1
- package/template/.repo/ci-checks.sh +2 -0
- package/template/AGENTS.md.tmpl +3 -0
- package/template/SETUP.md.tmpl +12 -3
- package/template/docs/CONTRIBUTING.md.tmpl +11 -6
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { type Context, type ContextOptions, makeContext } from "./context.ts";
|
|
|
3
3
|
export { PrecastError } from "./errors.ts";
|
|
4
4
|
export { type GenerateOptions, type GenerateResult, generate, ROOT } from "./generate.ts";
|
|
5
5
|
export { type PlatformDescriptor, platformNames, readPlatform } from "./platforms.ts";
|
|
6
|
+
export { defaultConfigPath, type Profile, readProfile } from "./profiles.ts";
|
|
6
7
|
export { DEFAULT_TIER, TIERS, type Tier } from "./tiers.ts";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { makeContext } from "./context.js";
|
|
|
3
3
|
export { PrecastError } from "./errors.js";
|
|
4
4
|
export { generate, ROOT } from "./generate.js";
|
|
5
5
|
export { platformNames, readPlatform } from "./platforms.js";
|
|
6
|
+
export { defaultConfigPath, readProfile } from "./profiles.js";
|
|
6
7
|
export { DEFAULT_TIER, TIERS } from "./tiers.js";
|
package/dist/platforms.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export interface PlatformDescriptor {
|
|
|
7
7
|
tiers?: Record<string, string[]>;
|
|
8
8
|
/** Ordered values; later entries may refer to earlier ones with `{KEY}`. */
|
|
9
9
|
context: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Replacements for `context` entries that apply only when generating for
|
|
12
|
+
* `server_url` itself, such as a hosted instance's default CI image.
|
|
13
|
+
*/
|
|
14
|
+
default_server_context?: Record<string, string>;
|
|
10
15
|
}
|
|
11
16
|
/** Platform IDs are the names of directories that contain a descriptor. */
|
|
12
17
|
export declare function platformNames(root: string): string[];
|
package/dist/platforms.js
CHANGED
|
@@ -3,7 +3,13 @@ import { join } from "node:path";
|
|
|
3
3
|
import { PrecastError } from "./errors.js";
|
|
4
4
|
import { isPlainObject } from "./tiers.js";
|
|
5
5
|
const STRING_FIELDS = ["server_url", "runner", "codeowners_pattern"];
|
|
6
|
-
const KNOWN_FIELDS = new Set([
|
|
6
|
+
const KNOWN_FIELDS = new Set([
|
|
7
|
+
...STRING_FIELDS,
|
|
8
|
+
"nested_namespaces",
|
|
9
|
+
"tiers",
|
|
10
|
+
"context",
|
|
11
|
+
"default_server_context",
|
|
12
|
+
]);
|
|
7
13
|
/** Platform IDs are the names of directories that contain a descriptor. */
|
|
8
14
|
export function platformNames(root) {
|
|
9
15
|
const directory = join(root, "platforms");
|
|
@@ -49,6 +55,19 @@ export function parseDescriptor(value, name) {
|
|
|
49
55
|
!Object.values(context).every((entry) => typeof entry === "string")) {
|
|
50
56
|
throw new PrecastError(`${label} needs a context object of strings`);
|
|
51
57
|
}
|
|
58
|
+
const hosted = value.default_server_context;
|
|
59
|
+
if (hosted !== undefined) {
|
|
60
|
+
if (!isPlainObject(hosted) ||
|
|
61
|
+
!Object.values(hosted).every((entry) => typeof entry === "string")) {
|
|
62
|
+
throw new PrecastError(`${label} needs a default_server_context object of strings`);
|
|
63
|
+
}
|
|
64
|
+
// Only replacements are allowed, so every server renders the same tokens.
|
|
65
|
+
for (const key of Object.keys(hosted)) {
|
|
66
|
+
if (!Object.hasOwn(context, key)) {
|
|
67
|
+
throw new PrecastError(`${label} default_server_context replaces no context key: ${key}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
52
71
|
return value;
|
|
53
72
|
}
|
|
54
73
|
export function readJson(path) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Tier } from "./tiers.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Saved defaults for one server, such as a self-hosted Forgejo or an internal
|
|
4
|
+
* GitLab. Values a command line gives explicitly win over the profile's.
|
|
5
|
+
*/
|
|
6
|
+
export interface Profile {
|
|
7
|
+
platform: string;
|
|
8
|
+
serverUrl?: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
author?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
defaultBranch?: string;
|
|
13
|
+
codeowner?: string;
|
|
14
|
+
runner?: string;
|
|
15
|
+
tier?: Tier;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Where profiles live unless `--config` names another file: the XDG config
|
|
19
|
+
* directory on macOS and Linux, and the roaming application data folder on Windows.
|
|
20
|
+
*/
|
|
21
|
+
export declare function defaultConfigPath(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, home?: string): string;
|
|
22
|
+
/** Read one named profile from a settings file shaped as `{"profiles": {...}}`. */
|
|
23
|
+
export declare function readProfile(file: string, name: string): Profile;
|
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { PrecastError } from "./errors.js";
|
|
5
|
+
import { readJson } from "./platforms.js";
|
|
6
|
+
import { isPlainObject, isTier } from "./tiers.js";
|
|
7
|
+
const STRING_FIELDS = [
|
|
8
|
+
"platform",
|
|
9
|
+
"serverUrl",
|
|
10
|
+
"namespace",
|
|
11
|
+
"author",
|
|
12
|
+
"description",
|
|
13
|
+
"defaultBranch",
|
|
14
|
+
"codeowner",
|
|
15
|
+
"runner",
|
|
16
|
+
];
|
|
17
|
+
const PROFILE_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
18
|
+
/**
|
|
19
|
+
* Where profiles live unless `--config` names another file: the XDG config
|
|
20
|
+
* directory on macOS and Linux, and the roaming application data folder on Windows.
|
|
21
|
+
*/
|
|
22
|
+
export function defaultConfigPath(env = process.env, platform = process.platform, home = homedir()) {
|
|
23
|
+
// Relative values are ignored, as the XDG base directory specification
|
|
24
|
+
// requires, so a settings file is never read from the working directory.
|
|
25
|
+
if (platform === "win32") {
|
|
26
|
+
const appData = env.APPDATA && path.win32.isAbsolute(env.APPDATA) ? env.APPDATA : undefined;
|
|
27
|
+
return path.win32.join(appData ?? path.win32.join(home, "AppData", "Roaming"), "precast", "config.json");
|
|
28
|
+
}
|
|
29
|
+
const xdg = env.XDG_CONFIG_HOME && path.posix.isAbsolute(env.XDG_CONFIG_HOME)
|
|
30
|
+
? env.XDG_CONFIG_HOME
|
|
31
|
+
: undefined;
|
|
32
|
+
return path.posix.join(xdg ?? path.posix.join(home, ".config"), "precast", "config.json");
|
|
33
|
+
}
|
|
34
|
+
/** Read one named profile from a settings file shaped as `{"profiles": {...}}`. */
|
|
35
|
+
export function readProfile(file, name) {
|
|
36
|
+
if (!PROFILE_NAME.test(name)) {
|
|
37
|
+
throw new PrecastError(`Invalid profile name: '${name}'`);
|
|
38
|
+
}
|
|
39
|
+
if (!existsSync(file)) {
|
|
40
|
+
throw new PrecastError(`No settings file at ${file}; create it to use --profile`);
|
|
41
|
+
}
|
|
42
|
+
const settings = readJson(file);
|
|
43
|
+
if (!isPlainObject(settings) || !isPlainObject(settings.profiles)) {
|
|
44
|
+
throw new PrecastError(`${file} must be a JSON object with a "profiles" object`);
|
|
45
|
+
}
|
|
46
|
+
for (const key of Object.keys(settings)) {
|
|
47
|
+
if (key !== "profiles") {
|
|
48
|
+
throw new PrecastError(`${file} has an unknown field: ${key}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const profiles = settings.profiles;
|
|
52
|
+
if (!Object.hasOwn(profiles, name)) {
|
|
53
|
+
const known = Object.keys(profiles).sort();
|
|
54
|
+
throw new PrecastError(`No profile '${name}' in ${file}${known.length > 0 ? `; it has: ${known.join(", ")}` : ""}`);
|
|
55
|
+
}
|
|
56
|
+
return parseProfile(profiles[name], `Profile '${name}' in ${file}`);
|
|
57
|
+
}
|
|
58
|
+
function parseProfile(value, label) {
|
|
59
|
+
if (!isPlainObject(value)) {
|
|
60
|
+
throw new PrecastError(`${label} must be an object`);
|
|
61
|
+
}
|
|
62
|
+
for (const [key, field] of Object.entries(value)) {
|
|
63
|
+
if (key === "tier") {
|
|
64
|
+
if (typeof field !== "string" || !isTier(field)) {
|
|
65
|
+
throw new PrecastError(`${label} has an unknown tier: ${JSON.stringify(field)}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (!STRING_FIELDS.includes(key)) {
|
|
69
|
+
throw new PrecastError(`${label} has an unknown field: ${key}`);
|
|
70
|
+
}
|
|
71
|
+
else if (typeof field !== "string") {
|
|
72
|
+
throw new PrecastError(`${label} needs a string ${key}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (typeof value.platform !== "string") {
|
|
76
|
+
throw new PrecastError(`${label} needs a platform`);
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Tier } from "./tiers.ts";
|
|
2
|
+
/** The values every generation needs; any of them may still be missing. */
|
|
3
|
+
export interface RequiredValues {
|
|
4
|
+
platform?: string | undefined;
|
|
5
|
+
namespace?: string | undefined;
|
|
6
|
+
repo?: string | undefined;
|
|
7
|
+
output?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** The answers a prompted session collects; `tier` only when it was asked. */
|
|
10
|
+
export type Answers = Record<keyof RequiredValues, string> & {
|
|
11
|
+
tier?: Tier;
|
|
12
|
+
};
|
|
13
|
+
/** Ask one question; resolves undefined when the person cancels or input ends. */
|
|
14
|
+
export type Ask = (question: string) => Promise<string | undefined>;
|
|
15
|
+
/** Thrown when the person cancels a prompt, so nothing is generated. */
|
|
16
|
+
export declare class Cancelled extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ask for each missing required value in turn. Answers go through the same
|
|
21
|
+
* checks as command-line options, and an invalid answer is asked again.
|
|
22
|
+
*/
|
|
23
|
+
export declare function promptForMissing(values: RequiredValues, ask: Ask, write: (text: string) => void, root: string, { stream, askTier }?: {
|
|
24
|
+
stream?: NodeJS.WritableStream;
|
|
25
|
+
askTier?: boolean;
|
|
26
|
+
}): Promise<Answers>;
|
|
27
|
+
/** Ask questions on the terminal, treating Ctrl+C and Ctrl+D as cancelling. */
|
|
28
|
+
export declare function withTerminal<T>(input: NodeJS.ReadableStream, output: NodeJS.WritableStream, use: (ask: Ask) => Promise<T>): Promise<T>;
|
|
29
|
+
/** Quote an argument for a POSIX shell only when it needs it. */
|
|
30
|
+
export declare function shellQuote(value: string): string;
|
package/dist/prompts.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { checkNamespace, checkRepo } from "./context.js";
|
|
3
|
+
import { PrecastError } from "./errors.js";
|
|
4
|
+
import { checkOutput } from "./generate.js";
|
|
5
|
+
import { platformNames, readPlatform } from "./platforms.js";
|
|
6
|
+
import { paint } from "./style.js";
|
|
7
|
+
import { DEFAULT_TIER, isTier, TIERS } from "./tiers.js";
|
|
8
|
+
const TIER_SUMMARIES = {
|
|
9
|
+
slim: "the essentials, for personal projects and experiments",
|
|
10
|
+
regular: "adds policies, templates, pre-commit, and CI",
|
|
11
|
+
full: "adds labels, releases, and housekeeping automation",
|
|
12
|
+
};
|
|
13
|
+
/** Thrown when the person cancels a prompt, so nothing is generated. */
|
|
14
|
+
export class Cancelled extends Error {
|
|
15
|
+
constructor() {
|
|
16
|
+
super("Cancelled; no files were written");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ask for each missing required value in turn. Answers go through the same
|
|
21
|
+
* checks as command-line options, and an invalid answer is asked again.
|
|
22
|
+
*/
|
|
23
|
+
export async function promptForMissing(values, ask, write, root, { stream, askTier = false } = {}) {
|
|
24
|
+
const answer = async (label, hint, check) => {
|
|
25
|
+
const shown = hint ? ` ${paint("dim", hint, stream)}` : "";
|
|
26
|
+
const question = `${paint("cyan", "?", stream)} ${paint("bold", label, stream)}${shown} ${paint("dim", "›", stream)} `;
|
|
27
|
+
for (;;) {
|
|
28
|
+
const reply = await ask(question);
|
|
29
|
+
if (reply === undefined)
|
|
30
|
+
throw new Cancelled();
|
|
31
|
+
try {
|
|
32
|
+
return check(reply.trim());
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (!(error instanceof PrecastError))
|
|
36
|
+
throw error;
|
|
37
|
+
write(` ${paint("red", `✗ ${error.message}`, stream)}\n`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
let platform = values.platform;
|
|
42
|
+
if (platform === undefined) {
|
|
43
|
+
const names = platformNames(root);
|
|
44
|
+
write(`${paint("bold", "Platforms", stream)}\n`);
|
|
45
|
+
for (const [index, name] of names.entries()) {
|
|
46
|
+
write(` ${paint("cyan", String(index + 1), stream)} ${name}\n`);
|
|
47
|
+
}
|
|
48
|
+
platform = await answer("Platform", `(1-${names.length} or a name)`, (reply) => {
|
|
49
|
+
const chosen = names[Number(reply) - 1] ?? reply;
|
|
50
|
+
if (!names.includes(chosen)) {
|
|
51
|
+
throw new PrecastError(`Choose 1-${names.length} or one of: ${names.join(", ")}`);
|
|
52
|
+
}
|
|
53
|
+
return chosen;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
let tier;
|
|
57
|
+
if (askTier) {
|
|
58
|
+
write(`${paint("bold", "Tiers", stream)} ${paint("dim", "(each adds to the one before)", stream)}\n`);
|
|
59
|
+
const width = Math.max(...TIERS.map((name) => name.length));
|
|
60
|
+
for (const [index, name] of TIERS.entries()) {
|
|
61
|
+
const summary = paint("dim", TIER_SUMMARIES[name], stream);
|
|
62
|
+
write(` ${paint("cyan", String(index + 1), stream)} ${name.padEnd(width)} ${summary}\n`);
|
|
63
|
+
}
|
|
64
|
+
tier = await answer("Tier", `(1-${TIERS.length} or a name, Enter for ${DEFAULT_TIER})`, (reply) => {
|
|
65
|
+
const chosen = reply === "" ? DEFAULT_TIER : (TIERS[Number(reply) - 1] ?? reply);
|
|
66
|
+
if (!isTier(chosen)) {
|
|
67
|
+
throw new PrecastError(`Choose 1-${TIERS.length} or one of: ${TIERS.join(", ")}`);
|
|
68
|
+
}
|
|
69
|
+
return chosen;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const nested = readPlatform(root, platform).nested_namespaces;
|
|
73
|
+
const namespace = values.namespace ??
|
|
74
|
+
(await answer("Namespace", nested ? "(owner, organization, or group/subgroup)" : "(owner or organization)", (reply) => checkNamespace(reply, nested)));
|
|
75
|
+
const repo = values.repo ?? (await answer("Repository name", "", checkRepo));
|
|
76
|
+
const output = values.output ??
|
|
77
|
+
(await answer("Output folder", `(${repo})`, (reply) => {
|
|
78
|
+
const folder = reply || repo;
|
|
79
|
+
// The generator's own check, so an answer it would refuse is asked again.
|
|
80
|
+
checkOutput(folder, root);
|
|
81
|
+
return folder;
|
|
82
|
+
}));
|
|
83
|
+
return tier === undefined
|
|
84
|
+
? { platform, namespace, repo, output }
|
|
85
|
+
: { platform, namespace, repo, output, tier };
|
|
86
|
+
}
|
|
87
|
+
/** Ask questions on the terminal, treating Ctrl+C and Ctrl+D as cancelling. */
|
|
88
|
+
export async function withTerminal(input, output, use) {
|
|
89
|
+
const terminal = createInterface({ input, output });
|
|
90
|
+
const closed = new Promise((resolve) => terminal.once("close", () => resolve(undefined)));
|
|
91
|
+
terminal.on("SIGINT", () => terminal.close());
|
|
92
|
+
try {
|
|
93
|
+
// Closing the terminal can also reject the pending question; both mean cancel.
|
|
94
|
+
return await use((question) => Promise.race([terminal.question(question).catch(() => undefined), closed]));
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
terminal.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Quote an argument for a POSIX shell only when it needs it. */
|
|
101
|
+
export function shellQuote(value) {
|
|
102
|
+
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
|
|
103
|
+
}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
type Format = Parameters<typeof styleText>[0];
|
|
3
|
+
/**
|
|
4
|
+
* Whether to color output for `stream`: only a terminal, and never when
|
|
5
|
+
* `NO_COLOR`, `NODE_DISABLE_COLORS`, `FORCE_COLOR=0`, or `TERM=dumb` asks for
|
|
6
|
+
* plain text. `FORCE_COLOR` cannot turn color on for a pipe or file, so logs
|
|
7
|
+
* and tests never contain escape codes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function colorEnabled(stream?: NodeJS.WritableStream, env?: NodeJS.ProcessEnv): boolean;
|
|
10
|
+
/** Style text for `stream` when `colorEnabled` allows it; otherwise return it unchanged. */
|
|
11
|
+
export declare function paint(format: Format, text: string, stream?: NodeJS.WritableStream): string;
|
|
12
|
+
/** The banner shown before the first question. */
|
|
13
|
+
export declare function header(version: string, stream?: NodeJS.WritableStream): string;
|
|
14
|
+
export {};
|
package/dist/style.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
/**
|
|
3
|
+
* Whether to color output for `stream`: only a terminal, and never when
|
|
4
|
+
* `NO_COLOR`, `NODE_DISABLE_COLORS`, `FORCE_COLOR=0`, or `TERM=dumb` asks for
|
|
5
|
+
* plain text. `FORCE_COLOR` cannot turn color on for a pipe or file, so logs
|
|
6
|
+
* and tests never contain escape codes.
|
|
7
|
+
*/
|
|
8
|
+
export function colorEnabled(stream = process.stdout, env = process.env) {
|
|
9
|
+
if (stream.isTTY !== true)
|
|
10
|
+
return false;
|
|
11
|
+
return !(env.NO_COLOR ||
|
|
12
|
+
env.NODE_DISABLE_COLORS ||
|
|
13
|
+
env.FORCE_COLOR === "0" ||
|
|
14
|
+
env.TERM === "dumb");
|
|
15
|
+
}
|
|
16
|
+
/** Style text for `stream` when `colorEnabled` allows it; otherwise return it unchanged. */
|
|
17
|
+
export function paint(format, text, stream = process.stdout) {
|
|
18
|
+
return colorEnabled(stream) ? styleText(format, text, { validateStream: false }) : text;
|
|
19
|
+
}
|
|
20
|
+
// figlet's Standard font at full width, kept to ASCII so every terminal shows it.
|
|
21
|
+
const WORDMARK = [
|
|
22
|
+
" _",
|
|
23
|
+
" _ __ _ __ ___ ___ __ _ ___ | |_",
|
|
24
|
+
"| '_ \\ | '__| / _ \\ / __| / _` |/ __|| __|",
|
|
25
|
+
"| |_) || | | __/| (__ | (_| |\\__ \\| |_",
|
|
26
|
+
"| .__/ |_| \\___| \\___| \\__,_||___/ \\__|",
|
|
27
|
+
"|_|",
|
|
28
|
+
];
|
|
29
|
+
/** The banner shown before the first question. */
|
|
30
|
+
export function header(version, stream) {
|
|
31
|
+
const art = WORDMARK.map((line) => ` ${paint("cyan", line, stream)}`).join("\n");
|
|
32
|
+
const tagline = paint("dim", ` Start a new project with its checks in place · v${version}`, stream);
|
|
33
|
+
return `\n${art}\n\n${tagline}\n\n`;
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -13,14 +13,18 @@ Generate with `--tier regular` or `--tier full` for issue templates, CI, and aut
|
|
|
13
13
|
Actions. Confirm a runner advertises the selected label from the workflow files.
|
|
14
14
|
The Pre-commit job runs in that label's job container, so its image must provide
|
|
15
15
|
Git, Bash, and Python 3.10+ with venv, plus access to the Python package index,
|
|
16
|
-
GitHub hook sources, and Go toolchain/module downloads.
|
|
16
|
+
GitHub hook sources, and Go toolchain/module downloads. Hosted runners, such as
|
|
17
|
+
Codeberg's, may use their own labels instead of `ubuntu-latest`; generate with
|
|
18
|
+
`--runner LABEL` to match one.
|
|
17
19
|
@@END_TIERS@@
|
|
18
20
|
@@TIERS full@@
|
|
19
21
|
- [ ] Enable the repository units I need under Settings, including Issues, Actions,
|
|
20
22
|
and Releases. Confirm a runner advertises the selected label from the workflow files.
|
|
21
23
|
The Pre-commit job runs in that label's job container, so its image must provide
|
|
22
24
|
Git, Bash, and Python 3.10+ with venv, plus access to the Python package index,
|
|
23
|
-
GitHub hook sources, and Go toolchain/module downloads.
|
|
25
|
+
GitHub hook sources, and Go toolchain/module downloads. Hosted runners, such as
|
|
26
|
+
Codeberg's, may use their own labels instead of `ubuntu-latest`; generate with
|
|
27
|
+
`--runner LABEL` to match one.
|
|
24
28
|
- [ ] Run **Actions → Sync labels → Run workflow** once after the first push. It
|
|
25
29
|
uses `.forgejo/labels.yml`; PR Labels needs these labels to exist. Alternatively,
|
|
26
30
|
run `.forgejo/scripts/sync-labels.sh` with `FORGEJO_API`, `FORGEJO_TOKEN`, `OWNER`,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# GitLab setup
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
This starter does not assume a GitLab version, subscription tier, or runner
|
|
4
|
+
setup. On a self-managed instance, check its runners and policies before relying
|
|
5
|
+
on the checks below.
|
|
5
6
|
|
|
6
7
|
- [ ] Confirm the destination project is in the intended namespace. Subgroups are supported.
|
|
7
8
|
@@TIERS regular full@@
|
|
@@ -11,11 +12,12 @@ desktop UI; runner, subscription, and project policy checks remain outstanding.
|
|
|
11
12
|
index (normally `pypi.org` and `files.pythonhosted.org`), GitHub hook repositories,
|
|
12
13
|
and Go toolchain/module services such as `go.dev`, `dl.google.com`,
|
|
13
14
|
`proxy.golang.org`, and `sum.golang.org`. Confirm outbound access or approved
|
|
14
|
-
mirrors/proxies; these are not assumed available on
|
|
15
|
+
mirrors/proxies; these are not assumed available on every instance's runners.
|
|
15
16
|
The default `tags: []`
|
|
16
17
|
requires a runner that accepts untagged jobs. Generate with `--runner TAG` to select
|
|
17
|
-
a tagged runner instead.
|
|
18
|
-
image
|
|
18
|
+
a tagged runner instead. Projects generated for GitLab.com set a public Python
|
|
19
|
+
image in `.gitlab-ci.yml`. On other instances with Docker/Kubernetes executors,
|
|
20
|
+
set an approved default image on the runner or add one to `.gitlab-ci.yml`.
|
|
19
21
|
@@END_TIERS@@
|
|
20
22
|
@@TIERS regular@@
|
|
21
23
|
- [ ] Add real build and test jobs to `.gitlab-ci.yml`. `project-tests` is a manual placeholder.
|
|
@@ -30,10 +32,10 @@ desktop UI; runner, subscription, and project policy checks remain outstanding.
|
|
|
30
32
|
@@END_TIERS@@
|
|
31
33
|
- [ ] Set protected branches, review requirements, visibility, and institutional policies.
|
|
32
34
|
@@TIERS slim@@
|
|
33
|
-
- [ ] Give a private security contact in `README.md` according to
|
|
35
|
+
- [ ] Give a private security contact in `README.md` according to your organization's requirements.
|
|
34
36
|
@@END_TIERS@@
|
|
35
37
|
@@TIERS regular full@@
|
|
36
|
-
- [ ] Set a private security contact in `docs/SECURITY.md` according to
|
|
38
|
+
- [ ] Set a private security contact in `docs/SECURITY.md` according to your organization's requirements.
|
|
37
39
|
@@END_TIERS@@
|
|
38
40
|
@@TIERS full@@
|
|
39
41
|
- [ ] Configure labels using `.gitlab/labels.json` manually, or explicitly run the command
|
|
@@ -52,11 +54,12 @@ desktop UI; runner, subscription, and project policy checks remain outstanding.
|
|
|
52
54
|
notes, including for prerelease tags. It does not build or attach artifacts.
|
|
53
55
|
@@END_TIERS@@
|
|
54
56
|
- [ ] Add dependency updates and issue triage automation if needed. This starter does
|
|
55
|
-
not assume that
|
|
57
|
+
not assume that your instance permits external bots, GitHub CodeQL, or scheduled
|
|
58
|
+
API writes.
|
|
56
59
|
|
|
57
60
|
@@TIERS slim@@
|
|
58
61
|
Generate with `--tier regular` or `--tier full` for templates, CI, labels, and releases.
|
|
59
62
|
|
|
60
63
|
@@END_TIERS@@
|
|
61
|
-
GitLab project
|
|
62
|
-
|
|
64
|
+
Precast does not create the GitLab project, synchronize labels, publish releases, or
|
|
65
|
+
run CI for you. Check each of those on your instance before relying on it.
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
# GitHub hook sources, and Go toolchain/module services (including go.dev,
|
|
4
4
|
# dl.google.com, proxy.golang.org, and sum.golang.org), or approved mirrors.
|
|
5
5
|
# See .gitlab/SETUP.md before using this on a restricted runner.
|
|
6
|
-
#
|
|
7
|
-
#
|
|
6
|
+
# Projects generated for GitLab.com use a public Python image. On other instances,
|
|
7
|
+
# a Docker or Kubernetes executor needs a suitable default image on the runner or
|
|
8
|
+
# an approved `image:` below; no executor or institutional image is assumed.
|
|
8
9
|
@@TIERS regular@@
|
|
9
10
|
stages: [validate, test]
|
|
10
11
|
@@END_TIERS@@
|
|
@@ -22,6 +23,7 @@ workflow:
|
|
|
22
23
|
|
|
23
24
|
default:
|
|
24
25
|
tags: @@RUNNER_TAGS_YAML@@
|
|
26
|
+
@@CI_IMAGE@@
|
|
25
27
|
|
|
26
28
|
pre-commit:
|
|
27
29
|
stage: validate
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"server_url": "https://
|
|
2
|
+
"server_url": "https://gitlab.com",
|
|
3
3
|
"nested_namespaces": true,
|
|
4
4
|
"runner": "",
|
|
5
5
|
"codeowners_pattern": "*",
|
|
@@ -28,7 +28,11 @@
|
|
|
28
28
|
"AUTOMATION_NOTE": "Use GitLab CI, CI_API_V4_URL and CI_PROJECT_ID. Namespaces can contain subgroups; do not split them into only owner/repository.",
|
|
29
29
|
"SECURITY_CHANNEL": "Set a private reporting address below and follow institutional reporting requirements before publishing this project.",
|
|
30
30
|
"LABEL_NOTE": "Labels and merge-request policies are configured in GitLab settings; `.gitlab/labels.json` contains the starting label definitions.",
|
|
31
|
-
"EXTRA_SETUP": "Review `.gitlab/SETUP.md` for runner requirements, releases and
|
|
32
|
-
"PRE_COMMIT_WORKFLOW_HOOKS": "# GitLab CI is checked by the shared YAML hook above."
|
|
31
|
+
"EXTRA_SETUP": "Review `.gitlab/SETUP.md` for runner requirements, releases and organization-specific checks. This template does not assume a GitLab subscription tier.",
|
|
32
|
+
"PRE_COMMIT_WORKFLOW_HOOKS": "# GitLab CI is checked by the shared YAML hook above.",
|
|
33
|
+
"CI_IMAGE": " # image: an approved image with Git, Bash, and Python 3.10+ with venv, if the runner has no suitable default"
|
|
34
|
+
},
|
|
35
|
+
"default_server_context": {
|
|
36
|
+
"CI_IMAGE": " # GitLab.com's hosted runners default to an image without Python's venv.\n image: python:3.14-trixie"
|
|
33
37
|
}
|
|
34
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
minimum_pre_commit_version: "3.2.0"
|
|
2
|
-
default_install_hook_types: [pre-commit]
|
|
2
|
+
default_install_hook_types: [pre-commit, pre-merge-commit, commit-msg]
|
|
3
3
|
default_stages: [pre-commit]
|
|
4
4
|
|
|
5
5
|
repos:
|
|
@@ -8,6 +8,11 @@ repos:
|
|
|
8
8
|
hooks:
|
|
9
9
|
- id: check-merge-conflict
|
|
10
10
|
args: [--assume-in-merge]
|
|
11
|
+
# Changes reach the default branch through branches and review. CI skips this,
|
|
12
|
+
# and SKIP=no-commit-to-branch allows a deliberate commit there.
|
|
13
|
+
- id: no-commit-to-branch
|
|
14
|
+
args: [--branch, @@DEFAULT_BRANCH_YAML@@]
|
|
15
|
+
stages: [pre-commit, pre-merge-commit]
|
|
11
16
|
- id: check-json
|
|
12
17
|
- id: check-yaml
|
|
13
18
|
- id: check-toml
|
|
@@ -15,6 +20,13 @@ repos:
|
|
|
15
20
|
- id: check-added-large-files
|
|
16
21
|
args: [--maxkb=10240, --enforce-all]
|
|
17
22
|
|
|
23
|
+
- repo: https://github.com/compilerla/conventional-pre-commit
|
|
24
|
+
rev: 33b50eb042bee26eac0ee96ad84aa9c1b4dccdd8 # frozen: v4.5.0
|
|
25
|
+
hooks:
|
|
26
|
+
# Commit messages use the Conventional Commit types.
|
|
27
|
+
- id: conventional-pre-commit
|
|
28
|
+
stages: [commit-msg]
|
|
29
|
+
|
|
18
30
|
- repo: https://github.com/gitleaks/gitleaks
|
|
19
31
|
rev: 83d9cd684c87d95d656c1458ef04895a7f1cbd8e # frozen: v8.30.1
|
|
20
32
|
hooks:
|
|
@@ -15,4 +15,6 @@ export PRE_COMMIT_HOME="${PRE_COMMIT_HOME:-${ci_tmp}/pre-commit}"
|
|
|
15
15
|
# this checkout in a temporary Git configuration, leaving user settings untouched.
|
|
16
16
|
export GIT_CONFIG_GLOBAL="${ci_tmp}/gitconfig"
|
|
17
17
|
git config --global --add safe.directory "$(pwd -P)"
|
|
18
|
+
# CI checks out the default branch on pushes, which the local branch guard rejects.
|
|
19
|
+
export SKIP="${SKIP:+${SKIP},}no-commit-to-branch"
|
|
18
20
|
pre-commit run --all-files --show-diff-on-failure
|
package/template/AGENTS.md.tmpl
CHANGED
|
@@ -25,6 +25,9 @@ Project instructions for coding agents. Human contributors should read
|
|
|
25
25
|
- Markdown audit: `pre-commit run --hook-stage manual rumdl-check --all-files`.
|
|
26
26
|
- Install local hooks explicitly with `pre-commit install` after installing the
|
|
27
27
|
development tool. Generation never installs hooks or modifies Git settings.
|
|
28
|
+
- A `commit-msg` hook enforces Conventional Commit messages, and
|
|
29
|
+
`no-commit-to-branch` refuses commits and merge commits on `@@DEFAULT_BRANCH@@`. Work on a branch;
|
|
30
|
+
do not bypass either hook unless the maintainer asks.
|
|
28
31
|
@@END_TIERS@@
|
|
29
32
|
|
|
30
33
|
## Layout
|
package/template/SETUP.md.tmpl
CHANGED
|
@@ -21,15 +21,24 @@ apply labels, enable features, configure protections, or run destination CI.
|
|
|
21
21
|
|
|
22
22
|
- [ ] Create an empty destination repository with the intended visibility at @@REPO_URL@@.
|
|
23
23
|
- [ ] Initialize this directory with Git and set the default branch to `@@DEFAULT_BRANCH@@`.
|
|
24
|
+
- [ ] Review every file before committing and pushing. No master-template Git history is included.
|
|
24
25
|
@@TIERS regular full@@
|
|
26
|
+
- [ ] Make the first commit on `@@DEFAULT_BRANCH@@` before installing hooks: the
|
|
27
|
+
hooks refuse commits and merge commits on that branch.
|
|
25
28
|
- [ ] Install pre-commit as a development tool, review `.pre-commit-config.yaml`,
|
|
26
|
-
then run `pre-commit install
|
|
27
|
-
|
|
29
|
+
then run `pre-commit install`. Check the files once with
|
|
30
|
+
`SKIP=no-commit-to-branch pre-commit run --all-files`, since the branch guard
|
|
31
|
+
fails on `@@DEFAULT_BRANCH@@` itself, or run `pre-commit run --all-files` from a
|
|
32
|
+
topic branch. Hook environments need network access on the first run;
|
|
33
|
+
generation itself remains offline.
|
|
34
|
+
- [ ] Work on short branches from here on. The installed hooks check commit messages
|
|
35
|
+
for Conventional Commits and refuse commits and merge commits on
|
|
36
|
+
`@@DEFAULT_BRANCH@@`. For a deliberate commit there, run
|
|
37
|
+
`SKIP=no-commit-to-branch git commit`.
|
|
28
38
|
- [ ] Confirm CI can run `.repo/ci-checks.sh`: Git, Bash, Python with pip/venv,
|
|
29
39
|
and access to the pinned hook/tool sources are required. Hook runtimes are managed
|
|
30
40
|
by pre-commit; no separately installed Go toolchain is required.
|
|
31
41
|
@@END_TIERS@@
|
|
32
|
-
- [ ] Review every file before committing and pushing. No master-template Git history is included.
|
|
33
42
|
- [ ] Set the description, topics, and access permissions on the destination.
|
|
34
43
|
@@TIERS regular full@@
|
|
35
44
|
- [ ] Review `@@PLATFORM_DIR@@/CODEOWNERS`; no owner is inferred from a group namespace.
|
|
@@ -12,20 +12,25 @@ Clone [the repository](@@REPO_URL@@), then follow these steps:
|
|
|
12
12
|
> Keep them consistent with `AGENTS.md` and `@@CI_FILE@@`.
|
|
13
13
|
|
|
14
14
|
For the shared development checks, install pre-commit in your development environment,
|
|
15
|
-
then explicitly install the local
|
|
15
|
+
then explicitly install the local hooks. Run the checks from a topic branch: on
|
|
16
|
+
`@@DEFAULT_BRANCH@@` itself the branch guard fails by design.
|
|
16
17
|
|
|
17
18
|
```sh
|
|
18
19
|
pre-commit install
|
|
20
|
+
git switch -c improve-export
|
|
19
21
|
pre-commit run --all-files --show-diff-on-failure
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
The first run downloads pinned hook sources and their managed runtimes. The hooks
|
|
23
25
|
check conflicts, file types, case collisions, file size, secrets, EditorConfig,
|
|
24
|
-
shell scripts, and native Actions workflows where applicable. Markdown lint is
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
shell scripts, and native Actions workflows where applicable. Markdown lint is an
|
|
27
|
+
optional audit: `pre-commit run --hook-stage manual rumdl-check --all-files`.
|
|
28
|
+
`pre-commit install` also adds a commit-message hook that requires Conventional
|
|
29
|
+
Commits, and a check that refuses commits and merge commits on `@@DEFAULT_BRANCH@@`,
|
|
30
|
+
so changes go through a branch and a change request. CI runs the automatic checks
|
|
31
|
+
through `.repo/ci-checks.sh` and native lint jobs. Forgejo/GitHub skip only the
|
|
32
|
+
hooks already covered by their pinned native jobs; local hooks still run the
|
|
33
|
+
complete set.
|
|
29
34
|
|
|
30
35
|
## Reporting issues
|
|
31
36
|
|