|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +## |
| 4 | +## Generate test instructions from changelog for Jetpack releases. |
| 5 | +## |
| 6 | +## This script automates the creation of consolidated test instructions |
| 7 | +## by parsing the CHANGELOG.md, fetching PR details from GitHub, and |
| 8 | +## optionally using AI to consolidate the instructions. |
| 9 | +## |
| 10 | + |
| 11 | +set -eo pipefail |
| 12 | + |
| 13 | +# Get the base directory |
| 14 | +BASE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) |
| 15 | + |
| 16 | +# Source common includes |
| 17 | +. "$BASE/tools/includes/check-osx-bash-version.sh" |
| 18 | +. "$BASE/tools/includes/chalk-lite.sh" |
| 19 | + |
| 20 | +# Default values |
| 21 | +CHANGELOG_PATH="projects/plugins/jetpack/CHANGELOG.md" |
| 22 | +OUTPUT_FILE="" |
| 23 | +SINCE_VERSION="" |
| 24 | +SINCE_DATE="" |
| 25 | +SKIP_AI=false |
| 26 | +API_KEY="${ANTHROPIC_API_KEY:-}" |
| 27 | +VERBOSE=false |
| 28 | + |
| 29 | +## |
| 30 | +## Print usage information and exit |
| 31 | +## |
| 32 | +function usage { |
| 33 | + cat <<-'EOH' |
| 34 | + usage: gen-test-instructions.sh [options] |
| 35 | +
|
| 36 | + Generate consolidated test instructions from Jetpack changelog entries. |
| 37 | +
|
| 38 | + OPTIONS: |
| 39 | + -c, --changelog <path> Path to CHANGELOG.md file (default: projects/plugins/jetpack/CHANGELOG.md) |
| 40 | + -o, --output <file> Output file path for test instructions |
| 41 | + -v, --version <version> Start from this version (e.g., 15.1). Defaults to last stable release |
| 42 | + -d, --since-date <date> Include entries since this date (YYYY-MM-DD) |
| 43 | + -k, --api-key <key> Anthropic API key for AI consolidation (or set ANTHROPIC_API_KEY env var) |
| 44 | + -s, --skip-ai Skip AI consolidation and output raw format |
| 45 | + -h, --help Show this help message |
| 46 | +
|
| 47 | + EXAMPLES: |
| 48 | + # Generate since last stable release (default) |
| 49 | + tools/gen-test-instructions.sh |
| 50 | +
|
| 51 | + # Generate since specific version |
| 52 | + tools/gen-test-instructions.sh --version 15.1 |
| 53 | +
|
| 54 | + # Specify output file |
| 55 | + tools/gen-test-instructions.sh --output test-guide.md |
| 56 | +
|
| 57 | + # Skip AI consolidation |
| 58 | + tools/gen-test-instructions.sh --skip-ai |
| 59 | +
|
| 60 | + # With API key |
| 61 | + tools/gen-test-instructions.sh --api-key sk-ant-... |
| 62 | +
|
| 63 | + REQUIREMENTS: |
| 64 | + - Node.js (available in monorepo) |
| 65 | + - GitHub CLI (gh) - must be installed and authenticated |
| 66 | + - Anthropic API Key (optional, for AI consolidation) |
| 67 | + EOH |
| 68 | + exit 1 |
| 69 | +} |
| 70 | + |
| 71 | +## |
| 72 | +## Parse command line arguments |
| 73 | +## |
| 74 | +while [[ $# -gt 0 ]]; do |
| 75 | + case "$1" in |
| 76 | + -c|--changelog) |
| 77 | + CHANGELOG_PATH="$2" |
| 78 | + shift 2 |
| 79 | + ;; |
| 80 | + -o|--output) |
| 81 | + OUTPUT_FILE="$2" |
| 82 | + shift 2 |
| 83 | + ;; |
| 84 | + -v|--version) |
| 85 | + SINCE_VERSION="$2" |
| 86 | + shift 2 |
| 87 | + ;; |
| 88 | + -d|--since-date) |
| 89 | + SINCE_DATE="$2" |
| 90 | + shift 2 |
| 91 | + ;; |
| 92 | + -k|--api-key) |
| 93 | + API_KEY="$2" |
| 94 | + shift 2 |
| 95 | + ;; |
| 96 | + -s|--skip-ai) |
| 97 | + SKIP_AI=true |
| 98 | + shift |
| 99 | + ;; |
| 100 | + --verbose) |
| 101 | + VERBOSE=true |
| 102 | + shift |
| 103 | + ;; |
| 104 | + -h|--help) |
| 105 | + usage |
| 106 | + ;; |
| 107 | + *) |
| 108 | + error "Unknown option: $1" |
| 109 | + usage |
| 110 | + ;; |
| 111 | + esac |
| 112 | +done |
| 113 | + |
| 114 | +# Main execution starts here |
| 115 | +info "🧪 Generating Testing Instructions..." |
| 116 | +echo "" |
| 117 | + |
| 118 | +# Check prerequisites |
| 119 | +if ! command -v gh &> /dev/null; then |
| 120 | + error "GitHub CLI (gh) is not installed. Please install it first:" |
| 121 | + echo " macOS: brew install gh" |
| 122 | + echo " See: https://github.com/cli/cli/blob/trunk/docs/install_linux.md for other platforms" |
| 123 | + exit 1 |
| 124 | +fi |
| 125 | + |
| 126 | +# Check if gh is authenticated |
| 127 | +if ! gh auth status &> /dev/null; then |
| 128 | + error "GitHub CLI is not authenticated. Please run: gh auth login" |
| 129 | + exit 1 |
| 130 | +fi |
| 131 | + |
| 132 | +# Check if Node.js is available |
| 133 | +if ! command -v node &> /dev/null; then |
| 134 | + error "Node.js is not installed" |
| 135 | + exit 1 |
| 136 | +fi |
| 137 | + |
| 138 | +# Resolve changelog path |
| 139 | +if [[ ! "$CHANGELOG_PATH" = /* ]]; then |
| 140 | + CHANGELOG_PATH="$BASE/$CHANGELOG_PATH" |
| 141 | +fi |
| 142 | + |
| 143 | +# Check if changelog exists |
| 144 | +if [[ ! -f "$CHANGELOG_PATH" ]]; then |
| 145 | + error "Changelog file not found at: $CHANGELOG_PATH" |
| 146 | + exit 1 |
| 147 | +fi |
| 148 | + |
| 149 | +# Set default output file if not specified |
| 150 | +if [[ -z "$OUTPUT_FILE" ]]; then |
| 151 | + if [[ -n "$SINCE_VERSION" ]]; then |
| 152 | + OUTPUT_FILE="test-instructions-${SINCE_VERSION}.md" |
| 153 | + else |
| 154 | + OUTPUT_FILE="test-instructions-latest.md" |
| 155 | + fi |
| 156 | + |
| 157 | + # Prompt for confirmation |
| 158 | + info "Output file will be: $OUTPUT_FILE" |
| 159 | + read -p "Press Enter to continue or provide a name, or press Ctrl+C to cancel:" |
| 160 | +fi |
| 161 | + |
| 162 | +# Build arguments for the Node.js script |
| 163 | +NODE_ARGS=() |
| 164 | +NODE_ARGS+=("--changelog" "$CHANGELOG_PATH") |
| 165 | +NODE_ARGS+=("--output" "$OUTPUT_FILE") |
| 166 | + |
| 167 | +if [[ -n "$SINCE_VERSION" ]]; then |
| 168 | + NODE_ARGS+=("--version" "$SINCE_VERSION") |
| 169 | +fi |
| 170 | + |
| 171 | +if [[ -n "$SINCE_DATE" ]]; then |
| 172 | + NODE_ARGS+=("--since-date" "$SINCE_DATE") |
| 173 | +fi |
| 174 | + |
| 175 | +if [[ -n "$API_KEY" ]]; then |
| 176 | + NODE_ARGS+=("--api-key" "$API_KEY") |
| 177 | +fi |
| 178 | + |
| 179 | +if [[ "$SKIP_AI" = true ]]; then |
| 180 | + NODE_ARGS+=("--skip-ai") |
| 181 | +fi |
| 182 | + |
| 183 | +if [[ "$VERBOSE" = true ]]; then |
| 184 | + NODE_ARGS+=("--verbose") |
| 185 | +fi |
| 186 | + |
| 187 | +# Run the Node.js script |
| 188 | +NODE_SCRIPT="$BASE/tools/js-tools/gen-test-instructions.mjs" |
| 189 | + |
| 190 | +if [[ ! -f "$NODE_SCRIPT" ]]; then |
| 191 | + error "Node.js script not found at: $NODE_SCRIPT" |
| 192 | + exit 1 |
| 193 | +fi |
| 194 | + |
| 195 | +# Execute the Node.js script |
| 196 | +if [[ "$VERBOSE" = true ]]; then |
| 197 | + info "Running: node $NODE_SCRIPT ${NODE_ARGS[*]}" |
| 198 | +fi |
| 199 | + |
| 200 | +node "$NODE_SCRIPT" "${NODE_ARGS[@]}" |
| 201 | + |
| 202 | +# Check if the script succeeded |
| 203 | +if [[ $? -eq 0 ]]; then |
| 204 | + success "✅ Test guide generated successfully!" |
| 205 | + echo "" |
| 206 | + info "📄 Output file: $(cyan "$OUTPUT_FILE")" |
| 207 | + echo "" |
| 208 | + echo "You can now review and edit the test instructions before sharing." |
| 209 | +else |
| 210 | + error "Failed to generate test instructions" |
| 211 | + exit 1 |
| 212 | +fi |
0 commit comments