-
Notifications
You must be signed in to change notification settings - Fork 35
225 lines (198 loc) · 6.53 KB
/
ci.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: CI
on:
pull_request_target:
push:
branches:
- main
jobs:
test:
name: Test with Node v${{matrix.node}}
runs-on: ubuntu-latest
strategy:
matrix:
node: [lts/*, node]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PIPELINE_BOT_PAT }}
ref: ${{ github.head_ref || github.ref }}
repository: ${{ (
github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name
) || github.repository }}
fetch-depth: 0
- name: Use Node Version
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install Dependencies
run: |
npm i --prefer-offline --no-audit
- name: Run Lint
working-directory: packages/es-components
if: ${{ github.event_name == 'pull_request_target' }}
continue-on-error: true
run: |
npx eslint \
--output-file eslint_report.json \
--format json \
--no-error-on-unmatched-pattern \
--cache \
$(git diff origin/${{ github.base_ref }} --name-only --relative)
- name: Annotate JS Linting Results
if: ${{ github.event_name == 'pull_request_target' }}
uses: ataylorme/eslint-annotate-action@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: packages/es-components/eslint_report.json
- name: Run Tests
run: |
npm test --workspaces --if-present
npm:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [test]
name: Publish NPM Packages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PIPELINE_BOT_PAT }}
ref: main
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install Dependencies
run: |
npm i --prefer-offline --no-audit
- name: Set Commitbot Identity
run: |
git config user.name "ES-Components Lerna Publish Bot"
git config user.email "es-components-bot@wtw.org"
- name: Lerna Publish Latest
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc
npx lerna publish \
--conventional-commits \
--changelog-preset @aabenoja/conventional-changelog-eslint-lerna \
--conventional-graduate \
--yes
npm_prerelease:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [test, npm]
name: Pre-Prod Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PIPELINE_BOT_PAT }}
ref: pre-prod
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install Dependencies
run: |
npm i --prefer-offline --no-audit
- name: Set Commitbot Identity
run: |
git config user.name "ES-Components Lerna Publish Bot"
git config user.email "es-components-bot@wtw.org"
- name: Merge main to pre-prod
run: |
git merge --no-verify -Xtheirs --commit origin/main -m "Build: merging main into pre-prod"
# abort if failed merge
git merge --abort || true
git push origin pre-prod
# This is so that we always update the pre-prod dist tag with main when we merge.
# (Pre-prod can be ahead of main, but never behind.)
- name: Lerna Publish Pre-Prod
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc
npx lerna publish \
--conventional-commits \
--changelog-preset @aabenoja/conventional-changelog-eslint-lerna \
--conventional-prerelease \
--dist-tag pre-prod \
--preid pre-prod \
--allow-branch pre-prod \
--yes
docs:
if: ${{ github.ref == 'refs/heads/main' }}
needs: npm
name: Publish Docs to GH Pages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PIPELINE_BOT_PAT }}
ref: main
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'
- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install Dependencies
run: |
npm i --prefer-offline --no-audit
- name: Set Commitbot Identity
run: |
git config user.name "ES-Components Lerna Publish Bot"
git config user.email "es-components-bot@wtw.org"
- name: Rebuild docs
working-directory: packages/es-components
run: |
npm run styleguide-build
- name: Configure docs changes
run: |
git stash
git checkout gh-pages
git stash show -p | git apply && git stash drop
rm -rf build/
mv ./packages/es-components/docs/* .
git add index.html full-color-icons.html full-color-icons.js build
DIFF_RESULT=$(git diff --staged --quiet --exit-code; echo "$?")
HAS_CHANGES=$(
if [ $DIFF_RESULT -eq 0 ]
then echo "false"
else echo "true"
fi
)
echo "Has docs changes? $HAS_CHANGES"
echo "HAS_CHANGES=$HAS_CHANGES" >> $GITHUB_ENV
- name: Publish docs to github pages
if: env.HAS_CHANGES == 'true'
run: |
git commit -m "Deploy es-component docs to gh-pages"
git push origin gh-pages