Update README.md #331
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
| # Workflow for testing Node.js applications with clean dependency installation, caching, build, and tests | |
| name: test | |
| # Trigger the workflow on push and pull requests to the main branch | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| # Define permissions for security best practices | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Check out the repository code | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Set up Node.js with the latest available version | |
| - name: Set up Node.js (latest) | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 'latest' # Dynamically uses the latest Node.js version | |
| check-latest: true # Ensures the newest version is fetched (optional) | |
| cache: 'npm' | |
| cache-dependency-path: '**/package-lock.json' | |
| # Clean npm cache to prevent cache bloat | |
| - name: Clean npm cache | |
| run: npm cache clean --force | |
| # Install dependencies | |
| - name: Install dependencies | |
| run: npm ci | |
| # Build the project if a build script exists | |
| - name: Build project | |
| run: npm run build --if-present | |
| # Run tests | |
| - name: Run tests | |
| run: npm test | |
| # Upload artifacts for debugging if the job fails | |
| - name: Upload build artifacts (if build fails) | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-output | |
| path: | | |
| dist/ | |
| build/ | |
| retention-days: 7 | |
| # Enable debug logging for troubleshooting | |
| env: | |
| ACTIONS_STEP_DEBUG: true |