#!/usr/bin/env bash set -euo pipefail # create-release-packages.sh (workflow-local) # Build Spec Kit template release archives for each supported AI assistant and script type. # Usage: .github/workflows/scripts/create-release-packages.sh # Version argument should include leading 'v'. # Optionally set AGENTS and/or SCRIPTS env vars to limit what gets built. # AGENTS : space or comma separated subset of: claude gemini copilot (default: all) # SCRIPTS : space or comma separated subset of: sh ps (default: both) # Examples: # AGENTS=claude SCRIPTS=sh $0 v0.2.0 # AGENTS="copilot,gemini" $0 v0.2.0 # SCRIPTS=ps $0 v0.2.0 if [[ $# -ne 1 ]]; then echo "Usage: $0 " >&2 exit 1 fi NEW_VERSION="$1" if [[ ! $NEW_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Version must look like v0.0.0" >&2 exit 1 fi echo "Building release packages for $NEW_VERSION" rm -rf sdd-package-base* sdd-*-package-* spec-kit-template-*-${NEW_VERSION}.zip || true mkdir -p sdd-package-base SPEC_DIR="sdd-package-base/.specify" mkdir -p "$SPEC_DIR" [[ -d memory ]] && { cp -r memory "$SPEC_DIR/"; echo "Copied memory -> .specify"; } [[ -d scripts ]] && { cp -r scripts "$SPEC_DIR/"; echo "Copied scripts -> .specify/scripts"; } [[ -d templates ]] && { mkdir -p "$SPEC_DIR/templates"; find templates -type f -not -path "templates/commands/*" -exec cp --parents {} "$SPEC_DIR"/ \; ; echo "Copied templates -> .specify/templates"; } rewrite_paths() { sed -E \ -e 's@(/?)memory/@.specify/memory/@g' \ -e 's@(/?)scripts/@.specify/scripts/@g' \ -e 's@(/?)templates/@.specify/templates/@g' } generate_commands() { local agent=$1 ext=$2 arg_format=$3 output_dir=$4 script_variant=$5 mkdir -p "$output_dir" for template in templates/commands/*.md; do [[ -f "$template" ]] || continue local name description script_command body name=$(basename "$template" .md) # Normalize line endings file_content=$(tr -d '\r' < "$template") # Extract description and script command from YAML frontmatter description=$(printf '%s\n' "$file_content" | awk '/^description:/ {sub(/^description:[[:space:]]*/, ""); print; exit}') script_command=$(printf '%s\n' "$file_content" | awk -v sv="$script_variant" '/^[[:space:]]*'"$script_variant"':[[:space:]]*/ {sub(/^[[:space:]]*'"$script_variant"':[[:space:]]*/, ""); print; exit}') if [[ -z $script_command ]]; then echo "Warning: no script command found for $script_variant in $template" >&2 script_command="(Missing script command for $script_variant)" fi # Replace {SCRIPT} placeholder with the script command body=$(printf '%s\n' "$file_content" | sed "s|{SCRIPT}|${script_command}|g") # Remove the scripts: section from frontmatter while preserving YAML structure body=$(printf '%s\n' "$body" | awk ' /^---$/ { print; if (++dash_count == 1) in_frontmatter=1; else in_frontmatter=0; next } in_frontmatter && /^scripts:$/ { skip_scripts=1; next } in_frontmatter && /^[a-zA-Z].*:/ && skip_scripts { skip_scripts=0 } in_frontmatter && skip_scripts && /^[[:space:]]/ { next } { print } ') # Apply other substitutions body=$(printf '%s\n' "$body" | sed "s/{ARGS}/$arg_format/g" | sed "s/__AGENT__/$agent/g" | rewrite_paths) case $ext in toml) { echo "description = \"$description\""; echo; echo "prompt = \"\"\""; echo "$body"; echo "\"\"\""; } > "$output_dir/$name.$ext" ;; md) echo "$body" > "$output_dir/$name.$ext" ;; prompt.md) echo "$body" > "$output_dir/$name.$ext" ;; esac done } build_variant() { local agent=$1 script=$2 local base_dir="sdd-${agent}-package-${script}" echo "Building $agent ($script) package..." mkdir -p "$base_dir" cp -r sdd-package-base/. "$base_dir"/ # Inject variant into plan-template.md within .specify/templates if present local plan_tpl="$base_dir/.specify/templates/plan-template.md" if [[ -f "$plan_tpl" ]]; then plan_norm=$(tr -d '\r' < "$plan_tpl") variant_line=$(printf '%s\n' "$plan_norm" | grep -E ".*//; s/^[[:space:]]+//; s/[[:space:]]+$//") if [[ -n $variant_line ]]; then tmp_file=$(mktemp) sed "s|VARIANT-INJECT|${variant_line}|" "$plan_tpl" | tr -d '\r' | sed "s|__AGENT__|${agent}|g" | sed '/