@marktiderman/genesis-cli 1.23.0 → 1.25.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.
@@ -0,0 +1,26 @@
1
+ # Copy to .github/workflows/claude-review.yml. Replace GENESIS_SHA with the commit of the
2
+ # Genesis release you run (docs/APP-CI.md in marktiderman/genesis says how).
3
+ # Claude reviews each pull request against this app's CLAUDE.md and AGENTS.md (run
4
+ # `genesis agents` so they hold the Genesis guide). Needs the Claude GitHub app and the
5
+ # CLAUDE_CODE_OAUTH_TOKEN secret.
6
+ name: Claude Code Review
7
+
8
+ on:
9
+ pull_request:
10
+ types: [opened, ready_for_review, reopened] # add synchronize to review every push (each run is billed)
11
+
12
+ concurrency:
13
+ group: claude-review-${{ github.event.pull_request.number }}
14
+ cancel-in-progress: true
15
+
16
+ permissions: {}
17
+
18
+ jobs:
19
+ review:
20
+ permissions:
21
+ contents: read
22
+ pull-requests: write
23
+ issues: write
24
+ id-token: write
25
+ uses: marktiderman/genesis/.github/workflows/claude-review.yml@GENESIS_SHA # @marktiderman/genesis@X.Y.Z
26
+ secrets: inherit
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env bash
2
+ # Vercel "Ignored Build Step": production always builds; a preview builds only when someone asks.
3
+ #
4
+ # Copy to scripts/vercel-ignore-build.sh in the app and point vercel.json at it (the vercel.json
5
+ # beside this file). Replace GENESIS_SHA below with the commit of the Genesis release you copied it
6
+ # from (docs/APP-CI.md, "Which ref to call", says how to find it), so the next upgrade can tell
7
+ # whether your copy is behind. Edit the copy, not the defaults: set the variables below in the
8
+ # Vercel project instead.
9
+ #
10
+ # Genesis template templates/vercel/ignore-build.sh @ GENESIS_SHA # @marktiderman/genesis@X.Y.Z
11
+ #
12
+ # Vercel runs this before every build: exit 0 skips the build, exit 1 builds.
13
+ #
14
+ # 1. Production (VERCEL_ENV=production, the production branch) always builds. So does a deploy
15
+ # with VERCEL_ENV unset (system variables not exposed: production can't be told from a preview,
16
+ # and production must never be skipped) and a custom environment (VERCEL_TARGET_ENV set to
17
+ # something other than preview, such as staging).
18
+ # 2. GENESIS_PREVIEWS=off: no preview builds. GENESIS_PREVIEWS=every-pr: every preview builds.
19
+ # 3. GENESIS_PREVIEWS=on-demand (the default) builds a preview only when one of these asks:
20
+ # - the branch starts with GENESIS_PREVIEW_BRANCH_PREFIX (default `preview/`);
21
+ # - the commit message has `[preview]` in it (the commit being deployed, not earlier ones);
22
+ # - the pull request has the label GENESIS_PREVIEW_LABEL (default `preview`, any case), read
23
+ # from the GitHub API with GENESIS_PREVIEW_GITHUB_TOKEN (a fine-grained token with read access
24
+ # to pull requests on this repository). No token, a failed request or a non-GitHub repository
25
+ # skips: an error never starts a build.
26
+ # Everything else skips.
27
+ #
28
+ # Vercel doesn't redeploy when a label is added: push a commit (or redeploy the latest one) after
29
+ # labelling. Vercel passes VERCEL_GIT_* only with "Automatically expose System Environment
30
+ # Variables" on in the project's Environment Variables settings.
31
+
32
+ # The app's own defaults can live in genesis.config.json's "environments" block:
33
+ # { "environments": { "previews": "every-pr", "label": "preview", "branchPrefix": "preview/" } }
34
+ # A variable set in the Vercel project wins over the file; the file wins over the defaults here.
35
+ config() { # prints the value, __EMPTY__ for "", nothing when unset or unreadable
36
+ [ -f genesis.config.json ] && command -v node > /dev/null 2>&1 || return 0
37
+ node -e 'try { const v = ((JSON.parse(require("fs").readFileSync("genesis.config.json", "utf8")) || {}).environments || {})[process.argv[1]]; if (typeof v === "string") process.stdout.write(v === "" ? "__EMPTY__" : v) } catch {}' "$1" 2> /dev/null || true
38
+ }
39
+ setting() { # $1 variable name, $2 config key, $3 default
40
+ if [ -n "${!1+set}" ]; then printf '%s' "${!1}"; return; fi
41
+ local v
42
+ v="$(config "$2")"
43
+ [ "$v" = "__EMPTY__" ] && return
44
+ printf '%s' "${v:-$3}"
45
+ }
46
+ previews="$(setting GENESIS_PREVIEWS previews on-demand)"
47
+ [ -n "$previews" ] || previews=on-demand
48
+ label="$(setting GENESIS_PREVIEW_LABEL label preview)" # set but empty: no label check
49
+ prefix="$(setting GENESIS_PREVIEW_BRANCH_PREFIX branchPrefix preview/)" # set but empty: no branch check
50
+ token="${GENESIS_PREVIEW_GITHUB_TOKEN:-}"
51
+ api="${GENESIS_GITHUB_API_URL:-https://api.github.com}"
52
+
53
+ ref="${VERCEL_GIT_COMMIT_REF:-}"
54
+ message="${VERCEL_GIT_COMMIT_MESSAGE:-}"
55
+ pr="${VERCEL_GIT_PULL_REQUEST_ID:-}"
56
+
57
+ build() {
58
+ echo "genesis previews: build ($1)"
59
+ exit 1
60
+ }
61
+ skip() {
62
+ echo "genesis previews: skip ($1)"
63
+ exit 0
64
+ }
65
+
66
+ [ "${VERCEL_ENV:-}" = "production" ] && build "production"
67
+ [ -z "${VERCEL_ENV:-}" ] && build "VERCEL_ENV unset: expose System Environment Variables to build previews on demand"
68
+ case "${VERCEL_TARGET_ENV:-preview}" in
69
+ preview | production | development) ;;
70
+ *) build "custom environment ${VERCEL_TARGET_ENV}" ;;
71
+ esac
72
+
73
+ case "$previews" in
74
+ off) skip "GENESIS_PREVIEWS=off" ;;
75
+ every-pr) build "GENESIS_PREVIEWS=every-pr" ;;
76
+ on-demand) ;;
77
+ *) echo "genesis previews: unknown GENESIS_PREVIEWS=\"$previews\" (on-demand, every-pr or off); using on-demand" ;;
78
+ esac
79
+
80
+ if [ -n "$prefix" ] && [ -n "$ref" ]; then
81
+ case "$ref" in
82
+ "$prefix"*) build "branch $ref starts with $prefix" ;;
83
+ esac
84
+ fi
85
+
86
+ lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
87
+
88
+ case "$(lower "$message")" in
89
+ *"[preview]"*) build "[preview] in the commit message" ;;
90
+ esac
91
+
92
+ [ -n "$label" ] || skip "no opt-in (GENESIS_PREVIEW_LABEL is empty)"
93
+ [ "${VERCEL_GIT_PROVIDER:-github}" = "github" ] || skip "no opt-in (label check needs GitHub, not ${VERCEL_GIT_PROVIDER})"
94
+ [ -n "$token" ] || skip "no opt-in (no GENESIS_PREVIEW_GITHUB_TOKEN to read the \"$label\" label)"
95
+ owner="${VERCEL_GIT_REPO_OWNER:-}"
96
+ repo="${VERCEL_GIT_REPO_SLUG:-}"
97
+ [ -n "$owner" ] && [ -n "$repo" ] || skip "no opt-in (VERCEL_GIT_REPO_OWNER or VERCEL_GIT_REPO_SLUG is unset)"
98
+
99
+ # The pull request (by number, or the open one for this branch when Vercel has no number yet).
100
+ if [ -n "$pr" ]; then
101
+ case "$pr" in
102
+ *[!0-9]*) skip "no opt-in (VERCEL_GIT_PULL_REQUEST_ID \"$pr\" isn't a number)" ;;
103
+ esac
104
+ body="$(curl -fsS --max-time 10 \
105
+ -H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
106
+ "$api/repos/$owner/$repo/pulls/$pr" 2>/dev/null)" || skip "no opt-in (couldn't read pull request #$pr from GitHub)"
107
+ else
108
+ [ -n "$ref" ] || skip "no opt-in (no branch or pull request to read a label from)"
109
+ body="$(curl -fsS --max-time 10 --get \
110
+ -H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
111
+ --data-urlencode "state=open" --data-urlencode "head=$owner:$ref" \
112
+ "$api/repos/$owner/$repo/pulls" 2>/dev/null)" || skip "no opt-in (couldn't read the pull requests for $ref from GitHub)"
113
+ fi
114
+
115
+ # The labels' names, one per line, read with Node (which every Vercel build image has). A pull
116
+ # request list (no number) is every open pull request for this branch: a label on any of them counts.
117
+ command -v node >/dev/null 2>&1 || skip "no opt-in (no node to read GitHub's answer)"
118
+ names="$(printf '%s' "$body" | node -e '
119
+ let s = "";
120
+ process.stdin.on("data", (d) => (s += d)).on("end", () => {
121
+ const j = JSON.parse(s);
122
+ for (const pr of Array.isArray(j) ? j : [j]) for (const l of pr?.labels ?? []) console.log(String(l.name ?? ""));
123
+ });
124
+ ' 2>/dev/null)" || skip "no opt-in (GitHub's answer wasn't the JSON expected)"
125
+ want="$(lower "$label")"
126
+ while IFS= read -r name; do
127
+ [ "$(lower "$name")" = "$want" ] && build "the pull request has the \"$label\" label"
128
+ done <<EOF_NAMES
129
+ $names
130
+ EOF_NAMES
131
+ skip "no opt-in (no $prefix branch, [preview] commit or \"$label\" label)"
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://openapi.vercel.sh/vercel.json",
3
+ "ignoreCommand": "bash scripts/vercel-ignore-build.sh"
4
+ }