Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 223 additions & 0 deletions tools/gen-test-instructions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused as to the purpose of this file; it's basically a 200+ line wrapper of the script at tools/js-tools/gen-test-instructions.mjs, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd just chop this file altogether. With specialized tooling I'm fine even skipping most of the checks, but otherwise the checks are probably better directly in the .mjs.


##
## Generate test instructions from changelog for Jetpack releases.
##
## This bash script serves as a user-friendly wrapper around the Node.js
## implementation at tools/js-tools/gen-test-instructions.mjs. It provides:
## - Prerequisite checking (gh CLI, Node.js, authentication)
## - Path resolution and validation
## - User-friendly prompts and error messages
## - Integration with standard Jetpack tooling (chalk-lite, etc.)
##
## The actual logic for parsing, fetching, and generating test instructions
## is in the JavaScript module, while this script handles the CLI interface
## and environment setup.
##

set -eo pipefail

# Get the base directory
BASE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)

# Source common includes
. "$BASE/tools/includes/check-osx-bash-version.sh"
. "$BASE/tools/includes/chalk-lite.sh"

# Default values
CHANGELOG_PATH="projects/plugins/jetpack/CHANGELOG.md"
OUTPUT_FILE=""
SINCE_VERSION=""
SINCE_DATE=""
SKIP_AI=false
API_KEY="${ANTHROPIC_API_KEY:-}"
VERBOSE=false

##
## Print usage information and exit
##
function usage {
cat <<-'EOH'
usage: gen-test-instructions.sh [options]

Generate consolidated test instructions from Jetpack changelog entries.

OPTIONS:
-c, --changelog <path> Path to CHANGELOG.md file (default: projects/plugins/jetpack/CHANGELOG.md)
-o, --output <file> Output file path for test instructions
-v, --version <version> Start from this version (e.g., 15.1). Defaults to last stable release
-d, --since-date <date> Include entries since this date (YYYY-MM-DD)
-k, --api-key <key> Anthropic API key for AI consolidation (or set ANTHROPIC_API_KEY env var)
-s, --skip-ai Skip AI consolidation and output raw format
-h, --help Show this help message

EXAMPLES:
# Generate since last stable release (default)
tools/gen-test-instructions.sh

# Generate since specific version
tools/gen-test-instructions.sh --version 15.1

# Specify output file
tools/gen-test-instructions.sh --output test-guide.md

# Skip AI consolidation
tools/gen-test-instructions.sh --skip-ai

# With API key
tools/gen-test-instructions.sh --api-key sk-ant-...

REQUIREMENTS:
- Node.js (available in monorepo)
- GitHub CLI (gh) - must be installed and authenticated
- Anthropic API Key (optional, for AI consolidation)
EOH
exit 1
}

##
## Parse command line arguments
##
while [[ $# -gt 0 ]]; do
case "$1" in
-c|--changelog)
CHANGELOG_PATH="$2"
shift 2
;;
-o|--output)
OUTPUT_FILE="$2"
shift 2
;;
-v|--version)
SINCE_VERSION="$2"
shift 2
;;
-d|--since-date)
SINCE_DATE="$2"
shift 2
;;
-k|--api-key)
API_KEY="$2"
shift 2
;;
-s|--skip-ai)
SKIP_AI=true
shift
;;
--verbose)
VERBOSE=true
shift
;;
-h|--help)
usage
;;
*)
error "Unknown option: $1"
usage
;;
esac
done

# Main execution starts here
info "🧪 Generating Testing Instructions..."
echo ""

# Check prerequisites
if ! command -v gh &> /dev/null; then
error "GitHub CLI (gh) is not installed. Please install it first:"
echo " macOS: brew install gh"
echo " See: https://github.com/cli/cli/blob/trunk/docs/install_linux.md for other platforms"
exit 1
fi

# Check if gh is authenticated
if ! gh auth status &> /dev/null; then
error "GitHub CLI is not authenticated. Please run: gh auth login"
exit 1
fi

# Check if Node.js is available
if ! command -v node &> /dev/null; then
error "Node.js is not installed"
exit 1
fi

# Resolve changelog path
if [[ ! "$CHANGELOG_PATH" = /* ]]; then
CHANGELOG_PATH="$BASE/$CHANGELOG_PATH"
fi

# Check if changelog exists
if [[ ! -f "$CHANGELOG_PATH" ]]; then
error "Changelog file not found at: $CHANGELOG_PATH"
exit 1
fi

# Set default output file if not specified
if [[ -z "$OUTPUT_FILE" ]]; then
if [[ -n "$SINCE_VERSION" ]]; then
OUTPUT_FILE="test-instructions-${SINCE_VERSION}.md"
else
OUTPUT_FILE="test-instructions-latest.md"
fi

# Prompt for confirmation
info "Output file will be: $OUTPUT_FILE"
read -p "Press Enter to continue, provide a different name, or press Ctrl+C to cancel: " USER_INPUT
if [[ -n "$USER_INPUT" ]]; then
OUTPUT_FILE="$USER_INPUT"
info "Output file updated to: $OUTPUT_FILE"
fi
fi

# Build arguments for the Node.js script
NODE_ARGS=()
NODE_ARGS+=("--changelog" "$CHANGELOG_PATH")
NODE_ARGS+=("--output" "$OUTPUT_FILE")

if [[ -n "$SINCE_VERSION" ]]; then
NODE_ARGS+=("--version" "$SINCE_VERSION")
fi

if [[ -n "$SINCE_DATE" ]]; then
NODE_ARGS+=("--since-date" "$SINCE_DATE")
fi

if [[ -n "$API_KEY" ]]; then
NODE_ARGS+=("--api-key" "$API_KEY")
fi

if [[ "$SKIP_AI" = true ]]; then
NODE_ARGS+=("--skip-ai")
fi

if [[ "$VERBOSE" = true ]]; then
NODE_ARGS+=("--verbose")
fi

# Run the Node.js script
NODE_SCRIPT="$BASE/tools/js-tools/gen-test-instructions.mjs"

if [[ ! -f "$NODE_SCRIPT" ]]; then
error "Node.js script not found at: $NODE_SCRIPT"
exit 1
fi

# Execute the Node.js script
if [[ "$VERBOSE" = true ]]; then
info "Running: node $NODE_SCRIPT ${NODE_ARGS[*]}"
fi

node "$NODE_SCRIPT" "${NODE_ARGS[@]}"

# Check if the script succeeded
if [[ $? -eq 0 ]]; then
success "✅ Test guide generated successfully!"
echo ""
info "📄 Output file: $(cyan "$OUTPUT_FILE")"
echo ""
echo "You can now review and edit the test instructions before sharing."
else
error "Failed to generate test instructions"
exit 1
fi
Loading
Loading