feat: enhanced input validation and error handling #94
Workflow file for this run
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
name: Tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- ".github/**" | |
- "**.md" | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: {} | |
jobs: | |
tests: | |
name: Tests | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
name: [backend, frontend-merge, frontend-pr] | |
include: | |
- name: backend | |
dir: backend | |
triggers: ('backend/') | |
expected_triggered: false | |
- name: frontend-merge | |
dir: frontend | |
triggers: ('.') | |
expected_triggered: true | |
- name: frontend-pr | |
dir: frontend | |
expected_triggered: true | |
steps: | |
- uses: actions/checkout@v5 | |
- id: action | |
uses: ./ | |
with: | |
commands: | | |
npm ci | |
npm run test:cov | |
dir: ${{ matrix.dir }} | |
node_version: "20" | |
repository: bcgov/quickstart-openshift | |
sonar_args: > | |
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts | |
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info | |
-Dsonar.organization=bcgov-nr | |
-Dsonar.projectKey=bcgov-nr_action-test-and-analyse_${{ matrix.dir }} | |
-Dsonar.sources=src | |
-Dsonar.tests.inclusions=**/*spec.ts | |
sonar_token: ${{ matrix.name == 'backend' && secrets.SONAR_TOKEN_BACKEND || secrets.SONAR_TOKEN_FRONTEND }} | |
triggers: ${{ matrix.triggers }} | |
- name: Verify trigger behavior | |
run: | | |
echo "🔍 Verifying trigger behavior for ${{ matrix.name }}" | |
echo "Expected: ${{ matrix.expected_triggered }}" | |
echo "Actual: ${{ steps.action.outputs.triggered }}" | |
case "${{ matrix.name }}" in | |
"backend") | |
if [ "${{ steps.action.outputs.triggered }}" != "false" ]; then | |
echo "❌ Backend job should NOT have been triggered (no backend/ changes)" | |
exit 1 | |
else | |
echo "✅ Backend job correctly NOT triggered" | |
fi | |
;; | |
"frontend-merge") | |
if [ "${{ steps.action.outputs.triggered }}" != "true" ]; then | |
echo "❌ Frontend-merge job should have been triggered (triggers: '.')" | |
exit 1 | |
else | |
echo "✅ Frontend-merge job correctly triggered" | |
fi | |
;; | |
"frontend-pr") | |
if [ "${{ steps.action.outputs.triggered }}" != "true" ]; then | |
echo "❌ Frontend-pr job should have been triggered (no triggers = always run)" | |
exit 1 | |
else | |
echo "✅ Frontend-pr job correctly triggered" | |
fi | |
;; | |
esac | |
echo "🎉 ${{ matrix.name }} trigger behavior verified correctly!" | |
error-handling-tests: | |
name: Error Handling Tests | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
test: [command-failure, missing-directory, missing-package-json] | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Test command failure handling | |
if: matrix.test == 'command-failure' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "npm run nonexistent-script" | |
dir: . | |
node_version: "20" | |
id: test-command-failure | |
- name: Test missing directory | |
if: matrix.test == 'missing-directory' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "nonexistent-directory" | |
node_version: "20" | |
id: test-missing-directory | |
- name: Test missing package.json | |
if: matrix.test == 'missing-package-json' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: ".github" | |
node_version: "20" | |
id: test-missing-package-json | |
- name: Verify error handling | |
run: | | |
case "${{ matrix.test }}" in | |
"command-failure") | |
if [ "${{ steps.test-command-failure.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for command failure" | |
exit 1 | |
else | |
echo "✅ Correctly failed for command failure with helpful error message" | |
fi | |
;; | |
"missing-directory") | |
if [ "${{ steps.test-missing-directory.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for missing directory" | |
exit 1 | |
else | |
echo "✅ Correctly failed for missing directory" | |
fi | |
;; | |
"missing-package-json") | |
if [ "${{ steps.test-missing-package-json.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for missing package.json" | |
exit 1 | |
else | |
echo "✅ Correctly failed for missing package.json" | |
fi | |
;; | |
esac | |
echo "🎉 Error handling test '${{ matrix.test }}' passed!" | |
pattern-validation-tests: | |
name: Pattern Validation Tests | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
test: [invalid-node-version, invalid-cache, invalid-dir, invalid-sonar-token, invalid-repository] | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Test invalid node_version pattern | |
if: matrix.test == 'invalid-node-version' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "." | |
node_version: "invalid-version" | |
id: test-invalid-node-version | |
- name: Test invalid cache pattern | |
if: matrix.test == 'invalid-cache' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "." | |
node_version: "20" | |
cache: "invalid-cache" | |
id: test-invalid-cache | |
- name: Test invalid dir pattern | |
if: matrix.test == 'invalid-dir' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "invalid dir with spaces" | |
node_version: "20" | |
id: test-invalid-dir | |
- name: Test invalid sonar_token pattern | |
if: matrix.test == 'invalid-sonar-token' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "." | |
node_version: "20" | |
sonar_token: "short" | |
id: test-invalid-sonar-token | |
- name: Test invalid repository pattern | |
if: matrix.test == 'invalid-repository' | |
uses: ./ | |
continue-on-error: false | |
with: | |
commands: "echo 'test'" | |
dir: "." | |
node_version: "20" | |
repository: "invalid/repo/format" | |
id: test-invalid-repository | |
- name: Verify pattern validation results | |
run: | | |
echo "🔍 Testing pattern validation for: ${{ matrix.test }}" | |
echo "Expected: Should fail due to invalid pattern" | |
echo "Actual outcome: ${{ steps[format('test-{0}', matrix.test)].outcome }}" | |
case "${{ matrix.test }}" in | |
"invalid-node-version") | |
if [ "${{ steps.test-invalid-node-version.outcome }}" == "success" ]; then | |
echo "❌ Pattern validation FAILED - invalid node_version was accepted" | |
echo " This means pattern validation is NOT working" | |
exit 1 | |
else | |
echo "✅ Pattern validation WORKED - invalid node_version was rejected" | |
fi | |
;; | |
"invalid-cache") | |
if [ "${{ steps.test-invalid-cache.outcome }}" == "success" ]; then | |
echo "❌ Pattern validation FAILED - invalid cache was accepted" | |
echo " This means pattern validation is NOT working" | |
exit 1 | |
else | |
echo "✅ Pattern validation WORKED - invalid cache was rejected" | |
fi | |
;; | |
"invalid-dir") | |
if [ "${{ steps.test-invalid-dir.outcome }}" == "success" ]; then | |
echo "❌ Pattern validation FAILED - invalid dir was accepted" | |
echo " This means pattern validation is NOT working" | |
exit 1 | |
else | |
echo "✅ Pattern validation WORKED - invalid dir was rejected" | |
fi | |
;; | |
"invalid-sonar-token") | |
if [ "${{ steps.test-invalid-sonar-token.outcome }}" == "success" ]; then | |
echo "❌ Pattern validation FAILED - invalid sonar_token was accepted" | |
echo " This means pattern validation is NOT working" | |
exit 1 | |
else | |
echo "✅ Pattern validation WORKED - invalid sonar_token was rejected" | |
fi | |
;; | |
"invalid-repository") | |
if [ "${{ steps.test-invalid-repository.outcome }}" == "success" ]; then | |
echo "❌ Pattern validation FAILED - invalid repository was accepted" | |
echo " This means pattern validation is NOT working" | |
exit 1 | |
else | |
echo "✅ Pattern validation WORKED - invalid repository was rejected" | |
fi | |
;; | |
esac | |
echo "🎉 Pattern validation test '${{ matrix.test }}' completed!" |