-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add javascript workflow #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||||||
| name: 'JavaScript CI' | ||||||||||
| description: 'Run lint, typecheck, optional tests, and build for Node.js/npm projects' | ||||||||||
|
|
||||||||||
| inputs: | ||||||||||
| token: | ||||||||||
| description: 'GitHub token for authentication' | ||||||||||
| required: true | ||||||||||
| node_version: | ||||||||||
| description: 'Node.js version to use' | ||||||||||
| required: false | ||||||||||
| default: 'lts/*' | ||||||||||
| working_directory: | ||||||||||
| description: 'Directory containing package.json (relative to repository root)' | ||||||||||
| required: false | ||||||||||
| default: '.' | ||||||||||
| lint_script: | ||||||||||
| description: 'NPM script name to run for linting' | ||||||||||
| required: false | ||||||||||
| default: 'lint' | ||||||||||
| run_tests: | ||||||||||
| description: 'Whether to run the test script (test or test:ci)' | ||||||||||
| required: false | ||||||||||
| default: 'true' | ||||||||||
|
|
||||||||||
| runs: | ||||||||||
| using: 'composite' | ||||||||||
| steps: | ||||||||||
| - name: Checkout repository | ||||||||||
| uses: actions/checkout@v4 | ||||||||||
| with: | ||||||||||
| fetch-depth: 0 | ||||||||||
| token: ${{ inputs.token }} | ||||||||||
|
|
||||||||||
| - name: Set up Node.js | ||||||||||
| uses: actions/setup-node@v4 | ||||||||||
| with: | ||||||||||
| node-version: ${{ inputs.node_version }} | ||||||||||
| cache: 'npm' | ||||||||||
| cache-dependency-path: ${{ inputs.working_directory }}/package-lock.json | ||||||||||
|
|
||||||||||
| - name: Install dependencies | ||||||||||
| shell: bash | ||||||||||
| working-directory: ${{ inputs.working_directory }} | ||||||||||
| run: | | ||||||||||
| if [ ! -f "package.json" ]; then | ||||||||||
| echo "❌ package.json not found in $PWD" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
|
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for |
||||||||||
| if [ -f "package-lock.json" ]; then | ||||||||||
| echo "📦 Using npm ci" | ||||||||||
| npm ci | ||||||||||
| else | ||||||||||
| echo "📦 Using npm install" | ||||||||||
| npm install | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| - name: Run lint | ||||||||||
| shell: bash | ||||||||||
| working-directory: ${{ inputs.working_directory }} | ||||||||||
| run: | | ||||||||||
| if jq -e ".scripts[\"${{ inputs.lint_script }}\"]" package.json >/dev/null; then | ||||||||||
| echo "🔎 Running npm run ${{ inputs.lint_script }}..." | ||||||||||
| npm run ${{ inputs.lint_script }} | ||||||||||
| else | ||||||||||
| echo "❌ No \"${{ inputs.lint_script }}\" script defined in package.json" | ||||||||||
| echo " Please add it or override the lint_script input." | ||||||||||
|
Lantum-Brendan marked this conversation as resolved.
|
||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| - name: Run typecheck | ||||||||||
| shell: bash | ||||||||||
| working-directory: ${{ inputs.working_directory }} | ||||||||||
| run: | | ||||||||||
| if jq -e '.scripts["typecheck"]' package.json >/dev/null; then | ||||||||||
| echo "🔡 Running npm run typecheck..." | ||||||||||
| npm run typecheck | ||||||||||
|
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the 'typecheck' script, the
Suggested change
|
||||||||||
| else | ||||||||||
|
Lantum-Brendan marked this conversation as resolved.
|
||||||||||
| echo "❌ No \"typecheck\" script defined in package.json" | ||||||||||
| echo " Please add a typecheck script (it can be a no-op if you are not using TypeScript)." | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| - name: Run tests | ||||||||||
| if: ${{ inputs.run_tests == 'true' }} | ||||||||||
| shell: bash | ||||||||||
| working-directory: ${{ inputs.working_directory }} | ||||||||||
| run: | | ||||||||||
| TEST_SCRIPT="" | ||||||||||
| if jq -e '.scripts["test:ci"]' package.json >/dev/null; then | ||||||||||
| TEST_SCRIPT="test:ci" | ||||||||||
| elif jq -e '.scripts["test"]' package.json >/dev/null; then | ||||||||||
| TEST_SCRIPT="test" | ||||||||||
| else | ||||||||||
| echo "❌ No \"test\" or \"test:ci\" script defined in package.json" | ||||||||||
| echo " Please define one of them to use the JavaScript CI action." | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| echo "🧪 Running npm run $TEST_SCRIPT..." | ||||||||||
| npm run "$TEST_SCRIPT" | ||||||||||
|
|
||||||||||
| - name: Run build | ||||||||||
| shell: bash | ||||||||||
| working-directory: ${{ inputs.working_directory }} | ||||||||||
| run: | | ||||||||||
| if jq -e '.scripts["build"]' package.json >/dev/null; then | ||||||||||
| echo "🏗️ Running npm run build..." | ||||||||||
| npm run build | ||||||||||
| else | ||||||||||
| echo "❌ No \"build\" script defined in package.json" | ||||||||||
| echo " Please add a build script (it can be a no-op if your project does not need a build step)." | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| - name: Summary | ||||||||||
| if: success() | ||||||||||
| shell: bash | ||||||||||
| run: | | ||||||||||
| echo "## ✅ JavaScript CI Summary" >> "$GITHUB_STEP_SUMMARY" | ||||||||||
| echo "" >> "$GITHUB_STEP_SUMMARY" | ||||||||||
| echo "- Node.js version: \`${{ inputs.node_version }}\`" >> "$GITHUB_STEP_SUMMARY" | ||||||||||
| echo "- Working directory: \`${{ inputs.working_directory }}\`" >> "$GITHUB_STEP_SUMMARY" | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.