-
Notifications
You must be signed in to change notification settings - Fork 95
257 lines (235 loc) · 9.71 KB
/
build.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Inspired from https://github.com/backstage/backstage/blob/master/.github/workflows/ci.yml. Thanks!
# See ci.yml for info on `quality` and `tests` stages
name: Build
on:
workflow_dispatch:
push:
branches:
- develop
paths:
- "packages/**"
- ".github/workflows/build.yml"
defaults:
run:
shell: bash
jobs:
quality:
strategy:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of ci.yml's snippet)
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
# TODO: make dev & test work without having to build everything (inspiration: https://github.com/Izhaki/mono.ts)
- name: build
run: yarn build
- name: format
run: yarn format
- name: lint
run: yarn lint
tests:
needs: quality
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version:
- 20.x # Active LTS (https://github.com/nodejs/release)
- 18.x # Maintenance LTS
exclude: # these cases are tested after the release with E2E tests
- os: windows-latest
node-version: 18.x
- os: windows-latest
node-version: 18.x
- os: macos-latest
node-version: 18.x
- os: macos-latest
node-version: 18.x
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # fetch all history to make Jest snapshot tests work
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of ci.yml's snippet)
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
# We have to build all the packages before the tests
# Because init-log4brains's integration tests use @log4brains/cli, which uses @log4brains/core
# TODO: we should separate tests that require built packages of the others, to get a quicker feedback
# Once it's done, we should add "yarn test" in each package's preVersion script
- name: build
run: |
yarn build
yarn link-cli
echo "$(yarn global bin)" >> $GITHUB_PATH
- name: typescript checks
run: yarn typescript
- name: test
run: yarn test
- name: E2E tests
run: yarn e2e
publish-pages:
needs: tests
strategy:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # required by JamesIves/github-pages-deploy-action
fetch-depth: 0 # required by Log4brains to work correctly (needs the whole Git history)
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of ci.yml's snippet)
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
- name: build
run: |
yarn build
yarn link-cli
echo "$(yarn global bin)" >> $GITHUB_PATH
- name: build self knowledge base
env:
HIDE_LOG4BRAINS_VERSION: "1" # TODO: use lerna to bump the version temporarily here so we don't have to hide it
run: log4brains build --basePath /${GITHUB_REPOSITORY#*/}/adr
- name: publish self knowledge base
uses: JamesIves/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: .log4brains/out
TARGET_FOLDER: adr
release:
needs: publish-pages # we could perform this step in parallel but this acts as a last end-to-end test before releasing
strategy:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all history for Lerna (https://stackoverflow.com/a/60184319/9285308)
ssh-key: ${{ secrets.LERNA_GITHUB_DEPLOY_KEY }} # so that Lerna is able to push to the protected branch (https://github.com/orgs/community/discussions/25305#discussioncomment-10728028)
- name: fetch all git tags for Lerna # (https://stackoverflow.com/a/60184319/9285308)
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
# Beginning of yarn setup [KEEP IN SYNC BETWEEN ALL WORKFLOWS] (copy/paste of ci.yml's snippet)
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: cache global yarn cache
uses: actions/cache@v2
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
if: steps.cache-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
# End of yarn setup
- name: build
run: yarn build
- name: git identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: release and publish to NPM
run: yarn lerna publish --yes --conventional-commits --conventional-prerelease --force-publish --dist-tag alpha --exact --create-release github
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}