Skip to content

Commit fe83b81

Browse files
feat: addition ci.yml for semantic-release
1 parent 52fa9c0 commit fe83b81

File tree

1 file changed

+271
-0
lines changed

1 file changed

+271
-0
lines changed

.github/workflow/ci.yml

+271
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# https://github.com/emibcn/covid/blob/master/.github/workflows/node.js.yml
2+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
3+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
4+
5+
name: Verification
6+
7+
on:
8+
push:
9+
branches: [master]
10+
paths-ignore:
11+
- '**.md'
12+
13+
pull_request:
14+
branches: [master]
15+
16+
jobs:
17+
check-secrets:
18+
timeout-minutes: 5
19+
runs-on: ubuntu-latest
20+
outputs:
21+
github-token: ${{ steps.github-token.outputs.defined }}
22+
steps:
23+
- id: github-token
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
if: "${{ env.GITHUB_TOKEN != '' }}"
27+
run: echo "::set-output name=defined::true"
28+
29+
pre_ci:
30+
name: Prepare CI environment
31+
timeout-minutes: 5
32+
runs-on: ubuntu-latest
33+
outputs:
34+
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
35+
branch: ${{ steps.extract_branch.outputs.branch }}
36+
37+
steps:
38+
- name: Checkout Project
39+
uses: actions/checkout@v2
40+
with:
41+
# We need to fetch with a depth of 2 for pull_request so we can do HEAD^2
42+
fetch-depth: 2
43+
44+
- name: 'Get commit message'
45+
id: get_commit_message
46+
env:
47+
COMMIT_PUSH: ${{ github.event.head_commit.message }}
48+
run: |
49+
COMMIT_MESSAGE="${COMMIT_PUSH:-$(git log --format=%B -n 1 HEAD^2)}"
50+
echo "::set-output name=commit_message::${COMMIT_MESSAGE}"
51+
- name: Extract branch name
52+
id: extract_branch
53+
run: |
54+
TMP_PULL_HEAD_REF="${{ github.head_ref }}"
55+
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}"
56+
EXPORT_VALUE=""
57+
if [ "${TMP_PULL_HEAD_REF}" != "" ]
58+
then
59+
EXPORT_VALUE="${TMP_PULL_HEAD_REF}"
60+
else
61+
EXPORT_VALUE="${TMP_GITHUB_REF}"
62+
fi
63+
echo "##[set-output name=branch;]${EXPORT_VALUE}"
64+
pre-tests:
65+
name: Install dependencies (if needed)
66+
runs-on: ubuntu-latest
67+
timeout-minutes: 5
68+
steps:
69+
- uses: actions/checkout@v2
70+
- uses: actions/setup-node@v1
71+
with:
72+
node-version: 16
73+
74+
- name: Manage cache
75+
uses: actions/[email protected]
76+
with:
77+
path: |
78+
./node_modules
79+
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/*.yml') }}
80+
restore-keys: |
81+
${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
82+
${{ runner.OS }}-build
83+
- name: npm install
84+
run: npm ci
85+
86+
test-build:
87+
needs: [pre-tests]
88+
name: Build
89+
timeout-minutes: 5
90+
runs-on: ubuntu-latest
91+
92+
steps:
93+
- uses: actions/checkout@v2
94+
- uses: actions/setup-node@v1
95+
with:
96+
node-version: 16
97+
98+
- name: Manage cache
99+
uses: actions/[email protected]
100+
with:
101+
path: |
102+
./node_modules
103+
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/*.yml') }}
104+
restore-keys: |
105+
${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
106+
${{ runner.OS }}-build
107+
- name: npm build
108+
run: npm run build
109+
110+
test-code:
111+
timeout-minutes: 5
112+
needs: [check-secrets, pre-tests]
113+
name: Test code and generate test coverage value
114+
runs-on: ubuntu-latest
115+
116+
# Map a step output to a job output
117+
outputs:
118+
coverage: ${{ steps.coverage.outputs.coverage }}
119+
coverage-rounded-display: ${{ steps.coverage.outputs.coverage-rounded-display }}
120+
121+
steps:
122+
- uses: actions/checkout@v2
123+
- uses: actions/setup-node@v1
124+
with:
125+
node-version: 16
126+
127+
- name: Manage cache
128+
uses: actions/[email protected]
129+
with:
130+
path: |
131+
./node_modules
132+
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/*.yml') }}
133+
restore-keys: |
134+
${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
135+
${{ runner.OS }}-build
136+
- name: npm test
137+
run: npm run test:coverage:color
138+
139+
# Coverage badges will be updated on any branch
140+
# and saved into a dedicated one
141+
- name: Check test coverage
142+
uses: johanvanhelden/gha-clover-test-coverage-check@v1
143+
id: coverage
144+
with:
145+
percentage: 50
146+
exit: 0
147+
rounded-precision: 2
148+
filename: './coverage/clover.xml'
149+
150+
test-lint:
151+
timeout-minutes: 5
152+
needs: [pre-tests]
153+
name: Lint
154+
runs-on: ubuntu-latest
155+
156+
steps:
157+
- uses: actions/checkout@v2
158+
- uses: actions/setup-node@v1
159+
with:
160+
node-version: 16
161+
162+
- name: Manage cache
163+
uses: actions/[email protected]
164+
with:
165+
path: |
166+
./node_modules
167+
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/*.yml') }}
168+
restore-keys: |
169+
${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
170+
${{ runner.OS }}-build
171+
- name: Get lint results
172+
run: npm run lint
173+
174+
test:
175+
timeout-minutes: 5
176+
name: Tests waiter
177+
# No need to wait for deepsource test and report
178+
needs: [test-code, test-build, test-lint]
179+
runs-on: ubuntu-latest
180+
outputs:
181+
coverage: ${{ needs.test-code.outputs.coverage }}
182+
coverage-rounded-display: ${{ needs.test-code.outputs.coverage-rounded-display }}
183+
steps:
184+
- name: Check test coverage
185+
env:
186+
COVERAGE: ${{ needs.test-code.outputs.coverage }}
187+
COVERAGE_ROUNDED: ${{ needs.test-code.outputs.coverage-rounded-display }}
188+
run: |
189+
echo "Coverage: ${COVERAGE}"
190+
echo "Coverage Rounded: ${COVERAGE_ROUNDED}"
191+
comment_pr:
192+
timeout-minutes: 5
193+
name: Comment on PR with test coverage value
194+
needs: [test, pre_ci]
195+
if: ${{ github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && !contains(needs.pre_ci.outputs.commit_message, '#comment-badge') }}
196+
197+
runs-on: ubuntu-latest
198+
199+
steps:
200+
- name: Generate comment file with test coverage
201+
env:
202+
COVERAGE: ${{ needs.test.outputs.coverage-rounded-display }}
203+
run: |
204+
echo "**Test coverage: ${COVERAGE}**" > output.md
205+
- name: Comment PR with test coverage
206+
uses: machine-learning-apps/[email protected]
207+
env:
208+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209+
with:
210+
path: output.md
211+
212+
publish:
213+
name: Publish a new version of package via Semantic Release
214+
needs: [test, pre_ci]
215+
timeout-minutes: 5
216+
if: ${{ github.ref == 'refs/heads/master' }}
217+
218+
runs-on: ubuntu-latest
219+
220+
steps:
221+
- uses: actions/checkout@v2
222+
- uses: actions/setup-node@v1
223+
with:
224+
node-version: 16
225+
226+
- name: Manage cache
227+
uses: actions/[email protected]
228+
with:
229+
path: |
230+
./node_modules
231+
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.github/workflows/*.yml') }}
232+
restore-keys: |
233+
${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
234+
${{ runner.OS }}-build
235+
- name: Prepare token
236+
run: echo "//npm.pkg.github.com/:_authToken=${GH_TOKEN}" >> .npmrc
237+
env:
238+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
239+
240+
- name: Build project
241+
run: npm run build
242+
243+
- name: Semantic release
244+
env:
245+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
246+
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
247+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
248+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
249+
run: npx semantic-release
250+
251+
comment_pr_badge:
252+
timeout-minutes: 5
253+
name: Comment on PR with generated badge
254+
needs: [pre_ci, badge]
255+
if: ${{ github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && !contains(needs.pre_ci.outputs.commit_message, '#comment-badge') }}
256+
257+
runs-on: ubuntu-latest
258+
259+
steps:
260+
- name: Generate comment file with test coverage badge
261+
env:
262+
BADGE: ${{ needs.badge.outputs.markdown }}
263+
run: |
264+
echo "Badge: ${BADGE}"
265+
echo "${BADGE}" > output.md
266+
- name: Comment PR with test coverage badge
267+
uses: machine-learning-apps/[email protected]
268+
env:
269+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
270+
with:
271+
path: output.md

0 commit comments

Comments
 (0)