-
Notifications
You must be signed in to change notification settings - Fork 7
231 lines (214 loc) Β· 8.95 KB
/
ci.yaml
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
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023-2024 The Enola <https://enola.dev> Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: CI
on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
# https://github.com/orgs/community/discussions/25722
types: [opened, synchronize, reopened, ready_for_review]
# Cancel any in-progress job or run if there is a newer commit
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build:
# https://github.com/orgs/community/discussions/25722
if:
(github.repository == 'enola-dev/enola') &&
(github.event.pull_request.draft == false)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
# NB: Repeated below in push-container-image: job; must keep in sync!
java-version: "21"
- name: Install graphviz
# NB: We unfortunately cannot cache this, see https://github.com/enola-dev/enola/issues/823
run: sudo apt-get install -y graphviz && dot -V
shell: bash
- name: Cache Bazel
uses: actions/cache@v4
with:
# KEEP IN SYNC WITH BELOW!
# https://github.com/actions/cache/pull/575/files
path: |
~/.cache/bazel/
~/.cache/bazelisk/
/private/var/tmp/_bazel_runner/
key: >
${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: ${{ runner.os }}-bazel-
- name: Cache Python
uses: actions/cache@v4
with:
path: .venv/
key: ${{ runner.os }}-venv-${{ hashFiles('requirements.txt') }}
restore-keys: ${{ runner.os }}-venv-
- name: Cache Node.js
uses: actions/cache@v4
with:
path: ~/.npm
# -${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-npm
restore-keys: ${{ runner.os }}-npm
- name: Cache Go
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Cache Pre-Commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit/
key:
${{ runner.os }}-cache-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: ${{ runner.os }}-cache-
- name: Cache Demo
uses: actions/cache@v4
with:
path: .cache/demo/
key: ${{ runner.os }}-demo-${{ hashFiles('tools/demo/*.bash') }}
restore-keys: ${{ runner.os }}-demo-
# https://asdf-vm.com
- name: Setup ASDF itself
uses: asdf-vm/actions/setup@v3
- name: Cache ASDF
uses: actions/cache@v4
id: asdf-cache
with:
# https://github.com/asdf-vm/asdf/blob/master/.gitignore
path: |
~/.asdf/installs
~/.asdf/plugins
~/.asdf/shims
key: ${{ runner.os }}-asdf-tools-${{ hashFiles('.tool-versions') }}
restore-keys: ${{ runner.os }}-asdf-tools-
- name: Install ASDF plugins
uses: asdf-vm/actions/install@v3
# See https://github.com/asdf-vm/actions/issues/445
if: ${{ steps.asdf-cache.outputs.cache-hit != 'true' }}
with:
# Keep this asdf_branch version in sync with //tools/asdf/install.bash
asdf_branch: v0.14.0
- name: Reshim installed ASDF tools
run: asdf reshim
shell: bash
- run: ./tools/test-ci/test.bash
# Build docs/ into site/ (not just on main branch but also for pull requests, as test)
- name:
Build Docs Site (but skip [slow] screencast recording, because on PR)
if: ${{ github.event_name == 'pull_request' }}
run: ./tools/docs/build.bash --without-demo-screencasts
- name: Build Docs Site, now with Screencasts (because on branch)
if: ${{ github.event_name == 'push' }}
run: ./tools/docs/build.bash
- name: pre-commit run --all-files
run: .venv/bin/pre-commit run --all-files
# The following steps deploy site/ (using GitHub Pages)
# to https://enola-dev.github.io = https://docs.enola.dev
- name: Setup Pages
if: ${{ github.event_name == 'push' }}
uses: actions/configure-pages@v5
- name: Upload site/ directory as GitHub Pages artifact
if: ${{ github.event_name == 'push' }}
uses: actions/upload-pages-artifact@v3
with:
path: "site/"
deploy-website:
needs: build
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication
# Sets required permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# https://github.com/actions/deploy-pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action
push-container-image:
needs: build
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
# This is a separate job from 'build' only because it needs additional permissions which we don't want 'build' to have:
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
# NB: Repeated above in build: job; must keep in sync!
java-version: "21"
- name: Cache Bazel
uses: actions/cache@v4
with:
# KEEP IN SYNC WITH ABOVE!
# https://github.com/actions/cache/pull/575/files
path: |
~/.cache/bazel/
~/.cache/bazelisk/
/private/var/tmp/_bazel_runner/
key: >
${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc',
'WORKSPACE.bazel', 'MODULE.bazel') }}
restore-keys: ${{ runner.os }}-bazel-
- name: Build Container Image # again, because technically it was already built in the 'build' job, but oh well!
run: ./tools/distro/build.bash
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}