This repository has been archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
250 lines (245 loc) · 9.35 KB
/
npm.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# DO NOT EDIT: BEGIN
# This snippet has been inserted automatically by mobsuccessbot, do not edit!
# If changes are needed, update the action npm in
# https://github.com/mobsuccess-devops/github-mobsuccess-policy
on:
merge_group:
types:
- checks_requested
push:
branches: [master, preprod, prod]
pull_request:
types: [opened, synchronize, reopened]
name: NPM
jobs:
packagejsonlint:
name: PackageJsonLint
runs-on: ubuntu-20.04
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- uses: mobsuccess-devops/github-actions-packagejsonlint@master
sortpackagejson:
name: Sort Package Json
runs-on: ubuntu-20.04
timeout-minutes: 7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- name: Cache Node Modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-20.12.0
- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc
name: Configure Credentials For GitHub Packages
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
working-directory: .
- run: |
echo "💡 👉 Check not passing? see the doc at https://www.notion.so/mobsuccess/sort-package-json-de5cf4648e8545dbb5a2a5a910380535"
npx --yes sort-package-json@2.4.1 --check
working-directory: .
prettier:
name: Prettier
runs-on: ubuntu-20.04
timeout-minutes: 7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- name: Cache Node Modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-20.12.0
- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc
name: Configure Credentials For GitHub Packages
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
working-directory: .
- run: npm run prettier
working-directory: .
eslint:
name: Eslint
runs-on: ubuntu-20.04
timeout-minutes: 7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- name: Cache Node Modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-20.12.0
- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc
name: Configure Credentials For GitHub Packages
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
working-directory: .
- run: npm run eslint
working-directory: .
test:
name: Test
runs-on: ubuntu-20.04
timeout-minutes: 7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- name: Cache Node Modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-20.12.0
- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc
name: Configure Credentials For GitHub Packages
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
working-directory: .
- run: npm run test
working-directory: .
postBuild:
needs: [packagejsonlint, sortpackagejson, prettier, eslint, test]
name: Post-Build
runs-on: ubuntu-20.04
timeout-minutes: 2
outputs:
needsPackage: ${{ steps.checkEligibility.outputs.needsPackage }}
pr: ${{ steps.checkEligibility.outputs.pr }}
tag: ${{ steps.checkEligibility.outputs.tag }}
steps:
- name: Check Package Eligibility
id: checkEligibility
run: |
if [[ ${{github.ref}} == "refs/heads/master" ]]; then
echo Packaging for master
echo "needsPackage=true" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_OUTPUT
else
has_label_package=${{ contains(github.event.pull_request.labels.*.name, 'npm-publish') }}
if [ "$has_label_package" == true ]; then
echo PR has package label
pr_number=${{github.event.number}}
if [ -z "$pr_number" ]; then
pr_number=${{github.event.issue.number}}
fi
echo "needsPackage=true" >> $GITHUB_OUTPUT
echo "pr=$pr_number" >> $GITHUB_OUTPUT
echo "tag=pr-$pr_number" >> $GITHUB_OUTPUT
else
echo PR does not have package label
echo "needsPackage=false" >> $GITHUB_OUTPUT
fi
fi
package:
needs: [postBuild]
name: Package
runs-on: ubuntu-20.04
timeout-minutes: 2
outputs:
packageVersion: ${{ steps.outputPackageVersion.outputs.packageVersion }}
if: needs.postBuild.outputs.needsPackage == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- name: Cache Node Modules
id: cache
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ./node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}-node-20.12.0
- run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.MS_READ_PACKAGES_GITHUB_PAT }}" >> ~/.npmrc
name: Configure Credentials For GitHub Packages
- run: npm ci
if: steps.cache.outputs.cache-hit != 'true'
working-directory: .
- run: npm version --no-git-tag-version $(node -e 'x=JSON.parse(require("fs").readFileSync("package.json", {encoding:"utf-8"})).version.split("."); x[2]="'$GITHUB_RUN_ID'"; console.log(x.join("."))' )
- run: npm version prerelease --no-git-tag-version --preid=pr-${{needs.postBuild.outputs.pr}}
if: github.ref != 'refs/heads/master'
- run: echo "packageVersion=$(node -e 'x=JSON.parse(require("fs").readFileSync("package.json", {encoding:"utf-8"})).version; console.log(x)')" >> $GITHUB_OUTPUT
id: outputPackageVersion
- name: Push tag
uses: rickstaa/action-create-tag@v1
if: github.ref == 'refs/heads/master'
with:
tag: "${{steps.outputPackageVersion.outputs.packageVersion}}"
force_push_tag: true
- name: "✏️ Generate release changelog"
id: build_changelog
uses: mobsuccess-devops/github-actions-mobsuccess@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
action: "changelog"
unreleased-tag: ${{ github.ref == 'refs/heads/master' && steps.outputPackageVersion.outputs.packageVersion || ''}}
max-releases: 10
- run: |
firstLine=$(cat << EOF
# Changelog
## Work In Progress
[pr-${{needs.postBuild.outputs.pr}}](https://github.com/$GITHUB_REPOSITORY/pull/${{needs.postBuild.outputs.pr}})
---
EOF
)
echo "$firstLine<br><br>${{ steps.build_changelog.outputs.changelog }}<br><br>-------<br><br>" | cat - README.md > temp && mv temp README.md
if: github.ref != 'refs/heads/master'
- run: echo "${{ steps.build_changelog.outputs.changelog }}<br><br>-------<br><br>" | cat - README.md > temp && mv temp README.md
if: github.ref == 'refs/heads/master'
- run: npm pack
working-directory: .
- name: Upload
uses: actions/upload-artifact@v2
with:
name: package
path: "*.tgz"
publish:
name: "Publish to GitHub Packages"
needs: [postBuild, package]
runs-on: ubuntu-20.04
timeout-minutes: 2
if: needs.postBuild.outputs.needsPackage == 'true'
steps:
- uses: actions/checkout@v4
- name: Upload
uses: actions/download-artifact@v2
with:
name: package
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
registry-url: https://npm.pkg.github.com/
scope: "@mobsuccess-devops"
- run: echo "registry=https://npm.pkg.github.com/@mobsuccess-devops" >> .npmrc
- run: npm publish $(ls *.tgz) --tag ${{needs.postBuild.outputs.tag}}
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Create a GitHub release
uses: ncipollo/release-action@v1
if: github.ref == 'refs/heads/master'
with:
tag: ${{ needs.package.outputs.packageVersion }}
prerelease: ${{github.ref != 'refs/heads/master'}}
generateReleaseNotes: true
# DO NOT EDIT: END