Skip to content

Commit 9a6d44e

Browse files
Added GA workflows
1 parent 1eebaf0 commit 9a6d44e

File tree

3 files changed

+443
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)