-
Notifications
You must be signed in to change notification settings - Fork 23
257 lines (235 loc) · 9.16 KB
/
continuous-integration.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
name: Continuous Integration
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
BAZEL_COMMAND: bazelisk
BAZEL_CACHE_FILE_MAX_SIZE: 20MB
BAZEL_CACHE_INTERMEDIATE_FILE_MAX_SIZE: 50MB
BAZEL_CACHE_PACKAGES_MAX_SIZE: 150MB
BAZEL_CACHE_COMBINED_MAX_SIZE: 600MB
BAZEL_CACHE_VERSION: v3
permissions: read-all
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Lint: Run tslint and bazel linter"
run: yarn lint
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Bazel: Copy .bazelrc to user home"
run: cp ./.github/.bazelrc ~/
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Bazel: Restore remote cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-workflow-bazel-cache
with:
key: combined
- name: "Bazel: Build"
run: yarn -s build all
timeout-minutes: 45
- name: "Bazel: Clean bazel disk cache"
if: ${{ success() || failure() }}
run: yarn -s bazel:cache clean --individualMaxSize=${{ env.BAZEL_CACHE_INTERMEDIATE_FILE_MAX_SIZE }}
- name: "Bazel: Upload cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/upload-intermediate-bazel-cache
packages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Bazel: Copy .bazelrc to user home"
run: cp ./.github/.bazelrc ~/
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Bazel: Restore remote cache"
if: ${{ success() || failure() }}
uses: actions/cache@v4
with:
path: ~/.bazel-cache/sbb-angular
key: bazel-packages-${{ env.BAZEL_CACHE_VERSION }}-${{ github.sha }}-${{ github.run_attempt }}
restore-keys: |
bazel-packages-${{ env.BAZEL_CACHE_VERSION }}-${{ github.sha }}-
bazel-packages-${{ env.BAZEL_CACHE_VERSION }}-
- name: "Bazel: Build packages"
run: yarn -s build packages
- name: "Bazel: Clean bazel disk cache"
if: ${{ success() || failure() }}
run: yarn -s bazel:cache clean --maxSize=${{ env.BAZEL_CACHE_PACKAGES_MAX_SIZE }}
integrity:
runs-on: ubuntu-latest
needs: packages
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Bazel: Restore remote cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-workflow-bazel-cache
with:
key: packages
- name: "Integrity: Verify workspace integrity"
run: yarn integrity
- name: "Integrity: Assert no changes (run `yarn integrity` if this fails)"
run: git diff --exit-code
test:
if: ${{ success() || failure() }}
needs: build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Bazel: Copy .bazelrc to user home"
run: cp ./.github/.bazelrc ~/
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Bazel: Download cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-intermediate-bazel-cache
- name: "Bazel: Run local tests"
run: bazelisk test src/... --build_tag_filters=-e2e --test_tag_filters=-e2e --build_tests_only
- name: "Bazel: Clean bazel disk cache"
if: ${{ success() || failure() }}
run: yarn -s bazel:cache clean --individualMaxSize=${{ env.BAZEL_CACHE_INTERMEDIATE_FILE_MAX_SIZE }}
- name: "Bazel: Upload cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/upload-intermediate-bazel-cache
with:
key: bazel-cache-test
showcase:
if: ${{ success() || failure() }}
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Bazel: Copy .bazelrc to user home"
run: cp ./.github/.bazelrc ~/
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: "Yarn: Install"
uses: ./.github/actions/yarn-install
- name: "Bazel: Download cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-intermediate-bazel-cache
- name: "Bazel: Build showcase"
if: ${{ success() || failure() }}
run: yarn -s build showcase
env:
JM_API_KEY: ${{ secrets.JM_API_KEY }}
- name: "Bazel: Clean bazel disk cache"
if: ${{ success() || failure() }}
run: yarn -s bazel:cache clean --individualMaxSize=${{ env.BAZEL_CACHE_INTERMEDIATE_FILE_MAX_SIZE }}
- name: "Bazel: Upload cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/upload-intermediate-bazel-cache
with:
key: bazel-cache-showcase
- name: "Deploy: Insert JM_API_KEY"
run: sed -i "s|</head>|<script>window.JM_API_KEY='$JM_API_KEY'</script></head>|" dist/releases/showcase/index.html
env:
JM_API_KEY: ${{ secrets.JM_API_KEY }}
- name: "Deploy: Pack showcase"
run: mv $(npm pack ./dist/releases/showcase | tail -n 1) sbb-esta-angular-showcase.tgz
- name: "Artifact: Upload showcase merge artifact for pull request"
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: showcase-artifact-${{ github.event.number }}
path: sbb-esta-angular-showcase.tgz
- name: "Artifact: Upload showcase merge artifact for main branch"
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: showcase-artifact-main
path: sbb-esta-angular-showcase.tgz
publish-showcase:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: showcase
runs-on: ubuntu-latest
permissions:
packages: write
env:
IMAGE_REPO: ghcr.io/${{ github.repository }}/showcase-preview
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Download showcase artifact"
uses: actions/download-artifact@v4
with:
name: showcase-artifact-main
- name: Unpack and prepare showcase file
run: |
tar -xvzf sbb-esta-angular-showcase.tgz
mkdir -p dist/releases
mv package/ dist/releases/showcase/
- name: Create and publish container image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker build --tag $IMAGE_REPO:rev-main .
docker push $IMAGE_REPO:rev-main
env:
DOCKER_BUILDKIT: 1
merge-caches:
if: ${{ success() || failure() }}
needs: [test, showcase]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- uses: actions/github-script@v7
with:
# Since we don't want to install the full package dependencies, we remove all dependencies that we don't need.
# We do this in order to reduce the time needed for this job.
script: |
const fs = require('fs');
let { name, version, devDependencies, scripts } = require('./package.json');
const packages = ['@actions/cache', '@types/node', 'ts-node', 'typescript'];
devDependencies = packages.reduce((deps, dep) => Object.assign(deps, { [dep]: devDependencies[dep] }), {});
scripts = { 'bazel:cache': scripts['bazel:cache'] };
fs.writeFileSync('./package.json', JSON.stringify({ name, version, devDependencies, scripts }), 'utf8');
- name: "Yarn: Install reduced dependencies"
run: yarn install --non-interactive
- name: "Bazel: Create cache directory"
run: mkdir -p ~/.bazel-cache/
- name: "Bazel: Download test cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-intermediate-bazel-cache
with:
key: bazel-cache-test
- name: "Bazel: Download showcase cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/download-intermediate-bazel-cache
with:
key: bazel-cache-showcase
- name: "Bazel: Clean bazel disk cache"
if: ${{ success() || failure() }}
run: yarn -s bazel:cache clean --maxSize=${{ env.BAZEL_CACHE_COMBINED_MAX_SIZE }} --individualMaxSize=${{ env.BAZEL_CACHE_FILE_MAX_SIZE }}
- name: "Bazel: Upload remote cache"
if: ${{ success() || failure() }}
uses: ./.github/actions/upload-workflow-bazel-cache
with:
key: combined