Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

2.2 KB
Raw Blame
#!/usr/bin/env bash
# Claude Code PreToolUse hook (Bash): before a release tag is pushed, checks that a release
# which changes the UI shows it in the release notes. Blocks (exit 2) when Sources/Cra/UI
# changed since the previous tag and the version's entry in cra-website's releases.ts has no
# `media:` clip. A release whose UI changes have nothing to film opts out with a comment in
# its entry: `// no clip: <reason>`.
set -euo pipefail

command="$(jq -r '.tool_input.command // empty')"
# Only an actual `git push` (at the start of a command, maybe after VAR=… prefixes),
# not text that mentions one.
grep -qE '(^|[;&|(]|\$\()[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=("[^"]*"|[^[:space:]]+)[[:space:]]+)*git[[:space:]]+push\b' <<<"$command" || exit 0
version="$(grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+\b' <<<"$command" | head -1)" || exit 0
[[ -n "$version" ]] || exit 0

repo="$(cd "$(dirname "$0")/../.." && pwd)"
releases="${CRA_WEBSITE:-$repo/../cra-website}/src/content/releases.ts"
[[ -f "$releases" ]] || exit 0

# The tag right below this version, and the tag itself if it exists yet (else HEAD).
previous="$(git -C "$repo" tag -l 'v*' | { cat; echo "$version"; } | sort -uV | grep -B1 -x "$version" | head -1)"
[[ -n "$previous" && "$previous" != "$version" ]] || exit 0
target="$version"; git -C "$repo" rev-parse -q --verify "refs/tags/$version" >/dev/null || target=HEAD
ui_changes="$(git -C "$repo" diff --name-only "$previous" "$target" -- Sources/Cra/UI)"
[[ -n "$ui_changes" ]] || exit 0

entry="$(awk -v v="${version#v}" '
  /^    version: "/ { inside = index($0, "\"" v "\"") > 0 }
  inside' "$releases")"

if [[ -z "$entry" ]]; then
  echo "Release $version has no entry in $releases yet. Add its release notes first (see docs/release.md)." >&2
  exit 2
fi
if grep -qE 'media: \{|// no clip:' <<<"$entry"; then
  exit 0
fi

cat >&2 <<EOF
Release $version changes the UI since $previous but its release notes have no clip:
$(sed 's/^/  /' <<<"$ui_changes" | head -15)

Record the visible change and attach it as \`media\` on the highlight in
$releases
(skill: release-clips; tools in scripts/clips/, encoder in cra-website/scripts/release-clip.sh).
If there is nothing to film, add \`// no clip: <reason>\` inside the $version entry.
EOF
exit 2