-
Notifications
You must be signed in to change notification settings - Fork 1
194 lines (167 loc) · 5.62 KB
/
main.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
name: General Validity
on:
workflow_dispatch:
push:
branches: [ main ]
paths-ignore:
# Can we use '**.md' ?
- 'README.md'
- 'SECURITY.md'
- 'CODE_OF_CONDUCT.md'
- 'LICENSE'
- '.gitignore'
- '.npmignore'
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [14]
# Map a step output to a job output
outputs:
coverage: ${{ steps.coverage.outputs.coverage }}
coverage-rounded-display: ${{ steps.coverage.outputs.coverage-rounded-display }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: ${{ matrix.node }}
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --color --immutable
- name: test + coverage
run: yarn test:unit
# Coverage badges will be updated on any branch
# and saved into a dedicated one
- name: Check test coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
id: coverage
with:
percentage: 50
exit: 0
rounded-precision: 2
filename: "coverage/clover.xml"
badge:
# Only generate and publish if these conditions are met:
# - The test step ended successfully
# - One of these is met:
# - This is a pull request event and the pull actor is the same as the repo owner
# - This is a push event and the push event is on branch 'main'
needs: test
if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- name: Extract branch name
run: |
TMP_PULL_HEAD_REF="${{ github.head_ref }}"
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}"
EXPORT_VALUE=""
if [ "${TMP_PULL_HEAD_REF}" != "" ]
then
EXPORT_VALUE="${TMP_PULL_HEAD_REF}"
else
EXPORT_VALUE="${TMP_GITHUB_REF}"
fi
echo "branch=${EXPORT_VALUE}" >> "${GITHUB_OUTPUT}"
id: extract_branch
- uses: actions/checkout@v4
with:
ref: badges
# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v2.0.3
id: badge
with:
label: 'Coverage'
status: ${{ needs.test.outputs.coverage-rounded-display }}
color: ${{
needs.test.outputs.coverage > 90 && 'green' ||
needs.test.outputs.coverage > 80 && 'yellow,green' ||
needs.test.outputs.coverage > 70 && 'yellow' ||
needs.test.outputs.coverage > 60 && 'orange,yellow' ||
needs.test.outputs.coverage > 50 && 'orange' ||
needs.test.outputs.coverage > 40 && 'red,orange' ||
needs.test.outputs.coverage > 30 && 'red,red,orange' ||
needs.test.outputs.coverage > 20 && 'red,red,red,orange' ||
'red' }}
path: test-coverage.svg
- name: Commit badge
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
FILE: 'test-coverage.svg'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
mkdir -p "${BRANCH}"
mv "${FILE}" "${BRANCH}"
git add "${BRANCH}/${FILE}"
# Will give error if badge did not changed
git commit -m "Add/Update badge" || true
- name: Push badge commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
test-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --immutable
- name: test build
run: yarn test:build-test
docs:
runs-on: ubuntu-20.04
needs: [test, test-build]
if: ${{ ( github.event_name == 'pull_request' && github.event.pull_request.merged == true ) || github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --immutable
- name: generate docs
run: yarn mkdocs
- name: Deploy to GitHub Pages
if: success()
uses: crazy-max/ghaction-github-pages@v4
with:
target_branch: gh-pages
build_dir: doc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}