Module CI/CD #5
Workflow file for this run
This file contains 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: Module CI/CD | |
on: | |
push: | |
tags: | |
- v0.** | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
node: [16, 18] # Test against multiple Node.js versions | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Clean npm cache | |
run: npm cache clean -f | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node }} | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Check npm version | |
run: npm --version | |
- name: Install dependencies and run tests | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npm ci | |
npm run lint | |
npm run build | |
deploy: | |
name: Deploy to NPM | |
needs: build-and-test # Make sure build and test pass before deploying | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
registry-url: 'https://npm.pkg.github.com' | |
- name: Publish package | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | |
run: npm publish --registry=https://npm.pkg.github.com/ --access public |