Skip to content

Commit

Permalink
chore: add cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilian committed Jan 2, 2025
1 parent c19acd9 commit b9d32d5
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

name: Node.js CI/CD

on:
push:
branches:
- master # Build on every push to main
- feat/add-cicd # Build on every push to feat/add-cicd
tags:
- v* # Publish to npm when pushing a tag that starts with "v"

jobs:
# -------------------------------------
# 1. Build job (for pushes to main)
# -------------------------------------
build:
# Only run this job when *not* publishing a tag
if: startsWith(github.ref, 'refs/tags/') != true
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

# -------------------------------------
# 2. Release job (for pushes with tags)
# -------------------------------------
release:
# Only run when the ref is a tag
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20'
# Configure default registry to npmjs.org
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm test

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 comments on commit b9d32d5

Please sign in to comment.