-
Notifications
You must be signed in to change notification settings - Fork 26
201 lines (169 loc) · 7.8 KB
/
build-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
#
# This workflow will do a clean install of node dependencies, build the source code,
# run unit tests, perform a Sonarqube scan, and publish NPM artifacts from master/main.
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
# Common FOLIO configurable environment variables to set:
# - YARN_TEST_OPTIONS (options to pass to 'yarn test')
# - SQ_ROOT_DIR (root SQ directory to scan relative to top-level directory)
# - PUBLISH_MOD_DESCRIPTOR (boolean 'true' or 'false')
# - COMPILE_TRANSLATION_FILES (boolean 'true' or 'false')
name: buildNPM Snapshot
on: [push, pull_request]
jobs:
build-npm:
env:
YARN_TEST_OPTIONS: '--karma.singleRun --karma.browsers ChromeDocker --karma.reporters mocha junit --coverage'
SQ_ROOT_DIR: './src'
COMPILE_TRANSLATION_FILES: 'true'
PUBLISH_MOD_DESCRIPTOR: 'true'
FOLIO_NPM_REGISTRY: 'https://repository.folio.org/repository/npm-folioci/'
FOLIO_MD_REGISTRY: 'https://folio-registry.dev.folio.org'
NODEJS_VERSION: '18'
JEST_JUNIT_OUTPUT_DIR: 'artifacts/jest-junit'
JEST_COVERAGE_REPORT_DIR: 'artifacts/coverage-jest/lcov-report/'
BIGTEST_JUNIT_OUTPUT_DIR: 'artifacts/runTest'
BIGTEST_COVERAGE_REPORT_DIR: 'artifacts/coverage/lcov-report/'
SQ_LCOV_REPORT: 'artifacts/coverage-jest/lcov.info'
SQ_EXCLUSIONS: '**/platform/alias-service.js,**/docs/**,**/node_modules/**,**/examples/**,**/artifacts/**,**/ci/**,Jenkinsfile,**/LICENSE,**/*.css,**/*.md,**/*.json,**/tests/**,**/stories/*.js,**/test/**,**/.stories.js,**/resources/bigtest/interactors/**,**/resources/bigtest/network/**,**/*-test.js,**/*.test.js,**/*-spec.js,**/karma.conf.js,**/jest.config.js'
runs-on: ubuntu-latest
steps:
- uses: folio-org/checkout@v2
with:
fetch-depth: 0
- name: Setup kernel for react native, increase watchers
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODEJS_VERSION }}
check-latest: true
always-auth: true
- name: Set yarn config
run: yarn config set @folio:registry $FOLIO_NPM_REGISTRY
- name: Set FOLIO NPM snapshot version
run: |
git clone https://github.com/folio-org/folio-tools.git
npm --no-git-tag-version version `folio-tools/github-actions-scripts/folioci_npmver.sh`
rm -rf folio-tools
env:
JOB_ID: ${{ github.run_number }}
- name: Run yarn install
run: yarn install --ignore-scripts
- name: Run yarn list
run: yarn list --pattern @folio
- name: Run yarn lint
run: yarn lint
continue-on-error: true
- name: Run yarn formatjs-compile
if : ${{ env.COMPILE_TRANSLATION_FILES == 'true' }}
run: yarn formatjs-compile
- name: Run yarn test
run: xvfb-run --server-args="-screen 0 1024x768x24" yarn test $YARN_TEST_OPTIONS
- name: Generate FOLIO module descriptor
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
run: yarn build-mod-descriptor
- name: Print FOLIO module descriptor
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
run: cat module-descriptor.json
- name: Publish Jest unit test results
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1
if: always()
with:
github_token: ${{ github.token }}
files: "${{ env.JEST_JUNIT_OUTPUT_DIR }}/*.xml"
check_name: Jest Unit Test Results
comment_mode: update last
comment_title: Jest Unit Test Statistics
- name: Publish Jest coverage report
uses: actions/upload-artifact@v2
if: always()
with:
name: jest-coverage-report
path: ${{ env.JEST_COVERAGE_REPORT_DIR }}
retention-days: 30
- name: Publish BigTest unit test results
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1
if: always()
with:
github_token: ${{ github.token }}
files: "${{ env.BIGTEST_JUNIT_OUTPUT_DIR }}/*.xml"
check_name: BigTest Unit Test Results
comment_mode: update last
comment_title: BigTest Unit Test Statistics
- name: Publish BigTest coverage report
uses: actions/upload-artifact@v2
if: always()
with:
name: bigtest-coverage-report
path: ${{ env.BIGTEST_COVERAGE_REPORT_DIR }}
retention-days: 30
- name: Publish yarn.lock
uses: actions/upload-artifact@v2
if: failure()
with:
name: yarn.lock
path: yarn.lock
retention-days: 5
- name: Set default branch as env variable
run: echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
- name: Fetch branches for SonarCloud
run: git fetch --no-tags ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} +refs/heads/${{ env.DEFAULT_BRANCH }}:refs/remotes/origin/${{ env.DEFAULT_BRANCH }}
- name: Run SonarCloud scan
uses: sonarsource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=folio-org
-Dsonar.projectKey=org.folio:${{ github.event.repository.name }}
-Dsonar.projectName=${{ github.event.repository.name }}
-Dsonar.sources=${{ env.SQ_ROOT_DIR }}
-Dsonar.language=js
-Dsonar.javascript.lcov.reportPaths=${{ env.SQ_LCOV_REPORT }}
-Dsonar.exclusions=${{ env.SQ_EXCLUSIONS }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Set up NPM environment for publishing
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODEJS_VERSION }}
check-latest: true
always-auth: true
- name: Set _auth in .npmrc
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: |
npm config set @folio:registry $FOLIO_NPM_REGISTRY
npm config set //repository.folio.org/repository/npm-folioci/:_auth $NODE_AUTH_TOKEN
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Exclude some CI-generated artifacts in package
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: |
echo "artifacts" >> .npmignore
echo ".github" >> .npmignore
echo ".scannerwork" >> .npmignore
cat .npmignore
- name: Publish NPM
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Read module descriptor
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' && github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
id: moduleDescriptor
uses: juliangruber/read-file-action@v1
with:
path: ./module-descriptor.json
- name: Publish module descriptor
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' && github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
id: modDescriptorPost
uses: fjogeleit/http-request-action@master
with:
url: ${{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules
method: 'POST'
contentType: 'application/json; charset=utf-8'
customHeaders: '{ "Accept": "application/json; charset=utf-8" }'
data: ${{ steps.moduleDescriptor.outputs.content }}
username: ${{ secrets.FOLIO_REGISTRY_USERNAME }}
password: ${{ secrets.FOLIO_REGISTRY_PASSWORD }}