forked from bcopy/homie-lit
-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (86 loc) · 2.7 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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