From 859abd44192deb51f9b4e069a4d6bcaf06866296 Mon Sep 17 00:00:00 2001 From: "w. ian douglas" Date: Thu, 28 Aug 2025 17:01:03 -0600 Subject: [PATCH 1/5] making small updates to recipe validation workflow so it only runs when a recipe is given and only re-runs if a recipe is udpated in the PR --- .github/workflows/validate-recipe-pr.yml | 61 ++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index a26832f4bcc8..fd6b1422a9c9 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -42,22 +42,60 @@ jobs: keyring: false EOF - - name: Find and validate recipe files - id: validate + - name: Check if recipe files changed in this PR + id: recipe_changes run: | - echo "🔍 Looking for recipe files..." - RECIPE_FILES=$(find documentation/src/pages/recipes/data/recipes/ -name "*.yaml" -o -name "*.yml" 2>/dev/null || true) + set -e + echo "🔍 Checking if recipe files were modified in this PR..." + + # Get the list of changed files in this PR + CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD) + + echo "All changed files in PR:" + echo "$CHANGED_FILES" + echo "" + + # Check if any recipe files were changed + if echo "$CHANGED_FILES" | grep -q "^documentation/src/pages/recipes/data/recipes/.*\.(yaml|yml)$"; then + echo "recipe_files_changed=true" >> "$GITHUB_OUTPUT" + echo "✅ Recipe files were modified in this PR - proceeding with validation" + else + echo "recipe_files_changed=false" >> "$GITHUB_OUTPUT" + echo "â„šī¸ No recipe files were modified in this PR - skipping validation" + fi + + - name: Find changed recipe files in PR + id: find_changed_recipes + if: steps.recipe_changes.outputs.recipe_files_changed == 'true' + run: | + echo "🔍 Finding recipe files changed in this PR..." + + # Get the list of changed files in this PR + CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD) + + # Filter for recipe files only + RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then - echo "❌ No recipe files found in the correct location!" + echo "❌ No recipe files found in the PR changes!" echo "📁 Please add your recipe to: documentation/src/pages/recipes/data/recipes/" echo "validation_status=no_files" >> $GITHUB_OUTPUT exit 1 fi - echo "Found recipe files:" + echo "Found changed recipe files:" echo "$RECIPE_FILES" + # Save recipe file paths for validation step + echo "$RECIPE_FILES" > /tmp/changed_recipe_files.txt + + - name: Validate changed recipe files + id: validate + if: steps.recipe_changes.outputs.recipe_files_changed == 'true' + run: | + # Read the list of changed recipe files + RECIPE_FILES=$(cat /tmp/changed_recipe_files.txt) + ALL_VALID=true VALIDATION_OUTPUT="" @@ -133,6 +171,7 @@ jobs: fi - name: Comment validation results + if: steps.recipe_changes.outputs.recipe_files_changed == 'true' uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -188,9 +227,15 @@ jobs: - name: Set validation status if: always() - env: - VALIDATION_STATUS: ${{ steps.validate.outputs.validation_status }} run: | + # Check if recipe files were changed in this PR + if [ "${{ steps.recipe_changes.outputs.recipe_files_changed }}" = "false" ]; then + # No recipe files were modified in this PR - validation skipped + echo "â„šī¸ No recipe files in PR - validation skipped" + exit 0 + fi + + VALIDATION_STATUS="${{ steps.validate.outputs.validation_status }}" if [ "$VALIDATION_STATUS" = "valid" ]; then echo "✅ All recipes are valid" exit 0 From b7387e3efa3d49b1788d376b4e5e912f6da11062 Mon Sep 17 00:00:00 2001 From: "w. ian douglas" Date: Thu, 28 Aug 2025 17:11:52 -0600 Subject: [PATCH 2/5] updating workflows for only running on new PR files, not existing files from main branch --- .github/workflows/recipe-security-scanner.yml | 23 ++++++++++++++----- .github/workflows/validate-recipe-pr.yml | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/recipe-security-scanner.yml b/.github/workflows/recipe-security-scanner.yml index 3d6e3945d6bf..9f004ea1a17a 100644 --- a/.github/workflows/recipe-security-scanner.yml +++ b/.github/workflows/recipe-security-scanner.yml @@ -64,22 +64,33 @@ jobs: if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: sudo apt-get update && sudo apt-get install -y jq - - name: Find recipe files in PR + - name: Find changed recipe files in PR id: find_recipes if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: | set -e - echo "Looking for recipe files in PR..." + echo "Looking for changed recipe files in PR..." - # Find all .yaml/.yml files in the recipes directory - RECIPE_FILES=$(find documentation/src/pages/recipes/data/recipes/ -name "*.yaml" -o -name "*.yml" 2>/dev/null || true) + # Get the list of changed files in this PR + if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "synchronize" ]; then + # For synchronize events, check files changed since the previous commit + echo "📝 Synchronize event - checking files changed since previous commit" + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) + else + # For opened/reopened, check all files in the PR + echo "📝 PR opened/reopened - checking all files in PR" + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD) + fi + + # Filter for recipe files only that were changed + RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then - echo "No recipe files found in PR" + echo "No changed recipe files found in PR" echo "has_recipes=false" >> "$GITHUB_OUTPUT" echo "recipe_count=0" >> "$GITHUB_OUTPUT" else - echo "Found recipe files:" + echo "Found changed recipe files:" echo "$RECIPE_FILES" RECIPE_COUNT=$(echo "$RECIPE_FILES" | wc -l) echo "has_recipes=true" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index fd6b1422a9c9..47265a94ef63 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -22,6 +22,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 - name: Set up Node.js uses: actions/setup-node@v3 From 44e5ddeb21f02e4faf45ae8fa3f7b7526997904f Mon Sep 17 00:00:00 2001 From: "w. ian douglas" Date: Thu, 28 Aug 2025 17:23:23 -0600 Subject: [PATCH 3/5] updating the workflows again and adding a test recipe --- .github/workflows/validate-recipe-pr.yml | 42 ++++++++---- .../recipes/data/recipes/lint-my-code.yaml | 67 +++++++++++++++++++ 2 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 documentation/src/pages/recipes/data/recipes/lint-my-code.yaml diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index 47265a94ef63..3334f3d8f619 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -43,43 +43,59 @@ jobs: keyring: false EOF - - name: Check if recipe files changed in this PR + - name: Check if recipe files changed in this push id: recipe_changes run: | set -e - echo "🔍 Checking if recipe files were modified in this PR..." + echo "🔍 Checking if recipe files were modified in this push..." - # Get the list of changed files in this PR - CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD) + # Get the list of changed files in this specific push + if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "synchronize" ]; then + # For synchronize events, check files changed since the previous commit + echo "📝 Synchronize event - checking files changed since previous commit" + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) + else + # For opened/reopened, check all files in the PR + echo "📝 PR opened/reopened - checking all files in PR" + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD) + fi - echo "All changed files in PR:" + echo "Changed files in this push:" echo "$CHANGED_FILES" echo "" # Check if any recipe files were changed - if echo "$CHANGED_FILES" | grep -q "^documentation/src/pages/recipes/data/recipes/.*\.(yaml|yml)$"; then + if echo "$CHANGED_FILES" | grep -q "^documentation/src/pages/recipes/data/recipes/"; then echo "recipe_files_changed=true" >> "$GITHUB_OUTPUT" - echo "✅ Recipe files were modified in this PR - proceeding with validation" + echo "✅ Recipe files were modified in this push - proceeding with validation" else echo "recipe_files_changed=false" >> "$GITHUB_OUTPUT" - echo "â„šī¸ No recipe files were modified in this PR - skipping validation" + echo "â„šī¸ No recipe files were modified in this push - skipping validation" fi - name: Find changed recipe files in PR id: find_changed_recipes if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: | - echo "🔍 Finding recipe files changed in this PR..." + set -e + echo "Looking for changed recipe files in PR..." # Get the list of changed files in this PR - CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD) + if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "synchronize" ]; then + # For synchronize events, check files changed since the previous commit + echo "📝 Synchronize event - checking files changed since previous commit" + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) + else + # For opened/reopened, check all files in the PR + echo "📝 PR opened/reopened - checking all files in PR" + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD) + fi - # Filter for recipe files only + # Filter for recipe files only that were changed RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then - echo "❌ No recipe files found in the PR changes!" - echo "📁 Please add your recipe to: documentation/src/pages/recipes/data/recipes/" + echo "No changed recipe files found in PR" echo "validation_status=no_files" >> $GITHUB_OUTPUT exit 1 fi diff --git a/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml b/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml new file mode 100644 index 000000000000..efeffd9b95a3 --- /dev/null +++ b/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml @@ -0,0 +1,67 @@ +version: 1.0.0 +title: Lint My Code +author: + contact: iandouglas +description: Analyzes code files for syntax and layout issues using available linting tools +instructions: You are a code quality expert that helps identify syntax and layout issues in code files +activities: + - Detect file type and programming language + - Check for available linting tools in the project + - Run appropriate linters for syntax and layout checking + - Provide recommendations if no linters are found +parameters: + - key: file_path + input_type: string + requirement: required + description: Path to the file you want to lint +extensions: + - type: builtin + name: developer + display_name: Developer + timeout: 300 + bundled: true +prompt: | + I need you to lint the file at {{ file_path }} for syntax and layout issues only. Do not modify the file - just report any problems you find. + + Here's what to do step by step: + + 1. **Verify the file exists and determine its type:** + - Check if {{ file_path }} exists + - Examine the file extension and content to determine the programming language/file type + - Focus on: Python (.py), JavaScript (.js, .jsx, .ts, .tsx), YAML (.yaml, .yml), HTML (.html, .htm), and CSS (.css) + + 2. **Check for available linting tools in the project:** + - Look for common linting tools and configurations in the current project: + - Python: flake8, pylint, black, ruff, pycodestyle, autopep8 + - JavaScript/TypeScript: eslint, prettier, jshint, tslint + - YAML: yamllint, yq + - HTML: htmlhint, tidy + - CSS: stylelint, csslint + - Check for configuration files like .eslintrc, .flake8, pyproject.toml, .yamllint, etc. + - Look in package.json, requirements.txt, or other dependency files + + 3. **Run appropriate linting tools:** + - If linting tools are found, run them only on the specified file + - Use syntax-only or layout-only flags where available (e.g., `flake8 --select=E,W` for Python) + - Capture and report the output clearly + + 4. **If no linters are found, provide recommendations:** + - For Python files: Suggest flake8, black, or ruff + - For JavaScript/TypeScript: Suggest ESLint and Prettier + - For YAML: Suggest yamllint + - For HTML: Suggest htmlhint or W3C validator + - For CSS: Suggest stylelint + - Provide installation commands and basic usage examples + + 5. **Report results:** + - Clearly summarize any syntax or layout issues found + - If no issues are found, confirm the file appears to be clean + - If linting tools weren't available, explain what you checked manually and provide tool recommendations + + Remember: + - Only check for syntax and layout issues, don't suggest code changes + - Do not change the file on behalf of the user + - Use tools that are already available in the project when possible + - Be helpful by suggesting appropriate tools if none are found + - Focus on the file types specified: Python, JavaScript, YAML, HTML, and CSS + \ No newline at end of file From ceea60f1486d74ef22e9eae320f5395e276ea751 Mon Sep 17 00:00:00 2001 From: "w. ian douglas" Date: Thu, 28 Aug 2025 17:27:41 -0600 Subject: [PATCH 4/5] now only catching new and updated recipes --- .github/workflows/recipe-security-scanner.yml | 14 +++++++------- .github/workflows/validate-recipe-pr.yml | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/recipe-security-scanner.yml b/.github/workflows/recipe-security-scanner.yml index 9f004ea1a17a..7531ba41723e 100644 --- a/.github/workflows/recipe-security-scanner.yml +++ b/.github/workflows/recipe-security-scanner.yml @@ -64,25 +64,25 @@ jobs: if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: sudo apt-get update && sudo apt-get install -y jq - - name: Find changed recipe files in PR + - name: Find recipe files in PR (new or modified) id: find_recipes if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: | set -e - echo "Looking for changed recipe files in PR..." + echo "Looking for recipe files in PR (new or modified)..." - # Get the list of changed files in this PR + # Get the list of changed/new files in this PR if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "synchronize" ]; then # For synchronize events, check files changed since the previous commit - echo "📝 Synchronize event - checking files changed since previous commit" + echo "📝 Synchronize event - checking files changed/added since previous commit" CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR - echo "📝 PR opened/reopened - checking all files in PR" + # For opened/reopened, check all files in the PR (new and modified) + echo "📝 PR opened/reopened - checking all new/modified files in PR" CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD) fi - # Filter for recipe files only that were changed + # Filter for recipe files only that were changed or added RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index 3334f3d8f619..c360472c9c2b 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -73,25 +73,25 @@ jobs: echo "â„šī¸ No recipe files were modified in this push - skipping validation" fi - - name: Find changed recipe files in PR + - name: Find recipe files in PR (new or modified) id: find_changed_recipes if: steps.recipe_changes.outputs.recipe_files_changed == 'true' run: | set -e - echo "Looking for changed recipe files in PR..." + echo "Looking for recipe files in PR (new or modified)..." - # Get the list of changed files in this PR + # Get the list of changed/new files in this PR if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "synchronize" ]; then # For synchronize events, check files changed since the previous commit - echo "📝 Synchronize event - checking files changed since previous commit" + echo "📝 Synchronize event - checking files changed/added since previous commit" CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR - echo "📝 PR opened/reopened - checking all files in PR" + # For opened/reopened, check all files in the PR (new and modified) + echo "📝 PR opened/reopened - checking all new/modified files in PR" CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD) fi - # Filter for recipe files only that were changed + # Filter for recipe files only that were changed or added RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then From f9e05810b16adf2374a3f2fb5dcb5377b3c0aaf8 Mon Sep 17 00:00:00 2001 From: "w. ian douglas" Date: Thu, 28 Aug 2025 17:34:58 -0600 Subject: [PATCH 5/5] trying a string formating change and removing test recipe for now --- .github/workflows/validate-recipe-pr.yml | 9 +-- .../recipes/data/recipes/lint-my-code.yaml | 67 ------------------- 2 files changed, 5 insertions(+), 71 deletions(-) delete mode 100644 documentation/src/pages/recipes/data/recipes/lint-my-code.yaml diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index c360472c9c2b..a70906ade155 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -118,15 +118,16 @@ jobs: # First pass: Basic YAML validation while IFS= read -r RECIPE_FILE; do + BASE_RECIPE_FILENAME=$(basename "$RECIPE_FILE" if [ -f "$RECIPE_FILE" ]; then echo "🔍 Validating: $RECIPE_FILE" if OUTPUT=$(goose recipe validate "$RECIPE_FILE" 2>&1); then - echo "✅ Valid: $RECIPE_FILE" - VALIDATION_OUTPUT="${VALIDATION_OUTPUT}✅ $RECIPE_FILE: VALID\n" + echo "✅ Valid: $BASE_RECIPE_FILENAME" + VALIDATION_OUTPUT="${VALIDATION_OUTPUT}✅ $BASE_RECIPE_FILENAME: VALID\n" else - echo "❌ Invalid: $RECIPE_FILE" + echo "❌ Invalid: $BASE_RECIPE_FILENAME" echo "$OUTPUT" - VALIDATION_OUTPUT="${VALIDATION_OUTPUT}❌ $RECIPE_FILE: INVALID\n\`\`\`\n$OUTPUT\n\`\`\`\n" + VALIDATION_OUTPUT="${VALIDATION_OUTPUT}❌ $BASE_RECIPE_FILENAME: INVALID\n\`\`\`\n$OUTPUT\n\`\`\`\n" ALL_VALID=false fi fi diff --git a/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml b/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml deleted file mode 100644 index efeffd9b95a3..000000000000 --- a/documentation/src/pages/recipes/data/recipes/lint-my-code.yaml +++ /dev/null @@ -1,67 +0,0 @@ -version: 1.0.0 -title: Lint My Code -author: - contact: iandouglas -description: Analyzes code files for syntax and layout issues using available linting tools -instructions: You are a code quality expert that helps identify syntax and layout issues in code files -activities: - - Detect file type and programming language - - Check for available linting tools in the project - - Run appropriate linters for syntax and layout checking - - Provide recommendations if no linters are found -parameters: - - key: file_path - input_type: string - requirement: required - description: Path to the file you want to lint -extensions: - - type: builtin - name: developer - display_name: Developer - timeout: 300 - bundled: true -prompt: | - I need you to lint the file at {{ file_path }} for syntax and layout issues only. Do not modify the file - just report any problems you find. - - Here's what to do step by step: - - 1. **Verify the file exists and determine its type:** - - Check if {{ file_path }} exists - - Examine the file extension and content to determine the programming language/file type - - Focus on: Python (.py), JavaScript (.js, .jsx, .ts, .tsx), YAML (.yaml, .yml), HTML (.html, .htm), and CSS (.css) - - 2. **Check for available linting tools in the project:** - - Look for common linting tools and configurations in the current project: - - Python: flake8, pylint, black, ruff, pycodestyle, autopep8 - - JavaScript/TypeScript: eslint, prettier, jshint, tslint - - YAML: yamllint, yq - - HTML: htmlhint, tidy - - CSS: stylelint, csslint - - Check for configuration files like .eslintrc, .flake8, pyproject.toml, .yamllint, etc. - - Look in package.json, requirements.txt, or other dependency files - - 3. **Run appropriate linting tools:** - - If linting tools are found, run them only on the specified file - - Use syntax-only or layout-only flags where available (e.g., `flake8 --select=E,W` for Python) - - Capture and report the output clearly - - 4. **If no linters are found, provide recommendations:** - - For Python files: Suggest flake8, black, or ruff - - For JavaScript/TypeScript: Suggest ESLint and Prettier - - For YAML: Suggest yamllint - - For HTML: Suggest htmlhint or W3C validator - - For CSS: Suggest stylelint - - Provide installation commands and basic usage examples - - 5. **Report results:** - - Clearly summarize any syntax or layout issues found - - If no issues are found, confirm the file appears to be clean - - If linting tools weren't available, explain what you checked manually and provide tool recommendations - - Remember: - - Only check for syntax and layout issues, don't suggest code changes - - Do not change the file on behalf of the user - - Use tools that are already available in the project when possible - - Be helpful by suggesting appropriate tools if none are found - - Focus on the file types specified: Python, JavaScript, YAML, HTML, and CSS - \ No newline at end of file