-
Notifications
You must be signed in to change notification settings - Fork 4
130 lines (114 loc) · 4.76 KB
/
standard-publish.yaml
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Standard Publish
permissions: write-all
on:
push:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
# do not start if [skip-publish] and [skip publish] is found in commit msg
# configuration:
# - you can change the keywords to your desired ones in the below "if" statement
if: contains(github.event.head_commit.message, '[skip-publish]') != true && contains(github.event.head_commit.message, '[skip publish]') != true
# All steps of the job depend on their previous step to finish successfully
steps:
# Checkout repo
- name: Checkout Repo
id: checkout
uses: actions/checkout@v3
# Install node
- name: Install NodeJS v18
id: node
if: steps.checkout.outcome == 'success'
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
# Install deps
- name: Install Dependencies
id: install
if: steps.node.outcome == 'success'
run: npm install --ignore-scripts
# Lint the source code
- name: Lint
id: lint
if: steps.install.outcome == 'success'
run: npm run lint
# Run the tests
- name: Test
id: test
if: steps.lint.outcome == 'success'
run: npm test
# Test doc generation
- name: Test Docs Generation
id: docs
if: steps.test.outcome == 'success'
run: npm run docgen
# Configure Git
- name: Git Config
id: git
if: steps.docs.outcome == 'success'
# set git user and email to github actions,
# this email and user id will result in github user with github avatar in Github
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
# Major Release
- name: Bump Major Version
id: major
# bump major version only if the commit msg ends with [major] keyword
# [major] keyword must be at the end of commit msg
# configuration:
# - you can change the keyword to your desired one in the below "if" statement
if: steps.git.outcome == 'success' && endsWith(github.event.head_commit.message, '[major]')
# bump the major version without creating tag and commit and store the version in env
run: echo "NEW_VERSION=$(npm version major --no-git-tag-version)" >> $GITHUB_ENV
# Minor Release
- name: Bump Minor Version
id: minor
# bump minor version only if the commit msg ends with [minor] keyword
# [minor] keyword must be at the end of commit msg
# configuration:
# - you can change the keyword to your desired one in the below "if" statement
if: steps.git.outcome == 'success' && endsWith(github.event.head_commit.message, '[minor]')
# bump the minor version without creating tag and commit and store the version in env
run: echo "NEW_VERSION=$(npm version minor --no-git-tag-version)" >> $GITHUB_ENV
# Patch Release
- name: Bump Patch Version
id: patch
# bump patch version only if [major] and [minor] are not present in commit msg
# will increase patch version for any other commits that don't have major and minor keywords
# configuration:
# - alternatively you can set a keyword for bumping patch version with specific keyword
if: steps.git.outcome == 'success' && ! endsWith(github.event.head_commit.message, '[major]') && ! endsWith(github.event.head_commit.message, '[minor]')
# bump the patch version without creating tag and commit and store the version in env
run: echo "NEW_VERSION=$(npm version patch --no-git-tag-version)" >> $GITHUB_ENV
# Commit changes and tag
- name: Commit And Tag
id: commit
if: steps.major.outcome == 'success' || steps.minor.outcome == 'success' || steps.patch.outcome == 'success'
run: |
git add "package.json"
git add "package-lock.json"
git commit -m "Release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
# Push changes and tag
- name: Push Changes To Remote
id: push
if: steps.commit.outcome == 'success'
run: |
git push origin
git push -u origin ${{ env.NEW_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create gitHub release with built package archives
- name: Create GitHub Release
id: release
if: steps.push.outcome == 'success'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
name: Release ${{ env.NEW_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}