-
Notifications
You must be signed in to change notification settings - Fork 839
CLI: Add gen-test-instructions command
#45491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
manzoorwanijk
wants to merge
7
commits into
trunk
Choose a base branch
from
add/cli/gen-test-instructions
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
449831a
CLI: Add gen-test-instructions command
manzoorwanijk 20e8921
Move the tool from CLI to /tools
manzoorwanijk 3234481
Address Copilot feedback
manzoorwanijk 96eb7ad
Address PR feedback
manzoorwanijk f32d982
Merge branch 'trunk' into add/cli/gen-test-instructions
manzoorwanijk 1a6de0c
Update Claude model version
manzoorwanijk 1297299
Update instructions for headings
manzoorwanijk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| ## | ||
| ## 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 | ||
manzoorwanijk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.