@ligeti/shell 1.2.0 → 1.3.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/README.md +33 -0
- package/dist/cli/installed-versions.d.ts +9 -0
- package/dist/cli/installed-versions.d.ts.map +1 -0
- package/dist/cli/installed-versions.js +50 -0
- package/dist/cli/installed-versions.js.map +1 -0
- package/dist/cli/plugin.d.ts +13 -0
- package/dist/cli/plugin.d.ts.map +1 -0
- package/dist/cli/plugin.js +188 -0
- package/dist/cli/plugin.js.map +1 -0
- package/dist/cli/pre-push.d.ts +12 -0
- package/dist/cli/pre-push.d.ts.map +1 -0
- package/dist/cli/pre-push.js +56 -0
- package/dist/cli/pre-push.js.map +1 -0
- package/dist/cli/share-dir.d.ts +3 -0
- package/dist/cli/share-dir.d.ts.map +1 -0
- package/dist/cli/share-dir.js +13 -0
- package/dist/cli/share-dir.js.map +1 -0
- package/dist/cli/version.d.ts +6 -0
- package/dist/cli/version.d.ts.map +1 -0
- package/dist/cli/version.js +14 -0
- package/dist/cli/version.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +31 -4
- package/dist/cli.js.map +1 -1
- package/package.json +6 -5
- package/share/.claude-plugin/marketplace.json +14 -0
- package/share/plugins/ligeti/.claude-plugin/plugin.json +6 -0
- package/share/plugins/ligeti/README.md +31 -0
- package/share/plugins/ligeti/docs/attestation.md +590 -0
- package/share/plugins/ligeti/docs/shell.md +417 -0
- package/share/plugins/ligeti/docs/troubleshooting.md +28 -0
- package/share/plugins/ligeti/references/rules.md +93 -0
- package/share/plugins/ligeti/skills/authoring-steps/SKILL.md +147 -0
- package/share/plugins/ligeti/skills/authoring-workflows/SKILL.md +142 -0
- package/share/plugins/ligeti/skills/installing-workflows/SKILL.md +121 -0
- package/share/plugins/ligeti/skills/onboard/SKILL.md +290 -0
- package/share/plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.github.yml +66 -0
- package/share/plugins/ligeti/skills/onboard/assets/ligeti-verify-attestation.yml +69 -0
- package/share/plugins/ligeti/skills/onboard/assets/pre-push.sh +11 -0
- package/share/plugins/ligeti/skills/scheduling-workflows/SKILL.md +102 -0
- package/share/plugins/ligeti/skills/troubleshooting/SKILL.md +94 -0
- package/share/plugins/ligeti/templates/step/.prettierignore +3 -0
- package/share/plugins/ligeti/templates/step/README.md +52 -0
- package/share/plugins/ligeti/templates/step/eslint.config.js +105 -0
- package/share/plugins/ligeti/templates/step/package.json +45 -0
- package/share/plugins/ligeti/templates/step/src/index.ts +3 -0
- package/share/plugins/ligeti/templates/step/src/settings.ts +27 -0
- package/share/plugins/ligeti/templates/step/src/tool-version.ts +61 -0
- package/share/plugins/ligeti/templates/step/test/rules.test.ts +144 -0
- package/share/plugins/ligeti/templates/step/test/settings.test.ts +30 -0
- package/share/plugins/ligeti/templates/step/test/tool-version.feature +32 -0
- package/share/plugins/ligeti/templates/step/tsconfig.build.json +26 -0
- package/share/plugins/ligeti/templates/step/tsconfig.json +21 -0
- package/share/plugins/ligeti/templates/workflow/.prettierignore +3 -0
- package/share/plugins/ligeti/templates/workflow/README.md +56 -0
- package/share/plugins/ligeti/templates/workflow/eslint.config.js +99 -0
- package/share/plugins/ligeti/templates/workflow/package.json +46 -0
- package/share/plugins/ligeti/templates/workflow/src/workflow.ts +72 -0
- package/share/plugins/ligeti/templates/workflow/test/__snapshots__/workflow.test.ts.snap +132 -0
- package/share/plugins/ligeti/templates/workflow/test/rules.test.ts +160 -0
- package/share/plugins/ligeti/templates/workflow/test/template-workflow.feature +31 -0
- package/share/plugins/ligeti/templates/workflow/test/workflow.test.ts +64 -0
- package/share/plugins/ligeti/templates/workflow/tsconfig.build.json +26 -0
- package/share/plugins/ligeti/templates/workflow/tsconfig.json +21 -0
- package/share/scripts/pre-push-gate.sh +308 -0
- package/share/scripts/pre-push-lib.sh +64 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ABOUTME: Pre-push gate: for every branch commit being pushed, verifies its published attestation,
|
|
3
|
+
# ABOUTME: and asks the ligeti shell to gate and publish it when none is fresh (docs/attestation.md).
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
REMOTE_NAME="${1:-}"
|
|
7
|
+
REMOTE_URL="${2:-}"
|
|
8
|
+
REMOTE_URL="$(printf '%s' "$REMOTE_URL" | sed -E 's#^(https?://)[^/@]*@#\1#')"
|
|
9
|
+
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
|
10
|
+
LIB_PATH="$(dirname "$0")/pre-push-lib.sh"
|
|
11
|
+
# shellcheck source=/dev/null
|
|
12
|
+
source "$LIB_PATH"
|
|
13
|
+
|
|
14
|
+
fail() {
|
|
15
|
+
echo "pre-push: $*" >&2
|
|
16
|
+
exit 1
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if [ -n "${LIGETI_GATE_ATTEST_CLI:-}" ] && [ -n "${LIGETI_GATE_LIGETI_CLI:-}" ]; then
|
|
20
|
+
ATTEST_CLI="$LIGETI_GATE_ATTEST_CLI"
|
|
21
|
+
LIGETI_CLI="$LIGETI_GATE_LIGETI_CLI"
|
|
22
|
+
LIGETI_CMD="ligeti"
|
|
23
|
+
START_HINT="\`ligeti serve\`"
|
|
24
|
+
MISSING_HINT="reinstall @ligeti/shell"
|
|
25
|
+
else
|
|
26
|
+
LIGETI_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
27
|
+
ATTEST_CLI="$LIGETI_ROOT/packages/attest/dist/cli/attest.js"
|
|
28
|
+
LIGETI_CLI="$LIGETI_ROOT/packages/shell/dist/cli/serve.js"
|
|
29
|
+
|
|
30
|
+
if [ ! -f "$ATTEST_CLI" ] || [ ! -f "$LIGETI_CLI" ]; then
|
|
31
|
+
GIT_COMMON_DIR=""
|
|
32
|
+
if ! GIT_COMMON_DIR="$(cd "$LIGETI_ROOT" && git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"; then
|
|
33
|
+
GIT_COMMON_DIR=""
|
|
34
|
+
fi
|
|
35
|
+
if [ -n "$GIT_COMMON_DIR" ] && MAIN_ROOT="$(cd "$GIT_COMMON_DIR/.." 2>/dev/null && pwd)"; then
|
|
36
|
+
MAIN_ATTEST_CLI="$MAIN_ROOT/packages/attest/dist/cli/attest.js"
|
|
37
|
+
MAIN_LIGETI_CLI="$MAIN_ROOT/packages/shell/dist/cli/serve.js"
|
|
38
|
+
if [ "$MAIN_ROOT" != "$LIGETI_ROOT" ] && [ -f "$MAIN_ATTEST_CLI" ] && [ -f "$MAIN_LIGETI_CLI" ]; then
|
|
39
|
+
LIGETI_ROOT="$MAIN_ROOT"
|
|
40
|
+
ATTEST_CLI="$MAIN_ATTEST_CLI"
|
|
41
|
+
LIGETI_CLI="$MAIN_LIGETI_CLI"
|
|
42
|
+
fi
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
LIGETI_CMD="node $LIGETI_CLI"
|
|
46
|
+
START_HINT="\`pnpm serve\` in $LIGETI_ROOT"
|
|
47
|
+
MISSING_HINT="run \`pnpm build\` in $LIGETI_ROOT (or in this repository's main checkout)"
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
BASE_URL="${LIGETI_GATE_BASE_URL:-${LIGETI_PUBLIC_BASE_URL:-http://127.0.0.1:8100}}"
|
|
51
|
+
NODE="${LIGETI_GATE_NODE:-node}"
|
|
52
|
+
MIN_REMAINING_HOURS=12
|
|
53
|
+
PACKAGE_NAME="ligeti-attestation"
|
|
54
|
+
FILE_NAME="attestation.json"
|
|
55
|
+
|
|
56
|
+
for cli in "$ATTEST_CLI" "$LIGETI_CLI"; do
|
|
57
|
+
[ -f "$cli" ] || fail "$cli is missing -- $MISSING_HINT, then push again"
|
|
58
|
+
done
|
|
59
|
+
|
|
60
|
+
STORE="${LIGETI_ATTESTATION_STORE:-}"
|
|
61
|
+
if [ -z "$STORE" ]; then
|
|
62
|
+
STORE="$(store_for_remote_url "$REMOTE_URL")"
|
|
63
|
+
if [ "$STORE" = "git-notes" ]; then
|
|
64
|
+
echo "pre-push: $REMOTE_NAME is not hosted on gitlab.com, so attestations are kept as git notes" \
|
|
65
|
+
"-- set LIGETI_ATTESTATION_STORE=gitlab-registry to use a GitLab package registry instead" >&2
|
|
66
|
+
fi
|
|
67
|
+
fi
|
|
68
|
+
case "$STORE" in
|
|
69
|
+
gitlab-registry | git-notes) ;;
|
|
70
|
+
*) fail "unknown LIGETI_ATTESTATION_STORE \"$STORE\" (expected gitlab-registry or git-notes)" ;;
|
|
71
|
+
esac
|
|
72
|
+
|
|
73
|
+
NOTES_REF="refs/notes/ligeti-attestations"
|
|
74
|
+
PROJECT_URL=""
|
|
75
|
+
if [ "$STORE" = "gitlab-registry" ]; then
|
|
76
|
+
case "$REMOTE_URL" in
|
|
77
|
+
git@*:*)
|
|
78
|
+
host="${REMOTE_URL#git@}"
|
|
79
|
+
host="${host%%:*}"
|
|
80
|
+
project_path="${REMOTE_URL#*:}"
|
|
81
|
+
PROJECT_URL="https://${host}/${project_path%.git}"
|
|
82
|
+
;;
|
|
83
|
+
https://* | http://*)
|
|
84
|
+
PROJECT_URL="${REMOTE_URL%.git}"
|
|
85
|
+
;;
|
|
86
|
+
*)
|
|
87
|
+
fail "cannot tell which GitLab project \"$REMOTE_URL\" is -- expected git@host:path or http(s)://host/path"
|
|
88
|
+
;;
|
|
89
|
+
esac
|
|
90
|
+
PROJECT_URL="${PROJECT_URL%/}"
|
|
91
|
+
ORIGIN="$(printf '%s' "$PROJECT_URL" | sed -E 's#^(https?://[^/]+).*#\1#')"
|
|
92
|
+
PROJECT_PATH="${PROJECT_URL#"$ORIGIN"/}"
|
|
93
|
+
ENCODED_PROJECT="$(printf '%s' "$PROJECT_PATH" | sed 's#/#%2F#g')"
|
|
94
|
+
HOST="${ORIGIN#*://}"
|
|
95
|
+
|
|
96
|
+
TOKEN="${GITLAB_TOKEN:-${GITLAB_ACCESS_TOKEN:-}}"
|
|
97
|
+
if [ -z "$TOKEN" ] && command -v glab >/dev/null 2>&1; then
|
|
98
|
+
TOKEN="$(glab config get token --host "$HOST" 2>/dev/null || true)"
|
|
99
|
+
fi
|
|
100
|
+
if [ -z "$TOKEN" ]; then
|
|
101
|
+
fail "no GitLab token to read $PROJECT_URL's package registry with -- export GITLAB_TOKEN" \
|
|
102
|
+
"(or GITLAB_ACCESS_TOKEN), or log in with \`glab auth login --hostname $HOST\`"
|
|
103
|
+
fi
|
|
104
|
+
if [[ "$TOKEN" == *'"'* || "$TOKEN" == *\\* || "$TOKEN" == *$'\n'* ]]; then
|
|
105
|
+
fail "the GitLab token contains a \", \\, or newline character, which is not safe to write" \
|
|
106
|
+
"into curl's config file -- check GITLAB_TOKEN/GITLAB_ACCESS_TOKEN or your glab login"
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
WORK_DIR="$(mktemp -d)"
|
|
111
|
+
trap 'rm -rf "$WORK_DIR"' EXIT
|
|
112
|
+
|
|
113
|
+
fetch_registry_attestation() {
|
|
114
|
+
local sha="$1" url status
|
|
115
|
+
url="${ORIGIN}/api/v4/projects/${ENCODED_PROJECT}/packages/generic/${PACKAGE_NAME}/${sha}/${FILE_NAME}"
|
|
116
|
+
status="$(curl --silent --show-error --location --output "$WORK_DIR/$sha.json" \
|
|
117
|
+
--write-out '%{http_code}' --config - "$url" <<CURLCFG
|
|
118
|
+
header = "PRIVATE-TOKEN: $TOKEN"
|
|
119
|
+
CURLCFG
|
|
120
|
+
)" ||
|
|
121
|
+
fail "could not reach $ORIGIN to fetch the attestation for $sha"
|
|
122
|
+
case "$status" in
|
|
123
|
+
200) return 0 ;;
|
|
124
|
+
404) return 1 ;;
|
|
125
|
+
*) fail "fetching the attestation for $sha returned HTTP $status from $url" ;;
|
|
126
|
+
esac
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
fetch_notes_attestation() {
|
|
130
|
+
local sha="$1" fetch_err="$WORK_DIR/$1.fetch-err" ls_status=0
|
|
131
|
+
git -C "$REPO_ROOT" ls-remote --exit-code "$REMOTE_NAME" "$NOTES_REF" \
|
|
132
|
+
</dev/null >/dev/null 2>"$fetch_err" || ls_status=$?
|
|
133
|
+
case "$ls_status" in
|
|
134
|
+
0) ;;
|
|
135
|
+
2)
|
|
136
|
+
git -C "$REPO_ROOT" update-ref -d "$NOTES_REF" </dev/null
|
|
137
|
+
return 1
|
|
138
|
+
;;
|
|
139
|
+
*)
|
|
140
|
+
cat "$fetch_err" >&2
|
|
141
|
+
fail "could not reach $REMOTE_NAME to look for $NOTES_REF while reading the attestation for $sha"
|
|
142
|
+
;;
|
|
143
|
+
esac
|
|
144
|
+
if ! git -C "$REPO_ROOT" fetch --quiet --no-tags "$REMOTE_NAME" "+$NOTES_REF:$NOTES_REF" \
|
|
145
|
+
</dev/null 2>"$fetch_err"; then
|
|
146
|
+
cat "$fetch_err" >&2
|
|
147
|
+
fail "could not fetch $NOTES_REF from $REMOTE_NAME to read the attestation for $sha"
|
|
148
|
+
fi
|
|
149
|
+
local show_err="$WORK_DIR/$sha.show-err"
|
|
150
|
+
if ! LC_ALL=C git -C "$REPO_ROOT" notes --ref=ligeti-attestations show "$sha" \
|
|
151
|
+
</dev/null >"$WORK_DIR/$sha.json" 2>"$show_err"; then
|
|
152
|
+
if grep -qi "no note found" "$show_err"; then
|
|
153
|
+
return 1
|
|
154
|
+
fi
|
|
155
|
+
cat "$show_err" >&2
|
|
156
|
+
fail "could not read the attestation note for $sha from $NOTES_REF"
|
|
157
|
+
fi
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fetch_attestation() {
|
|
161
|
+
if [ "$STORE" = "git-notes" ]; then
|
|
162
|
+
fetch_notes_attestation "$1"
|
|
163
|
+
else
|
|
164
|
+
fetch_registry_attestation "$1"
|
|
165
|
+
fi
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
require_named_remote() {
|
|
169
|
+
[ "$STORE" = "git-notes" ] || return 0
|
|
170
|
+
if ! is_safe_remote_name "$REMOTE_NAME" || [ "$REMOTE_NAME" = "$REMOTE_URL" ]; then
|
|
171
|
+
fail "git-notes attestations are published to a named git remote, but this push targets" \
|
|
172
|
+
"\"$REMOTE_NAME\" -- add it with \`git remote add <name> <url>\` and push to that name"
|
|
173
|
+
fi
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
verify_attestation() {
|
|
177
|
+
local sha="$1" base_args=()
|
|
178
|
+
if [ -n "$BASE_SHA" ]; then
|
|
179
|
+
base_args=(--base "$BASE_SHA")
|
|
180
|
+
fi
|
|
181
|
+
"$NODE" "$ATTEST_CLI" verify --repo "$REPO_ROOT" --commit "$sha" --no-drift-guard \
|
|
182
|
+
--min-remaining-hours "$MIN_REMAINING_HOURS" --envelope-file "$WORK_DIR/$sha.json" \
|
|
183
|
+
${base_args[@]+"${base_args[@]}"} </dev/null >"$WORK_DIR/$sha.verify" 2>&1
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
run_input() {
|
|
187
|
+
local sha="$1" replace="$2"
|
|
188
|
+
"$NODE" -e '
|
|
189
|
+
const [repoPath, commit, store, remote, projectUrl, minRemainingHours, replace, base] =
|
|
190
|
+
process.argv.slice(1);
|
|
191
|
+
process.stdout.write(JSON.stringify({
|
|
192
|
+
repoPath, commit, store, minRemainingHours: Number(minRemainingHours),
|
|
193
|
+
...(store === "git-notes" ? { remote } : { projectUrl }),
|
|
194
|
+
...(replace === "true" ? { replace: true } : {}),
|
|
195
|
+
...(base === "" ? {} : { base }),
|
|
196
|
+
}));
|
|
197
|
+
' "$REPO_ROOT" "$sha" "$STORE" "$REMOTE_NAME" "$PROJECT_URL" "$MIN_REMAINING_HOURS" "$replace" \
|
|
198
|
+
"$BASE_SHA" </dev/null
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
print_trace_hint() {
|
|
202
|
+
local run_id="$1"
|
|
203
|
+
if [ -n "$run_id" ]; then
|
|
204
|
+
echo "pre-push: attest-and-publish run $run_id; read the full output with:" >&2
|
|
205
|
+
echo " $LIGETI_CMD trace $run_id --url $BASE_URL" >&2
|
|
206
|
+
fi
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
gate_and_publish() {
|
|
210
|
+
local sha="$1" replace="$2" input result run_id="" started_pattern='started attest-and-publish as ([^[:space:]]+)'
|
|
211
|
+
input="$(run_input "$sha" "$replace")"
|
|
212
|
+
if ! curl --silent --fail --output /dev/null "$BASE_URL/healthz" </dev/null; then
|
|
213
|
+
echo "pre-push: no ligeti shell answers at $BASE_URL, so $sha cannot be gated." >&2
|
|
214
|
+
echo "pre-push: start one with $START_HINT (attest-and-publish is a default workflow;" >&2
|
|
215
|
+
echo "pre-push: a set LIGETI_WORKFLOWS must list its absolute directory), then push again -- or gate it by hand with:" >&2
|
|
216
|
+
echo " echo '$input' | $LIGETI_CMD run --url $BASE_URL --wait attest-and-publish" >&2
|
|
217
|
+
exit 1
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
echo "pre-push: gating $sha in a fresh checkout -- this runs the whole gate" >&2
|
|
221
|
+
local run_stderr="$WORK_DIR/$sha.run-stderr" run_stdout="$WORK_DIR/$sha.run-stdout" run_ok=true
|
|
222
|
+
if ! printf '%s' "$input" | "$NODE" "$LIGETI_CLI" run --url "$BASE_URL" --wait attest-and-publish \
|
|
223
|
+
2>&1 >"$run_stdout" | tee "$run_stderr" >&2; then
|
|
224
|
+
run_ok=false
|
|
225
|
+
fi
|
|
226
|
+
result="$(cat "$run_stdout")"
|
|
227
|
+
if [[ "$(cat "$run_stderr")" =~ $started_pattern ]]; then
|
|
228
|
+
run_id="${BASH_REMATCH[1]}"
|
|
229
|
+
fi
|
|
230
|
+
if [ "$run_ok" = false ]; then
|
|
231
|
+
print_trace_hint "$run_id"
|
|
232
|
+
fail "attest-and-publish failed for $sha -- see the error above"
|
|
233
|
+
fi
|
|
234
|
+
|
|
235
|
+
local report
|
|
236
|
+
report="$(
|
|
237
|
+
cat <<'REPORT_JS'
|
|
238
|
+
const [sha, raw] = process.argv.slice(1);
|
|
239
|
+
const result = JSON.parse(raw);
|
|
240
|
+
if (result.predicate.result !== "passed") {
|
|
241
|
+
const failed = result.predicate.checks
|
|
242
|
+
.filter((check) => check.required && check.status !== "passed")
|
|
243
|
+
.map((check) => `${check.id} (${check.status}${check.detail ? `: ${check.detail}` : ""})`);
|
|
244
|
+
process.stderr.write(`pre-push: the gate failed for ${sha}: ${failed.join(", ")}\n`);
|
|
245
|
+
for (const { id, stderr } of result.failedChecks ?? []) {
|
|
246
|
+
process.stderr.write(`pre-push: stderr of gate check ${id}:\n`);
|
|
247
|
+
const text = stderr.trimEnd();
|
|
248
|
+
process.stderr.write(text === "" ? " (no stderr)\n" : `${text.replace(/^/gm, " ")}\n`);
|
|
249
|
+
}
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
if (result.publish === undefined) {
|
|
253
|
+
process.stderr.write(`pre-push: the gate passed for ${sha} but nothing was published\n`);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
process.stderr.write(`pre-push: attestation ${result.publish.status} for ${sha}\n`);
|
|
257
|
+
REPORT_JS
|
|
258
|
+
)"
|
|
259
|
+
if ! "$NODE" -e "$report" "$sha" "$result" </dev/null; then
|
|
260
|
+
print_trace_hint "$run_id"
|
|
261
|
+
exit 1
|
|
262
|
+
fi
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
ZERO_SHA_PATTERN='^0+$'
|
|
266
|
+
seen=" "
|
|
267
|
+
BASE_SHA=""
|
|
268
|
+
base_resolved=false
|
|
269
|
+
while read -r _local_ref local_sha remote_ref _remote_sha; do
|
|
270
|
+
if [[ "$local_sha" =~ $ZERO_SHA_PATTERN ]]; then
|
|
271
|
+
continue
|
|
272
|
+
fi
|
|
273
|
+
case "$remote_ref" in
|
|
274
|
+
refs/heads/*) ;;
|
|
275
|
+
*) continue ;;
|
|
276
|
+
esac
|
|
277
|
+
case "$seen" in
|
|
278
|
+
*" $local_sha "*) continue ;;
|
|
279
|
+
esac
|
|
280
|
+
seen="$seen$local_sha "
|
|
281
|
+
|
|
282
|
+
require_named_remote
|
|
283
|
+
if [ "$base_resolved" = false ]; then
|
|
284
|
+
BASE_SHA="$(push_base_sha "$REPO_ROOT" "$REMOTE_NAME")"
|
|
285
|
+
base_resolved=true
|
|
286
|
+
fi
|
|
287
|
+
replace=false
|
|
288
|
+
if fetch_attestation "$local_sha"; then
|
|
289
|
+
if verify_attestation "$local_sha"; then
|
|
290
|
+
echo "pre-push: $local_sha has a fresh attestation" >&2
|
|
291
|
+
continue
|
|
292
|
+
fi
|
|
293
|
+
if verify_failed_beyond_freshness "$WORK_DIR/$local_sha.verify"; then
|
|
294
|
+
echo "pre-push: the attestation published for $local_sha does not verify, replacing it" >&2
|
|
295
|
+
replace=true
|
|
296
|
+
fi
|
|
297
|
+
fi
|
|
298
|
+
|
|
299
|
+
gate_and_publish "$local_sha" "$replace"
|
|
300
|
+
|
|
301
|
+
fetch_attestation "$local_sha" ||
|
|
302
|
+
fail "the attestation for $local_sha was published but cannot be fetched back from ${ORIGIN:-$REMOTE_NAME}"
|
|
303
|
+
if ! verify_attestation "$local_sha"; then
|
|
304
|
+
cat "$WORK_DIR/$local_sha.verify" >&2
|
|
305
|
+
fail "the attestation published for $local_sha does not verify -- see the checks above"
|
|
306
|
+
fi
|
|
307
|
+
echo "pre-push: $local_sha verified" >&2
|
|
308
|
+
done
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ABOUTME: Pure helpers sourced by pre-push-gate.sh: the remote-host rule that picks the attestation store,
|
|
3
|
+
# ABOUTME: the git remote name rule, the push's base commit, and the reading of `ligeti-attest verify` output. Kept apart so tests can call them.
|
|
4
|
+
|
|
5
|
+
remote_host() {
|
|
6
|
+
local url="$1" host=""
|
|
7
|
+
case "$url" in
|
|
8
|
+
*://*)
|
|
9
|
+
host="${url#*://}"
|
|
10
|
+
host="${host%%/*}"
|
|
11
|
+
host="${host##*@}"
|
|
12
|
+
case "$host" in
|
|
13
|
+
\[*\]*) host="${host%%]*}]" ;;
|
|
14
|
+
*) host="${host%%:*}" ;;
|
|
15
|
+
esac
|
|
16
|
+
;;
|
|
17
|
+
/* | ./* | ../*) ;;
|
|
18
|
+
*:*)
|
|
19
|
+
host="${url%%:*}"
|
|
20
|
+
case "$host" in
|
|
21
|
+
*/*) host="" ;;
|
|
22
|
+
*) host="${host##*@}" ;;
|
|
23
|
+
esac
|
|
24
|
+
;;
|
|
25
|
+
*) ;;
|
|
26
|
+
esac
|
|
27
|
+
printf '%s' "$host" | tr '[:upper:]' '[:lower:]'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
store_for_remote_url() {
|
|
31
|
+
if [ "$(remote_host "$1")" = "gitlab.com" ]; then
|
|
32
|
+
printf 'gitlab-registry'
|
|
33
|
+
else
|
|
34
|
+
printf 'git-notes'
|
|
35
|
+
fi
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
is_safe_remote_name() {
|
|
39
|
+
case "$1" in
|
|
40
|
+
"" | -* | *..* | *[!A-Za-z0-9._/-]*) return 1 ;;
|
|
41
|
+
esac
|
|
42
|
+
return 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
verify_failed_beyond_freshness() {
|
|
46
|
+
grep '^\[FAIL\] ' "$1" | grep -qv '^\[FAIL\] freshness:' ||
|
|
47
|
+
grep -q '^\[FAIL\] freshness: .* is in the future beyond the ' "$1"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
push_base_sha() {
|
|
51
|
+
local repo="$1" remote="$2" sha=""
|
|
52
|
+
[ -n "$remote" ] || return 0
|
|
53
|
+
if is_safe_remote_name "$remote"; then
|
|
54
|
+
sha="$(git -C "$repo" rev-parse --verify --quiet "refs/remotes/$remote/HEAD^{commit}" </dev/null 2>/dev/null)" || sha=""
|
|
55
|
+
fi
|
|
56
|
+
if [ -z "$sha" ]; then
|
|
57
|
+
sha="$(git -C "$repo" ls-remote --symref -- "$remote" HEAD </dev/null 2>/dev/null |
|
|
58
|
+
awk -F'\t' '$2 == "HEAD" && $1 !~ /^ref:/ { print $1; exit }')" || sha=""
|
|
59
|
+
if [ -n "$sha" ] && ! git -C "$repo" cat-file -e "$sha^{commit}" </dev/null 2>/dev/null; then
|
|
60
|
+
sha=""
|
|
61
|
+
fi
|
|
62
|
+
fi
|
|
63
|
+
printf '%s' "$sha"
|
|
64
|
+
}
|