Skip to content

Conversation

DerekRoberts
Copy link
Member

@DerekRoberts DerekRoberts commented Sep 12, 2025

Summary

This PR adds a new triggered output to the action and enhances error handling with better debugging information.

🚀 New Features

Triggered Output

  • New Output: Added triggered output that exposes steps.diff.outputs.triggered
  • Use Case: Allows downstream actions to conditionally run based on whether this action was triggered
  • Example:
- uses: ./
  id: test-action
- if: steps.test-action.outputs.triggered == 'true'
  run: echo 'Action was triggered!'

Enhanced Error Handling

  • Better Command Failure Messages: Added comprehensive error handling for test command failures
  • Debug Information: Shows Node/NPM versions, working directory, and available scripts
  • Troubleshooting Steps: Provides common solutions for test failures
  • Multi-line Command Support: Fixed handling of multi-line commands in bash

🛠️ Input Validation

Pattern Validation

Added regex pattern validation for:

  • node_version: ^[0-9]+(\.[0-9]+)*$ (e.g., '18', '20', '22')
  • cache: ^(npm|yarn|pnpm)$ (package manager validation)
  • dir: ^[a-zA-Z0-9._/-]+$ (directory path validation)
  • sonar_token: ^[a-zA-Z0-9]{20,}$ (minimum 20 characters)
  • repository: ^[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+$ (owner/repo format)
  • diff_branch: ^[a-zA-Z0-9._/-]+$ (branch name validation)

🧪 Testing

Trigger Behavior Verification

  • Backend Job: Verifies it correctly doesn't trigger (no backend/ changes)
  • Frontend-merge Job: Verifies it triggers (triggers: '.')
  • Frontend-pr Job: Verifies it triggers (no triggers = always run)

Test Strategy

  • Uses matrix strategy to test different trigger scenarios
  • Verifies the new triggered output works correctly
  • Tests with real repository (bcgov/quickstart-openshift)
  • Includes SonarCloud integration testing

📈 Benefits

  • Better Integration: Downstream actions can now check if this action was triggered
  • Improved Debugging: Clear error messages and troubleshooting steps
  • Input Validation: Prevents invalid inputs from causing runtime failures
  • Reliable Testing: Comprehensive test coverage of core functionality

🔍 Example Usage

- uses: bcgov/action-test-and-analyse@v1
  id: test-action
  with:
    commands: |
      npm ci
      npm run test:cov
    dir: frontend
    node_version: '20'

- name: Deploy if tests passed
  if: steps.test-action.outputs.triggered == 'true'
  run: echo 'Tests were triggered and passed!'

- Add comprehensive input validation with helpful error messages
- Validate required inputs (commands, dir, node_version)
- Check node_version format and cache values
- Verify directory existence and package.json presence
- Add detailed error handling for command failures
- Provide troubleshooting steps and debug information
- Add comprehensive validation test suite
- Test 7 different validation failure scenarios
- Improve user experience with clear error messages
- Remove manual input validation checks
- Add native pattern validation for node_version (regex: ^[0-9]+(\.[0-9]+)*$)
- Add native pattern validation for cache (regex: ^(npm|yarn|pnpm)$)
- Simplify validation tests to focus on error handling scenarios
- Let GitHub Actions handle required input validation natively
- Keep only essential error handling for command failures and directory checks
- Change single quotes to double quotes for consistency
- Fixes potential YAML parsing issues with regex pattern
- GitHub Actions doesn't support pattern validation in input schema
- Remove incorrect pattern parameters for node_version and cache
- GitHub Actions only supports required, default, and description for inputs
- Input validation would need to be done manually in action code if needed
- Clean up formatting by removing trailing spaces
- No functional changes, just code style improvements
- Add parentheses around commands input to handle multi-line commands properly
- Fixes 'syntax error near unexpected token' when commands contain newlines
- Commands like 'npm ci\nnpm run test:cov' now execute correctly in bash if statement
- Add pattern validation for node_version: '^[0-9]+(\.[0-9]+)*$'
- Add pattern validation for cache: '^(npm|yarn|pnpm)$'
- Follows same pattern as bcgov/action-deployer-openshift
- GitHub Actions does support pattern validation in action.yml
- Provides native input validation before action execution
- Add sonar_token pattern: ^[a-zA-Z0-9]{20,}$ (alphanumeric, min 20 chars)
- Add diff_branch pattern: ^[a-zA-Z0-9._/-]+$ (valid branch names)
- Add repository pattern: ^[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+$ (owner/repo format)
- Add branch pattern: ^[a-zA-Z0-9._/-]*$ (valid branch names, allows empty)
- Provides comprehensive input validation before action execution
- Follows same patterns as bcgov/action-deployer-openshift
- Add dir pattern: ^[a-zA-Z0-9._/-]+$ (valid directory paths)
- Allows alphanumeric, hyphens, underscores, dots, forward slashes
- Prevents spaces and special characters that could cause shell issues
- Supports common directory structures: frontend, src/components, .github
- Completes pattern validation coverage for all practical inputs
@DerekRoberts DerekRoberts merged commit 1553ed7 into main Sep 13, 2025
7 checks passed
@DerekRoberts DerekRoberts deleted the feat/enhanced-validation branch September 13, 2025 17:00
@github-project-automation github-project-automation bot moved this from New to Done in DevOps (NR) Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant