#!/usr/bin/env bash # Checks that the crate is adopted: the CI release workflow is installed and up to date with the template of # its kind (comments and step names ignored; opt out with a `# kit-workflow: custom` line), and the kit copy # (.crate-kit/) is identical to the reference kit (crate-kit + overlay, assembled by $KIT_SRC/tools/kit-assemble.sh; default ../crate-kit). Read-only. # # Compares the CONTENT, not VERSION: a fix to the kit does not always change its number. # `--fix`: instead of failing on an out-of-date workflow, replace it with the template of its kind. # Without a crate-kit repository alongside (clone of the crate alone, CI), there is nothing to compare: success. set -euo pipefail . "$(dirname "$0")/common.sh" fix=0 [ "${1:-}" = "--fix" ] && fix=1 kit_dir="$(cd "$(dirname "$0")/.." && pwd)" crate_dir="$(dirname "$kit_dir")" # Without this workflow, a version-* tag publishes nothing: the crate was not adopted all the way. workflow=".gitea/workflows/release.yaml" if [ ! -f "$crate_dir/$workflow" ]; then err "✗ $workflow is missing in $crate_dir: the release CI will not trigger" info " Complete the adoption: crate-kit/adopt.sh [--kind ] $crate_dir" exit 1 fi kit_src="${KIT_SRC:-../crate-kit}" # Workflow up to date with the template of the crate's kind (the same one adopt.sh lays down). Only the # logic counts: comment lines and `- name:` labels are ignored, so a rewording is not a difference. if [ -x "$kit_src/tools/kit-assemble.sh" ] && ! grep -q '^# kit-workflow: custom' "$crate_dir/$workflow"; then kind="${CRATE_KIND:-}" if [ -z "$kind" ] && [ -f "$crate_dir/Makefile" ]; then kind=$(sed -n 's/^CRATE_KIND *[:?]*= *\([a-z]*\).*/\1/p' "$crate_dir/Makefile" | head -n 1) fi template="$("$kit_src/tools/kit-assemble.sh" --root)/template" overlay=$("$kit_src/tools/kit-assemble.sh" --overlay 2>/dev/null || true) [ -n "$kind" ] && [ -n "$overlay" ] && [ -d "$overlay/templates/$kind" ] && template="$overlay/templates/$kind" norm() { grep -v '^ *#' "$1" | grep -v '^ *- name:' | sed 's/[[:space:]]*$//'; } if [ -f "$template/$workflow" ] && ! diff <(norm "$crate_dir/$workflow") <(norm "$template/$workflow") >/dev/null; then if [ "$fix" = 1 ]; then cp "$template/$workflow" "$crate_dir/$workflow" ok "→ $workflow replaced with the template of its kind" else err "✗ $workflow differs from the template of its kind: the release CI is out of date" diff <(norm "$crate_dir/$workflow") <(norm "$template/$workflow") >&2 || true info " Replace it: cp $template/$workflow $crate_dir/$workflow" info " (keep a deliberate customization by adding the line \"# kit-workflow: custom\" to the workflow)" exit 1 fi fi fi if [ ! -x "$kit_src/tools/kit-assemble.sh" ]; then info " (reference kit not found: $kit_src, check skipped)" exit 0 fi ref="$(mktemp -d "${TMPDIR:-/tmp}/kit-check.XXXXXX")" trap 'rm -r "$ref"' EXIT "$kit_src/tools/kit-assemble.sh" "$ref" if diff -rq "$ref" "$kit_dir" >/dev/null 2>&1; then ok "✓ Kit up to date (crate-kit $(cat "$ref/VERSION"))" exit 0 fi err "✗ This crate's kit is not the one from $kit_src:" diff -rq "$ref" "$kit_dir" >&2 || true info " Update: make kit-update" exit 1