-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (162 loc) · 5.27 KB
/
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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Version Check and Publish
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: read
packages: write
issues: write
env:
REPO_NAME: ${GITHUB_REPOSITORY#*/}
jobs:
check-version:
name: Check version
runs-on: ubuntu-latest
outputs:
should_update: ${{ steps.compare_versions.outputs.should_update }}
should_publish: ${{ steps.compare_versions.outputs.should_publish }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Compare versions and set output
id: compare_versions
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
NPM_VERSION=$(npm view ${{ env.REPO_NAME }} version)
HIGHEST_VERSION=$(echo -e "$CURRENT_VERSION\n$NPM_VERSION" | sort -V | tail -n 1)
if [ "$HIGHEST_VERSION" = "$NPM_VERSION" ]; then
echo "should_update=true" >> $GITHUB_OUTPUT
elif [ "$HIGHEST_VERSION" = "$CURRENT_VERSION" ]; then
echo "should_publish=true" >> $GITHUB_OUTPUT
fi
build:
name: Build
needs: check-version
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: rm -rf dist && yarn build
- name: Prepare Template
run: |
cd dist
git clone https://github.com/Thre4dripper/NodeTs-Express-Service-Based-Template.git template
cd template
rm -rf .git && rm -rf .github
cd ../
cp -r template template-ts && cp -r template template-js
cd template-ts && rm -rf src-javascript && mv src-typescript src
sed -i 's|"rootDir": "./src-typescript"|"rootDir": "./src"|g' tsconfig.json
cd ../
cd template-js && rm -rf src-typescript && mv src-javascript src
rm tsconfig.json
cd ../
rm -rf template
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: build
path: |
./**
!node_modules/**
publish:
name: Publish to NPM
needs: build
if: needs.build.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Get build artifact
uses: actions/download-artifact@v4
with:
name: build
path: .
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Publish package on NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
release:
name: Create Release
needs: publish
if: needs.publish.result == 'success'
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Get build artifact
uses: actions/download-artifact@v4
with:
name: build
path: .
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Get Version
id: get_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
env:
tag: v${{ steps.get_version.outputs.VERSION }}
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="Release $tag" \
--generate-notes
- name: Create Release Asset
run: |
tar -czf release-v${{ steps.get_version.outputs.VERSION }}.tgz dist
shell: bash
- name: Upload Release Asset
run: |
gh release upload "$tag" release-v${{ steps.get_version.outputs.VERSION }}.tar.gz --clobber
shell: bash
update-version:
name: Update version
needs: check-version
if: needs.check-version.outputs.should_update == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Loop until versions match
run: |
while [ "$(npm view ${{ env.REPO_NAME }} version)" != "$(node -p "require('./package.json').version")" ]; do
git config --global user.name 'Version Bot'
git config --global user.email '[email protected]'
npm version patch -m "Update version to %s"
done
- name: Update version to next patch
run: |
git config --global user.name 'Version Bot'
git config --global user.email '[email protected]'
npm version patch -m "Update version to %s"
git push