Skip to content

Merge tag 'v0.5.6' into develop #45

Merge tag 'v0.5.6' into develop

Merge tag 'v0.5.6' into develop #45

Workflow file for this run

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: |
publish_package() {
local TAG=$1
local VERSION_SUFFIX=$2
# Try to get the current version, if it doesn't exist, this will be empty
CURRENT_VERSION=$(npm view $PKG_NAME version --tag $TAG 2>/dev/null || echo "")
if [ ! -z "$CURRENT_VERSION" ]; then
echo "Unpublishing existing version: $CURRENT_VERSION"
npm unpublish $PKG_NAME@$CURRENT_VERSION --force
else
echo "No existing version found for tag: $TAG"
fi
NEW_VERSION=$PKG_VERSION-$VERSION_SUFFIX.${{ github.run_number }}
echo "Publishing new version: $NEW_VERSION"
npm version $NEW_VERSION --no-git-tag-version
npm publish --tag $TAG
}
if [[ $GITHUB_REF == refs/heads/main ]]; then
# Publishing from main branch
publish_package "stable" "stable"
elif [[ $GITHUB_REF == refs/heads/develop ]]; then
# Publishing from develop branch
publish_package "dev" "dev"
elif [[ $GITHUB_REF == refs/tags/* ]]; then
# Publishing from a tag
VERSION=${GITHUB_REF#refs/tags/v}
npm publish --tag $VERSION
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