Added various NPM scripts.
This commit is contained in:
69
npm/npm-test/action.yaml
Normal file
69
npm/npm-test/action.yaml
Normal file
@@ -0,0 +1,69 @@
|
||||
name: npm-test
|
||||
description: "Install dependencies and run tests for an NPM package."
|
||||
inputs:
|
||||
workingDirectory:
|
||||
description: "Working directory containing package.json."
|
||||
required: false
|
||||
default: "."
|
||||
nodeVersion:
|
||||
description: "Node.js version to use."
|
||||
required: false
|
||||
default: "20"
|
||||
testCommand:
|
||||
description: "Command to run tests. Default: npm test"
|
||||
required: false
|
||||
default: "npm test"
|
||||
coverageCommand:
|
||||
description: "Command to run tests with coverage. Default: npm run test:coverage"
|
||||
required: false
|
||||
default: "npm run test:coverage"
|
||||
runCoverage:
|
||||
description: "Whether to run coverage. Values: true, false."
|
||||
required: false
|
||||
default: "false"
|
||||
coverageDirectory:
|
||||
description: "Directory for the coverage output. Default: coverage"
|
||||
required: false
|
||||
default: "coverage"
|
||||
uploadArtifacts:
|
||||
description: "Whether to upload test artifacts. Values: true, false."
|
||||
required: false
|
||||
default: "false"
|
||||
artifactName:
|
||||
description: "Name of the artifact to upload. Default: test-results"
|
||||
required: false
|
||||
default: "test-results"
|
||||
retention-days:
|
||||
description: "Number of retention days for artifacts. Default: 7"
|
||||
required: false
|
||||
default: "7"
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Setup Node.js"
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.nodeVersion }}
|
||||
cache: npm
|
||||
cache-dependency-path: ${{ inputs.workingDirectory }}/package-lock.json
|
||||
- name: "Install dependencies"
|
||||
run: npm ci
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Run tests"
|
||||
run: ${{ inputs.testCommand }}
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Run tests with coverage"
|
||||
if: ${{ inputs.runCoverage == 'true' }}
|
||||
run: ${{ inputs.coverageCommand }}
|
||||
working-directory: ${{ inputs.workingDirectory }}
|
||||
shell: bash
|
||||
- name: "Upload test artifacts"
|
||||
if: ${{ inputs.uploadArtifacts == 'true' && always() }}
|
||||
uses: https://github.com/ChristopherHX/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: ${{ inputs.artifactName }}
|
||||
path: ${{ inputs.workingDirectory }}/${{ inputs.coverageDirectory }}
|
||||
if-no-files-found: warn
|
||||
retention-days: ${{ inputs.retention-days }}
|
||||
Reference in New Issue
Block a user