Skip to content

Commit 44a3263

Browse files
committed
Move the tool from CLI to /tools
1 parent 449831a commit 44a3263

File tree

3 files changed

+445
-234
lines changed

3 files changed

+445
-234
lines changed

tools/cli/cliRouter.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as dependenciesCommand from './commands/dependencies.js';
88
import { dockerDefine } from './commands/docker.js';
99
import { docsDefine } from './commands/docs.js';
1010
import { draftDefine } from './commands/draft.js';
11-
import { genTestInstructionsDefine } from './commands/gen-test-instructions.js';
1211
import { generateDefine } from './commands/generate.js';
1312
import * as installCommand from './commands/install.js';
1413
import * as noopCommand from './commands/noop.js';
@@ -50,7 +49,6 @@ export async function cli() {
5049
argv = releaseDefine( argv );
5150
argv = rsyncDefine( argv );
5251
argv.command( testCommand );
53-
argv = genTestInstructionsDefine( argv );
5452
argv = watchDefine( argv );
5553

5654
// This adds usage information on failure and demands that a subcommand must be passed.

tools/gen-test-instructions.sh

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
--verbose Enable verbose output
46+
-h, --help Show this help message
47+
48+
EXAMPLES:
49+
# Generate since last stable release (default)
50+
tools/gen-test-instructions.sh
51+
52+
# Generate since specific version
53+
tools/gen-test-instructions.sh --version 15.1
54+
55+
# Specify output file
56+
tools/gen-test-instructions.sh --output test-guide.md
57+
58+
# Skip AI consolidation
59+
tools/gen-test-instructions.sh --skip-ai
60+
61+
# With API key
62+
tools/gen-test-instructions.sh --api-key sk-ant-...
63+
64+
REQUIREMENTS:
65+
- Node.js (available in monorepo)
66+
- GitHub CLI (gh) - must be installed and authenticated
67+
- Anthropic API Key (optional, for AI consolidation)
68+
69+
For more information, see: tools/gen-test-instructions-README.md
70+
EOH
71+
exit 1
72+
}
73+
74+
##
75+
## Parse command line arguments
76+
##
77+
while [[ $# -gt 0 ]]; do
78+
case "$1" in
79+
-c|--changelog)
80+
CHANGELOG_PATH="$2"
81+
shift 2
82+
;;
83+
-o|--output)
84+
OUTPUT_FILE="$2"
85+
shift 2
86+
;;
87+
-v|--version)
88+
SINCE_VERSION="$2"
89+
shift 2
90+
;;
91+
-d|--since-date)
92+
SINCE_DATE="$2"
93+
shift 2
94+
;;
95+
-k|--api-key)
96+
API_KEY="$2"
97+
shift 2
98+
;;
99+
-s|--skip-ai)
100+
SKIP_AI=true
101+
shift
102+
;;
103+
--verbose)
104+
VERBOSE=true
105+
shift
106+
;;
107+
-h|--help)
108+
usage
109+
;;
110+
*)
111+
error "Unknown option: $1"
112+
usage
113+
;;
114+
esac
115+
done
116+
117+
# Main execution starts here
118+
info "🧪 Generating Testing Instructions..."
119+
echo ""
120+
121+
# Check prerequisites
122+
if ! command -v gh &> /dev/null; then
123+
error "GitHub CLI (gh) is not installed. Please install it first:"
124+
echo " macOS: brew install gh"
125+
echo " See: https://github.com/cli/cli/blob/trunk/docs/install_linux.md for other platforms"
126+
exit 1
127+
fi
128+
129+
# Check if gh is authenticated
130+
if ! gh auth status &> /dev/null; then
131+
error "GitHub CLI is not authenticated. Please run: gh auth login"
132+
exit 1
133+
fi
134+
135+
# Check if Node.js is available
136+
if ! command -v node &> /dev/null; then
137+
error "Node.js is not installed"
138+
exit 1
139+
fi
140+
141+
# Resolve changelog path
142+
if [[ ! "$CHANGELOG_PATH" = /* ]]; then
143+
CHANGELOG_PATH="$BASE/$CHANGELOG_PATH"
144+
fi
145+
146+
# Check if changelog exists
147+
if [[ ! -f "$CHANGELOG_PATH" ]]; then
148+
error "Changelog file not found at: $CHANGELOG_PATH"
149+
exit 1
150+
fi
151+
152+
# Set default output file if not specified
153+
if [[ -z "$OUTPUT_FILE" ]]; then
154+
if [[ -n "$SINCE_VERSION" ]]; then
155+
OUTPUT_FILE="test-instructions-${SINCE_VERSION}.md"
156+
else
157+
OUTPUT_FILE="test-instructions-latest.md"
158+
fi
159+
160+
# Prompt for confirmation
161+
info "Output file will be: $OUTPUT_FILE"
162+
read -p "Press Enter to continue or provide a name, or press Ctrl+C to cancel:"
163+
fi
164+
165+
# Build arguments for the Node.js script
166+
NODE_ARGS=()
167+
NODE_ARGS+=("--changelog" "$CHANGELOG_PATH")
168+
NODE_ARGS+=("--output" "$OUTPUT_FILE")
169+
170+
if [[ -n "$SINCE_VERSION" ]]; then
171+
NODE_ARGS+=("--version" "$SINCE_VERSION")
172+
fi
173+
174+
if [[ -n "$SINCE_DATE" ]]; then
175+
NODE_ARGS+=("--since-date" "$SINCE_DATE")
176+
fi
177+
178+
if [[ -n "$API_KEY" ]]; then
179+
NODE_ARGS+=("--api-key" "$API_KEY")
180+
fi
181+
182+
if [[ "$SKIP_AI" = true ]]; then
183+
NODE_ARGS+=("--skip-ai")
184+
fi
185+
186+
if [[ "$VERBOSE" = true ]]; then
187+
NODE_ARGS+=("--verbose")
188+
fi
189+
190+
# Run the Node.js script
191+
NODE_SCRIPT="$BASE/tools/js-tools/gen-test-instructions.mjs"
192+
193+
if [[ ! -f "$NODE_SCRIPT" ]]; then
194+
error "Node.js script not found at: $NODE_SCRIPT"
195+
exit 1
196+
fi
197+
198+
# Execute the Node.js script
199+
if [[ "$VERBOSE" = true ]]; then
200+
info "Running: node $NODE_SCRIPT ${NODE_ARGS[*]}"
201+
fi
202+
203+
node "$NODE_SCRIPT" "${NODE_ARGS[@]}"
204+
205+
# Check if the script succeeded
206+
if [[ $? -eq 0 ]]; then
207+
success "✅ Test guide generated successfully!"
208+
echo ""
209+
info "📄 Output file: $(cyan "$OUTPUT_FILE")"
210+
echo ""
211+
echo "You can now review and edit the test instructions before sharing."
212+
else
213+
error "Failed to generate test instructions"
214+
exit 1
215+
fi

0 commit comments

Comments
 (0)