-
Notifications
You must be signed in to change notification settings - Fork 9
253 lines (211 loc) · 7.27 KB
/
npm-run.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
251
252
253
# Build MRjs and confirm everything passes
name: npm run
on:
workflow_dispatch:
push:
branches:
- '**' # This allows the workflow to run on all branches for the build job
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# todo - run the npm install with a dockerfile setup instead of pure
# install but not important to do right now since install isnt too long
- uses: actions/setup-node@v4
with:
node-version: 21
- name: Install Dependencies
run: |
npm install
- name: 👷 Build
run: |
npm run build
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: ./dist
- name: Archive node_modules
run: zip -r npm-artifacts.zip ./node_modules
- name: Upload Npm Artifacts
uses: actions/upload-artifact@v3
with:
name: npm-artifacts
path: ./npm-artifacts.zip
check-dist:
if: github.ref == 'refs/heads/main' # This job runs only if the current branch is main
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
token: ${{ secrets.MRJS_AND_DOCS_REPO_PAT }}
- name: remove potentially old dist
run: |
rm -rf ./dist
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./dist
- name: Check for changes
id: check_changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Changes detected. Committing and pushing."
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
commit_message=$'👷 MRjs - Auto Generated Dist 👷\n\nChanges at '"${GITHUB_SHA}"
git add .
git commit -m "$commit_message"
git -c http.extraHeader="AUTHORIZATION: basic $(echo -n x-access-token:${{ secrets.MRJS_AND_DOCS_REPO_PAT }} | base64)" push origin HEAD:main
else
echo "No changes detected. Exiting without committing."
fi
test:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 21
- name: Download Npm Artifacts
uses: actions/download-artifact@v3
with:
name: npm-artifacts
- name: extract and rebuild node_modules
run: |
unzip npm-artifacts.zip -d ./
npm rebuild
- name: remove potentially old dist
run: |
rm -rf ./dist
- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./dist
- name: 👷 Test
run: npm run test
js-api-docs:
if: github.ref == 'refs/heads/main' # This job runs only if the current branch is main
needs: [build]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
# NOTE -
#
# For local documentation or to check the local output when writing your own pr to see how it will
# update, run `npm run docs`. As a heads up, order of creation of docs depends on your operating
# system, so if when you run this the order looks different, no worries - in the repo itself our
# action will handle that for you and default to use the right version for these automatically
# generated docs.
#
# We're using mac as default for doc order generation (the order from that os makes the most sense
# from a readability perspective).
- uses: actions/setup-node@v4
with:
node-version: 21
- name: Download Npm Artifacts
uses: actions/download-artifact@v3
with:
name: npm-artifacts
- name: extract and rebuild node_modules
run: |
unzip npm-artifacts.zip -d ./
npm rebuild
- name: 👷 Write the markdown docs
run: |
npm run docs
- name: Get Docs content
id: get-docs
run: |
rm -rf ../doc
mkdir -p ../doc
cp -rf ./docs/* ../doc/
- name: see if info is there
run: |
echo "ll .."
ls -al ..
echo "ll ."
ls -al .
- name: Checkout documentation Repository
uses: actions/checkout@v4
with:
repository: Volumetrics-io/documentation
ref: main
token: ${{ secrets.MRJS_AND_DOCS_REPO_PAT }}
- name: Update Docs
run: |
rm -rf "./source/js-api*"
cp -a "../doc/js-api" "./source/"
cp -a "../doc/js-api-utils" "./source/"
cp -a "../doc/js-api-extras" "./source/"
ls -al ./source
- name: Commit only if there are changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "Changes detected. Committing and pushing."
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
commit_message=$'👷 MRjs - Auto Generated Docs 👷\n\nChanges at '"${GITHUB_SHA}"
git add .
git commit -m "$commit_message"
git push --quiet --set-upstream origin HEAD
else
echo "No changes detected. Exiting without committing."
fi
env:
GITHUB_TOKEN: ${{ secrets.MRJS_AND_DOCS_REPO_PAT }}
check-format:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 21
- name: Download Npm Artifacts
uses: actions/download-artifact@v3
with:
name: npm-artifacts
- name: extract and rebuild node_modules
run: |
unzip npm-artifacts.zip -d ./
npm rebuild
- name: 👷 Check if format is needed
run: |
# check if either need fixes
npm run prettier-check
exit_code_function_prettier=$?
npm run lint-check
exit_code_function_lint=$?
# check lint first, because it might have changed some prettier items
# if lint is successful, then check against prettier to see if there were
# any remaining problem items
#
# doing this ordering because prettier runs first and then is followed by lint
#
# this is also necessary because part of prettier and lint are in conflict atm
# but it's based on a specific formatting setting, to be resolved.
if [ $exit_code_function_lint -ne 0 ]; then
echo "Function lint encountered an error"
echo "Some files need formatting. Run 'npm run format' to format them or manually fix them as needed."
exit 1
elif [ $exit_code_function_prettier -ne 0 ]; then
echo "Function prettier encountered an error"
echo "Some files need formatting. Run 'npm run format' to format them or manually fix them as needed."
exit 1
fi
if ! npm run check-format; then
echo "Some files need formatting. Run 'npm run format' to format them or manually fix them as needed."
exit 1
fi