1+ name : Deploy
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ ReleaseType :
7+ description : ' Release Type'
8+ required : true
9+ default : ' warning'
10+ type : choice
11+ options :
12+ - Major
13+ - Feature
14+ - Bug
15+
16+ jobs :
17+ update-and-publish :
18+ runs-on : ubuntu-latest
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v2
22+
23+ - name : Setup Node.js
24+ uses : actions/setup-node@v2
25+ with :
26+ node-version : 16.x
27+ scope : ' @keyvaluesystems'
28+
29+ - name : Install dependencies
30+ run : npm install
31+
32+ - name : Run tests
33+ run : npm run test
34+
35+ - name : ' Set release type : ${{ inputs.ReleaseType }}'
36+ id : release_type
37+ uses : ASzc/change-string-case-action@v5
38+ with :
39+ string : ${{ inputs.ReleaseType }}
40+
41+ - name : Extract Current Branch and Validate
42+ id : get_current_branch
43+ shell : bash
44+ run : |
45+ BRANCH="${GITHUB_REF#refs/heads/}"
46+ if [ "$BRANCH" == 'master' ]
47+ then
48+ echo "Branch validation Successful"
49+ else
50+ echo "Releases only taken from master branch"
51+ exit 1
52+ fi
53+
54+ - name : Get Latest version from package.json
55+ run : |
56+ # Get the latest version from package.json
57+ LATEST_VERSION=$(node -p "require('./package.json').version")
58+
59+ # Output the latest version as a workflow env
60+ echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
61+
62+ - name : Get new version
63+ id : get_next_version
64+ uses :
christian-draeger/[email protected] 65+ with :
66+ current-version : ${{ env.latest_version }}
67+ version-fragment : ${{ steps.release_type.outputs.lowercase }}
68+
69+ - name : Update version in package.json and package-lock.json
70+ run : |
71+ OLD_VERSION=${{ env.latest_version }}
72+ NEW_VERSION=${{ steps.get_next_version.outputs.next-version }}
73+
74+ npm version $NEW_VERSION --no-git-tag-version
75+ git config user.name github-actions
76+ git config user.email [email protected] 77+ git add package.json package-lock.json
78+ git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION"
79+ git push origin HEAD:master
80+
81+ - name : Build Package
82+ run : npm run build
83+
84+ - name : Publish package
85+ run : npm publish --access public --//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
86+ if : success()
87+
88+ - name : Revert package.json and package-lock.json
89+ run : |
90+ # Revert package.json and package-lock.json to the previous version
91+ npm version ${{ env.latest_version }} --no-git-tag-version
92+ git commit -am "Revert to version ${{ env.latest_version }}"
93+ git push origin HEAD:master
94+ if : failure()
95+
96+ - name : Create GitHub release
97+ if : success()
98+ uses : actions/create-release@v1
99+ env :
100+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
101+ with :
102+ tag_name : v${{ steps.get_next_version.outputs.next-version }}
103+ release_name : Release v${{ steps.get_next_version.outputs.next-version }}
104+ # body: Release ${{ env.NEW_VERSION }}
105+ draft : false
106+ prerelease : false
0 commit comments