Skip to content

Commit 494c02c

Browse files
committed
added deployment github action
1 parent 473577a commit 494c02c

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Update version and Publish Package
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+
28+
- name: Install dependencies
29+
run: npm install
30+
31+
- name: Run tests
32+
run: npm run test
33+
34+
- name: Build Package
35+
run: npm run build
36+
37+
- name: 'Set release type : ${{ inputs.ReleaseType }}'
38+
id: release_type
39+
uses: ASzc/change-string-case-action@v5
40+
with:
41+
string: ${{ inputs.ReleaseType }}
42+
43+
- name: Extract Current Branch and Validate
44+
id: get_current_branch
45+
shell: bash
46+
run: |
47+
BRANCH="${GITHUB_REF#refs/heads/}"
48+
if [ "$BRANCH" == 'main' ]
49+
then
50+
echo "Branch validation Successful"
51+
else
52+
echo "Releases only taken from main branch"
53+
exit 1
54+
fi
55+
56+
- name: Get Latest version from package.json
57+
run: |
58+
# Get the latest version from package.json
59+
LATEST_VERSION=$(node -p "require('./package.json').version")
60+
61+
# Output the latest version as a workflow env
62+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
63+
64+
- name: Get new version
65+
id: get_next_version
66+
uses: christian-draeger/increment-semantic-version@1.0.3
67+
with:
68+
current-version: ${{ env.latest_version }}
69+
version-fragment: ${{ steps.release_type.outputs.lowercase }}
70+
71+
- name: Update version in package.json and package-lock.json
72+
run: |
73+
OLD_VERSION=${{ env.latest_version }}
74+
NEW_VERSION=${{ steps.get_next_version.outputs.next-version }}
75+
76+
npm version $NEW_VERSION --no-git-tag-version
77+
git config user.name github-actions
78+
git config user.email github-actions@github.com
79+
git add package.json package-lock.json
80+
git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION"
81+
git push origin HEAD:main
82+
83+
- name: Publish package
84+
uses: JS-DevTools/npm-publish@v1
85+
with:
86+
token: ${{ secrets.NPM_AUTH_TOKEN }}
87+
if: success()
88+
89+
- name: Revert package.json and package-lock.json
90+
run: |
91+
# Revert package.json and package-lock.json to the previous version
92+
npm version ${{ env.latest_version }} --no-git-tag-version
93+
git commit -am "Revert to version ${{ env.latest_version }}"
94+
git push origin HEAD:main
95+
if: failure()
96+
97+
- name: Create GitHub release
98+
if: success()
99+
uses: actions/create-release@v1
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
with:
103+
tag_name: v${{ steps.get_next_version.outputs.next-version }}
104+
release_name: Release v${{ steps.get_next_version.outputs.next-version }}
105+
# body: Release ${{ env.NEW_VERSION }}
106+
draft: false
107+
prerelease: false

0 commit comments

Comments
 (0)