Merge branch 'release/0.7.3' #40
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: '@cmcrobotics' | |
- 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_snapshot_package() { | |
local TAG=$1 | |
NEW_VERSION=${{ steps.package-info.outputs.PKG_VERSION }}-$TAG.${{ github.run_number }} | |
echo "Publishing new version: $NEW_VERSION" | |
npm version $NEW_VERSION --no-git-tag-version | |
npm publish | |
npm dist-tag add ${{ steps.package-info.outputs.PKG_NAME }}@$NEW_VERSION $TAG | |
} | |
if [[ $GITHUB_REF == refs/heads/main ]]; then | |
# Publishing from main branch | |
publish_snapshot_package "stable" | |
elif [[ $GITHUB_REF == refs/heads/develop ]]; then | |
# Publishing from develop branch | |
publish_snapshot_package "dev" | |
elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
# Publishing from a tag | |
VERSION=${GITHUB_REF#refs/tags/v} | |
npm publish | |
npm dist-tag add ${{ steps.package-info.outputs.PKG_NAME }}@$VERSION "stable" | |
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 |