forked from radicalgeek/node-microservice-chassis
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (63 loc) · 2.17 KB
/
npm-publish.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
name: CI/CD Pipeline
on:
push:
branches:
- main
workflow_dispatch:
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
MAJOR_VERSION: ${{ secrets.MAJOR_VERSION }}
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm ci --prefer-offline
- name: Cache npm
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Fetch tags
run: |
git fetch --tags
- name: Determine version
id: version
run: |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "1.0.0")
latest_major=$(echo $latest_tag | cut -d'.' -f1)
latest_minor=$(echo $latest_tag | cut -d'.' -f2)
if [ "$latest_major" != "$MAJOR_VERSION" ]; then
MINOR_VERSION=0
else
MINOR_VERSION=$((latest_minor+1))
fi
if git rev-parse refs/tags/$latest_tag >/dev/null 2>&1; then
PATCH_VERSION=$(git rev-list refs/tags/$latest_tag..HEAD --count)
else
PATCH_VERSION=0
fi
FULL_VERSION="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"
echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_ENV
- name: Tag the new version
run: |
git tag ${{ env.FULL_VERSION }}
git push https://$DEPLOY_TOKEN@github.com/${{ github.repository }} --tags
- name: Update package.json version
run: |
sed -i 's/"version": "[^"]*"/"version": "${{ env.FULL_VERSION }}"/' package.json
- name: Configure .npmrc for GitHub Packages
run: |
echo "registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.DEPLOY_TOKEN }}" >> .npmrc
- name: Publish to GitHub Packages
run: npm publish --access public