Skip to content

Commit ee3f8ba

Browse files
Merge pull request #5 from folio-org/UIREQMED-1-github
Add GitHub
2 parents a9220ef + 569a660 commit ee3f8ba

File tree

2 files changed

+427
-0
lines changed

2 files changed

+427
-0
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# This workflow will do a clean install of node dependencies, build the source code,
2+
# run unit tests, and perform a SonarCloud scan ONLY on a `release`.
3+
4+
# For more information see:
5+
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
6+
7+
# Common FOLIO configurable env:
8+
# - YARN_TEST_OPTIONS (options to pass to 'yarn test')
9+
# - SQ_ROOT_DIR (where to scan relative to top-level directory)
10+
# - FOLIO_NAME
11+
# - PUBLISH_MOD_DESCRIPTOR (boolean 'true' or 'false')
12+
# - COMPILE_TRANSLATION_FILES (boolean 'true' or 'false')
13+
14+
15+
16+
name: buildNPM Release
17+
on:
18+
push:
19+
tags:
20+
- 'v[0-9]+.[0-9]+.[0-9]+*'
21+
workflow_dispatch:
22+
23+
jobs:
24+
build-npm-release:
25+
if : ${{ startsWith(github.ref, 'refs/tags/v') }}
26+
env:
27+
YARN_TEST_OPTIONS: '--ci --coverage --colors'
28+
SQ_ROOT_DIR: './src'
29+
PUBLISH_MOD_DESCRIPTOR: 'false'
30+
COMPILE_TRANSLATION_FILES: 'false'
31+
FOLIO_NPM_REGISTRY: 'https://repository.folio.org/repository/npm-folio/'
32+
FOLIO_NPM_REGISTRY_AUTH: '//repository.folio.org/repository/npm-folio/'
33+
FOLIO_MD_REGISTRY: 'https://folio-registry.dev.folio.org'
34+
NODEJS_VERSION: '18'
35+
JEST_JUNIT_OUTPUT_DIR: 'artifacts/jest-junit'
36+
JEST_COVERAGE_REPORT_DIR: 'artifacts/coverage-jest/lcov-report/'
37+
OKAPI_PULL: '{ "urls" : [ "https://folio-registry.dev.folio.org" ] }'
38+
SQ_LCOV_REPORT: 'artifacts/coverage-jest/lcov.info'
39+
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'
40+
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
with:
45+
fetch-depth: 0
46+
47+
# Runs a single command using the runners shell
48+
- name: Print tag info
49+
run: echo "Building release tag, ${GITHUB_REF}"
50+
51+
- name: Set TAG_VERSION
52+
run: echo "TAG_VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV
53+
54+
- name: Get version from package.json
55+
id: package_version
56+
uses: notiz-dev/github-action-json-property@release
57+
with:
58+
path: 'package.json'
59+
prop_path: 'version'
60+
61+
- name: Check matching tag and version in package.json
62+
if: ${{ env.TAG_VERSION != steps.package_version.outputs.prop }}
63+
run: |
64+
echo "Tag version, ${TAG_VERSION}, does not match package.json version, ${PACKAGE_VERSION}."
65+
exit 1
66+
env:
67+
PACKAGE_VERSION: ${{ steps.package_version.outputs.prop }}
68+
69+
- name: Setup kernel for react native, increase watchers
70+
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
71+
- name: Use Node.js
72+
uses: actions/setup-node@v3
73+
with:
74+
node-version: ${{ env.NODEJS_VERSION }}
75+
check-latest: true
76+
always-auth: true
77+
78+
- name: Set yarn config
79+
run: yarn config set @folio:registry $FOLIO_NPM_REGISTRY
80+
81+
- name: Run yarn install
82+
run: yarn install --ignore-scripts
83+
84+
- name: Run yarn list
85+
run: yarn list --pattern @folio
86+
87+
- name: Run yarn lint
88+
run: yarn lint
89+
continue-on-error: true
90+
91+
- name: Get number of CPU cores
92+
id: cpu-cores
93+
uses: SimenB/github-actions-cpu-cores@v1
94+
95+
- name: Run yarn test
96+
run: xvfb-run --server-args="-screen 0 1024x768x24" yarn test $YARN_TEST_OPTIONS --max-workers ${{ steps.cpu-cores.outputs.count }}
97+
98+
- name: Run yarn formatjs-compile
99+
if : ${{ env.COMPILE_TRANSLATION_FILES == 'true' }}
100+
run: yarn formatjs-compile
101+
102+
- name: Generate FOLIO module descriptor
103+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
104+
run: yarn build-mod-descriptor
105+
106+
- name: Print FOLIO module descriptor
107+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
108+
run: cat module-descriptor.json
109+
110+
- name: Read module descriptor
111+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
112+
id: moduleDescriptor
113+
uses: juliangruber/read-file-action@v1
114+
with:
115+
path: ./module-descriptor.json
116+
117+
- name: Docker registry login
118+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login https://docker.io/v2/ -u "${{ secrets.DOCKER_USER }}" --password-stdin
119+
120+
- name: Start a local instance of Okapi
121+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
122+
run: |
123+
docker pull folioorg/okapi:latest
124+
docker run --name okapi -t -detach folioorg/okapi:latest dev
125+
echo "OKAPI_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' okapi)" >> $GITHUB_ENV
126+
sleep 10
127+
128+
- name: Pull all Module descriptors to local Okapi instance
129+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
130+
uses: fjogeleit/http-request-action@master
131+
with:
132+
url: http://${{ env.OKAPI_IP }}:9130/_/proxy/pull/modules
133+
method: 'POST'
134+
contentType: 'application/json; charset=utf-8'
135+
customHeaders: '{ "Accept": "application/json; charset=utf-8" }'
136+
data: ${{ env.OKAPI_PULL }}
137+
timeout: 60000
138+
139+
- name: Perform local Okapi dependency check
140+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
141+
uses: fjogeleit/http-request-action@master
142+
with:
143+
url: http://${{ env.OKAPI_IP }}:9130/_/proxy/modules?preRelease=false&npmSnapshot=false
144+
method: 'POST'
145+
contentType: 'application/json; charset=utf-8'
146+
customHeaders: '{ "Accept": "application/json; charset=utf-8" }'
147+
data: ${{ steps.moduleDescriptor.outputs.content }}
148+
149+
- name: Upload event file
150+
uses: actions/upload-artifact@v3
151+
with:
152+
name: Event File
153+
path: ${{ github.event_path }}
154+
retention-days: 30
155+
156+
- name: Upload Jest results
157+
if: always()
158+
uses: actions/upload-artifact@v3
159+
with:
160+
name: jest-test-results
161+
path: ${{ env.JEST_JUNIT_OUTPUT_DIR }}/*.xml
162+
retention-days: 30
163+
164+
- name: Publish Jest coverage report
165+
uses: actions/upload-artifact@v2
166+
if: always()
167+
with:
168+
name: jest-coverage-report
169+
path: ${{ env.JEST_COVERAGE_REPORT_DIR }}
170+
retention-days: 30
171+
172+
- name: Set default branch as env variable
173+
run: echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
174+
175+
- name: Fetch branches for SonarCloud
176+
run: git fetch --no-tags ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} +refs/heads/${{ env.DEFAULT_BRANCH }}:refs/remotes/origin/${{ env.DEFAULT_BRANCH }}
177+
178+
- name: Run SonarCloud scan
179+
uses: sonarsource/sonarcloud-github-action@master
180+
with:
181+
args: >
182+
-Dsonar.organization=folio-org
183+
-Dsonar.projectKey=org.folio:${{ github.event.repository.name }}
184+
-Dsonar.projectName=${{ github.event.repository.name }}
185+
-Dsonar.sources=${{ env.SQ_ROOT_DIR }}
186+
-Dsonar.language=js
187+
-Dsonar.javascript.lcov.reportPaths=${{ env.SQ_LCOV_REPORT }}
188+
-Dsonar.exclusions=${{ env.SQ_EXCLUSIONS }}
189+
env:
190+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
191+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
192+
193+
- name: Set up NPM environment for publishing
194+
uses: actions/setup-node@v3
195+
with:
196+
node-version: ${{ env.NODEJS_VERSION }}
197+
check-latest: true
198+
always-auth: true
199+
200+
- name: Set _auth in .npmrc
201+
run: |
202+
npm config set @folio:registry $FOLIO_NPM_REGISTRY
203+
npm config set $FOLIO_NPM_REGISTRY_AUTH:_auth $NODE_AUTH_TOKEN
204+
env:
205+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
206+
207+
- name: Exclude some CI-generated artifacts in package
208+
run: |
209+
echo "artifacts" >> .npmignore
210+
echo ".github" >> .npmignore
211+
echo ".scannerwork" >> .npmignore
212+
cat .npmignore
213+
214+
- name: Publish NPM to FOLIO NPM registry
215+
run: npm publish
216+
env:
217+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
218+
219+
- name: Publish module descriptor to FOLIO registry
220+
if: ${{ env.PUBLISH_MOD_DESCRIPTOR == 'true' }}
221+
id: modDescriptorPost
222+
uses: fjogeleit/http-request-action@master
223+
with:
224+
url: ${{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules
225+
method: 'POST'
226+
contentType: 'application/json; charset=utf-8'
227+
customHeaders: '{ "Accept": "application/json; charset=utf-8" }'
228+
data: ${{ steps.moduleDescriptor.outputs.content }}
229+
username: ${{ secrets.FOLIO_REGISTRY_USERNAME }}
230+
password: ${{ secrets.FOLIO_REGISTRY_PASSWORD }}
231+

0 commit comments

Comments
 (0)