feat: enhanced input validation and error handling #84
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!" | |
validation-tests: | |
name: Validation Tests | |
runs-on: ubuntu-24.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
test: [missing-commands, missing-dir, missing-node-version, invalid-node-version, invalid-cache, missing-directory, missing-package-json] | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Test missing commands | |
if: matrix.test == 'missing-commands' | |
uses: ./ | |
continue-on-error: true | |
with: | |
dir: . | |
node_version: "20" | |
id: test-missing-commands | |
- name: Test missing dir | |
if: matrix.test == 'missing-dir' | |
uses: ./ | |
continue-on-error: true | |
with: | |
commands: "echo 'test'" | |
node_version: "20" | |
id: test-missing-dir | |
- name: Test missing node_version | |
if: matrix.test == 'missing-node-version' | |
uses: ./ | |
continue-on-error: true | |
with: | |
commands: "echo 'test'" | |
dir: . | |
id: test-missing-node-version | |
- name: Test invalid node_version | |
if: matrix.test == 'invalid-node-version' | |
uses: ./ | |
continue-on-error: true | |
with: | |
commands: "echo 'test'" | |
dir: . | |
node_version: "invalid-version" | |
id: test-invalid-node-version | |
- name: Test invalid cache | |
if: matrix.test == 'invalid-cache' | |
uses: ./ | |
continue-on-error: true | |
with: | |
commands: "echo 'test'" | |
dir: . | |
node_version: "20" | |
cache: "invalid-cache" | |
id: test-invalid-cache | |
- name: Test missing directory | |
if: matrix.test == 'missing-directory' | |
uses: ./ | |
continue-on-error: true | |
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: true | |
with: | |
commands: "echo 'test'" | |
dir: ".github" | |
node_version: "20" | |
id: test-missing-package-json | |
- name: Verify validation failures | |
run: | | |
case "${{ matrix.test }}" in | |
"missing-commands") | |
if [ "${{ steps.test-missing-commands.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for missing commands" | |
exit 1 | |
else | |
echo "✅ Correctly failed for missing commands" | |
fi | |
;; | |
"missing-dir") | |
if [ "${{ steps.test-missing-dir.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for missing dir" | |
exit 1 | |
else | |
echo "✅ Correctly failed for missing dir" | |
fi | |
;; | |
"missing-node-version") | |
if [ "${{ steps.test-missing-node-version.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for missing node_version" | |
exit 1 | |
else | |
echo "✅ Correctly failed for missing node_version" | |
fi | |
;; | |
"invalid-node-version") | |
if [ "${{ steps.test-invalid-node-version.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for invalid node_version" | |
exit 1 | |
else | |
echo "✅ Correctly failed for invalid node_version" | |
fi | |
;; | |
"invalid-cache") | |
if [ "${{ steps.test-invalid-cache.outcome }}" == "success" ]; then | |
echo "❌ Should have failed for invalid cache" | |
exit 1 | |
else | |
echo "✅ Correctly failed for invalid cache" | |
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 "🎉 Validation test '${{ matrix.test }}' passed!" |