Add ESM build #31
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: CI/CD | |
on: | |
push: | |
branches: [ main, develop ] | |
tags: | |
- 'v*' | |
pull_request: | |
branches: [ main, develop ] | |
jobs: | |
build-test-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
registry-url: 'https://npm.pkg.github.com' | |
scope: '@bcopy' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run unit tests | |
run: npm test | |
- name: Start Mosquitto | |
uses: namoshek/mosquitto-github-action@v1 | |
with: | |
version: '1.6' | |
ports: '1883:1883' | |
container-name: 'mqtt' | |
- name: Run integration tests | |
run: npm run test:integration | |
env: | |
MQTT_BROKER_URL: mqtt://localhost:1883 | |
- name: Build | |
run: npm run build | |
- name: Get package info | |
id: package-info | |
run: | | |
echo 'PKG_NAME=$(node -p "require(\"./package.json\").name")' >> $GITHUB_OUTPUT | |
echo 'PKG_VERSION=$(node -p "require(\"./package.json\").version")' >> $GITHUB_OUTPUT | |
- name: Publish to GitHub Packages | |
run: | | |
if [[ $GITHUB_REF == refs/heads/main ]]; then | |
# Publishing from main branch | |
npm publish --tag stable | |
elif [[ $GITHUB_REF == refs/heads/develop ]]; then | |
# Publishing from develop branch | |
npm version --no-git-tag-version prerelease --preid=dev | |
npm publish --tag dev | |
elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
# Publishing from a tag | |
VERSION=${GITHUB_REF#refs/tags/v} | |
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
npm publish --tag latest | |
else | |
npm publish --tag $VERSION | |
fi | |
fi | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
create-release: | |
needs: build-test-publish | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: false | |
prerelease: false |