Skip to content

Commit 1553ed7

Browse files
authored
feat: enhanced input validation and error handling (#79)
1 parent 750b218 commit 1553ed7

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

action.yml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ inputs:
1313
dir:
1414
description: App/package directory
1515
required: true
16+
pattern: "^[a-zA-Z0-9._/-]+$"
1617

1718
node_version:
18-
description: Node version to use
19+
description: Node version to use (e.g., '18', '20', '22')
1920
required: true
21+
pattern: '^[0-9]+(\.[0-9]+)*$'
2022

2123
### Typical / recommended
2224
cache:
2325
description: Package manager for caching; e.g. npm, yarn, pnpm
2426
default: npm
27+
pattern: "^(npm|yarn|pnpm)$"
2528

2629
sonar_args:
2730
# https://docs.sonarcloud.io/advanced-setup/analysis-parameters/
@@ -32,6 +35,7 @@ inputs:
3235
3336
sonar_token:
3437
description: Sonar token, provide unpopulated token for pre-setup (will skip)
38+
pattern: "^[a-zA-Z0-9]{20,}$"
3539

3640
triggers:
3741
description: Paths (array) used to trigger a build; e.g. ('./backend/' './frontend/)
@@ -40,14 +44,17 @@ inputs:
4044
diff_branch:
4145
description: Branch to diff against
4246
default: ${{ github.event.repository.default_branch }}
47+
pattern: "^[a-zA-Z0-9._/-]+$"
4348

4449
repository:
4550
description: Non-default repository to clone (used for testing this action)
4651
default: ${{ github.repository }}
52+
pattern: "^[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+$"
4753

4854
branch:
4955
description: Non-default branch to clone (used for testing this action)
5056
default: ""
57+
pattern: "^[a-zA-Z0-9._/-]*$"
5158

5259
outputs:
5360
triggered:
@@ -61,24 +68,14 @@ runs:
6168
shell: bash
6269
run: |
6370
# Warnings for breaking changes
64-
65-
# node_version now required
66-
if [ -z "${{ inputs.node_version }}" ]; then
67-
echo -e "\nnode_version now required. Previous default: 16."
68-
echo -e "\n\tAction: add a node_version parameter\n"
69-
exit 1
70-
fi
71-
72-
# sonar_project_token renamed sonar_token
7371
if [ ! -z "${{ inputs.sonar_project_token }}" ]; then
74-
echo -e "\nsonar_project_token renamed. Please correct this and try again."
72+
echo -e "\n⚠️ Breaking change: sonar_project_token renamed"
7573
echo -e "\n\tAction: rename sonar_project_token to sonar_token\n"
7674
exit 1
7775
fi
7876
79-
#
8077
if [ ! -z "${{ inputs.sonar_comment_token }}" ]; then
81-
echo -e "\nsonar_comment_token deprecated. Please correct this and try again."
78+
echo -e "\n⚠️ Breaking change: sonar_comment_token deprecated"
8279
echo -e "\n\tAction: remove sonar_comment_token parameter\n"
8380
exit 1
8481
fi
@@ -110,8 +107,35 @@ runs:
110107
shell: bash
111108
working-directory: ${{ inputs.dir }}
112109
run: |
113-
# Run Tests
114-
${{ inputs.commands }}
110+
echo "🚀 Running test commands in ${{ inputs.dir }}..."
111+
echo "Commands: ${{ inputs.commands }}"
112+
113+
# Run Tests with error handling
114+
if ! (${{ inputs.commands }}); then
115+
echo ""
116+
echo "❌ Test commands failed!"
117+
echo ""
118+
echo "🔧 Common troubleshooting steps:"
119+
echo " 1. Check if package.json exists and has test scripts"
120+
echo " 2. Verify all dependencies are installed (npm ci)"
121+
echo " 3. Check if test files exist and are properly configured"
122+
echo " 4. Ensure Node.js version compatibility"
123+
echo ""
124+
echo "📋 Debug information:"
125+
echo " - Working directory: $(pwd)"
126+
echo " - Node version: $(node --version)"
127+
echo " - NPM version: $(npm --version)"
128+
echo " - Available scripts:"
129+
if [ -f package.json ]; then
130+
npm run 2>/dev/null | grep -E '^ [a-z]' | head -10 || echo " (no scripts found)"
131+
else
132+
echo " (no package.json found)"
133+
fi
134+
echo ""
135+
exit 1
136+
fi
137+
138+
echo "✅ Test commands completed successfully"
115139
116140
### Optional SonarCloud
117141

0 commit comments

Comments
 (0)