-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (90 loc) · 3.22 KB
/
deploy.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
105
106
name: Deploy
on:
workflow_dispatch:
inputs:
ReleaseType:
description: 'Release Type'
required: true
default: 'warning'
type: choice
options:
- Major
- Feature
- Bug
jobs:
update-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
scope: '@keyvaluesystems'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
- name: 'Set release type : ${{ inputs.ReleaseType }}'
id: release_type
uses: ASzc/change-string-case-action@v5
with:
string: ${{ inputs.ReleaseType }}
- name: Extract Current Branch and Validate
id: get_current_branch
shell: bash
run: |
BRANCH="${GITHUB_REF#refs/heads/}"
if [ "$BRANCH" == 'master' ]
then
echo "Branch validation Successful"
else
echo "Releases only taken from master branch"
exit 1
fi
- name: Get Latest version from package.json
run: |
# Get the latest version from package.json
LATEST_VERSION=$(node -p "require('./package.json').version")
# Output the latest version as a workflow env
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
- name: Get new version
id: get_next_version
uses: christian-draeger/increment-semantic-version@1.0.3
with:
current-version: ${{ env.latest_version }}
version-fragment: ${{ steps.release_type.outputs.lowercase }}
- name: Update version in package.json and package-lock.json
run: |
OLD_VERSION=${{ env.latest_version }}
NEW_VERSION=${{ steps.get_next_version.outputs.next-version }}
npm version $NEW_VERSION --no-git-tag-version
git config user.name github-actions
git config user.email github-actions@github.com
git add package.json package-lock.json
git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION"
git push origin HEAD:master
- name: Build Package
run: npm run build
- name: Publish package
run: npm publish --access public --//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
if: success()
- name: Revert package.json and package-lock.json
run: |
# Revert package.json and package-lock.json to the previous version
npm version ${{ env.latest_version }} --no-git-tag-version
git commit -am "Revert to version ${{ env.latest_version }}"
git push origin HEAD:master
if: failure()
- name: Create GitHub release
if: success()
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_next_version.outputs.next-version }}
release_name: Release v${{ steps.get_next_version.outputs.next-version }}
# body: Release ${{ env.NEW_VERSION }}
draft: false
prerelease: false