返回 last30days-skill
build-skill.sh
根目录 / skills / last30days / scripts / build-skill.sh
1 #!/usr/bin/env bash
2 # build-skill.sh - package this repo as a claude.ai-upload-ready .skill file
3 # Usage: bash skills/last30days/scripts/build-skill.sh (run from repo root)
4 #
5 # Produces dist/last30days.skill, a zip with a single top-level `last30days/`
6 # directory containing SKILL.md and the scripts/ runtime from skills/last30days.
7 # See
8 # docs/plans/2026-04-14-001-fix-skill-upload-200-file-limit-plan.md.
9 set -euo pipefail
10
11 REPO_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
12 cd "$REPO_ROOT"
13
14 if ! git diff --quiet || ! git diff --cached --quiet; then
15 echo "error: working tree is dirty; commit or stash before building" >&2
16 exit 1
17 fi
18
19 mkdir -p dist
20 OUT="dist/last30days.skill"
21 STAGING=$(mktemp -d "dist/.last30days-skill.XXXXXXXX")
22 ARCHIVE="$STAGING/last30days.skill"
23 trap 'rm -f -- "$ARCHIVE"; rmdir -- "$STAGING"' EXIT
24 git archive --format=zip --prefix=last30days/ --output="$ARCHIVE" HEAD:skills/last30days \
25 ':(exclude)assets' \
26 ':(exclude)scripts/compare.sh' \
27 ':(exclude)scripts/verify_v3.py' \
28 ':(exclude,glob)scripts/test[-_]*'
29
30 ENTRIES=$(unzip -Z1 "$ARCHIVE")
31 COUNT=$(awk '!/\/$/ { count++ } END { print count + 0 }' <<<"$ENTRIES")
32
33 if [ "$COUNT" -gt 200 ]; then
34 echo "error: $COUNT files in zip, claude.ai's cap is 200" >&2
35 exit 1
36 fi
37
38 SKILL_MD_COUNT=$(awk '/(^|\/)SKILL\.md$/ { count++ } END { print count + 0 }' <<<"$ENTRIES")
39 if [ "$SKILL_MD_COUNT" -ne 1 ] || ! grep -Fxq 'last30days/SKILL.md' <<<"$ENTRIES"; then
40 echo "error: expected exactly one SKILL.md at last30days/SKILL.md" >&2
41 exit 1
42 fi
43
44 SIZE=$(du -h "$ARCHIVE" | cut -f1)
45 python3 -I - "$ARCHIVE" "$OUT" <<'PY'
46 import os
47 import sys
48
49 source, output = sys.argv[1:]
50 if os.path.isdir(output):
51 sys.exit(f"error: cannot replace {output}: destination is a directory")
52 try:
53 os.replace(source, output)
54 except OSError as exc:
55 sys.exit(f"error: cannot replace {output}: {exc.strerror}")
56 PY
57 echo "built $OUT ($COUNT files, $SIZE)"
58 echo "upload via the claude.ai skill UI"
59
59 lines BASH