-
Notifications
You must be signed in to change notification settings - Fork 14
267 lines (266 loc) · 9.97 KB
/
reusable-precommit.yml
File metadata and controls
267 lines (266 loc) · 9.97 KB
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
258
259
260
261
262
263
264
265
266
267
name: Pre-commit (reusable)
on:
workflow_call:
inputs:
BATFISH_GITHUB_BATFISH_REPO:
description: "Git repo containing Batfish"
required: true
type: string
BATFISH_GITHUB_BATFISH_REF:
description: "Git ref for Batfish version to release"
required: true
type: string
BATFISH_GITHUB_PYBATFISH_REPO:
description: "Git repo containing Pybatfish"
required: true
type: string
BATFISH_GITHUB_PYBATFISH_REF:
description: "Git ref for Pybatfish version to release"
required: true
type: string
outputs:
bf_version:
description: "Batfish version string (in the format YYYY.MM.DD.####)"
value: ${{ jobs.bf_version.outputs.bf_version }}
batfish_repo:
description: "Batfish repository used for this pre-commit"
value: ${{ inputs.BATFISH_GITHUB_BATFISH_REPO }}
batfish_resolved_sha:
description: "The resolved Batfish SHA at which the release was built"
value: ${{ jobs.bf_version.outputs.bf_resolved_sha }}
pybatfish_repo:
description: "Pybatfish repository used for this pre-commit"
value: ${{ inputs.BATFISH_GITHUB_PYBATFISH_REPO }}
pybatfish_resolved_sha:
description: "The resolved pybatfish SHA at which the release was built"
value: ${{ jobs.bf_version.outputs.pybf_resolved_sha }}
jobs:
bf_version:
name: Setup Build Metadata
runs-on: ubuntu-latest
steps:
- name: Get Build ID
id: get_build_id
run: echo "build_id=$(TZ=America/Los_Angeles date +'%Y.%m.%d').${{ github.run_number }}" >> $GITHUB_OUTPUT
- name: Checkout Batfish repo
uses: actions/checkout@v6
with:
repository: "${{ inputs.BATFISH_GITHUB_BATFISH_REPO }}"
path: batfish
ref: "${{ inputs.BATFISH_GITHUB_BATFISH_REF }}"
- name: Get Batfish SHA
id: get_bf_sha
run: |
cd batfish
echo "batfish_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "batfish_resolved_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Checkout pybatfish repo
uses: actions/checkout@v6
with:
repository: "${{ inputs.BATFISH_GITHUB_PYBATFISH_REPO }}"
path: pybatfish
ref: "${{ inputs.BATFISH_GITHUB_PYBATFISH_REF }}"
- name: Get pybatfish SHA
id: get_pybf_sha
run: |
cd pybatfish
echo "pybatfish_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "pybatfish_resolved_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
outputs:
bf_version: ${{ steps.get_build_id.outputs.build_id }}
bf_sha: ${{ steps.get_bf_sha.outputs.batfish_sha }}
bf_resolved_sha: ${{ steps.get_bf_sha.outputs.batfish_resolved_sha }}
pybf_sha: ${{ steps.get_pybf_sha.outputs.pybatfish_sha }}
pybf_resolved_sha: ${{ steps.get_pybf_sha.outputs.pybatfish_resolved_sha }}
bf_build:
runs-on: ubuntu-latest
needs:
- bf_version
steps:
- name: Get date
id: date
run: echo "ymd=$(TZ=America/Los_Angeles date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Checkout Docker repo
uses: actions/checkout@v6
- name: Checkout Batfish repo
uses: actions/checkout@v6
with:
repository: "${{ inputs.BATFISH_GITHUB_BATFISH_REPO }}"
path: batfish
ref: "${{ needs.bf_version.outputs.bf_resolved_sha }}"
- name: Bazelisk cache
uses: actions/cache@v5
with:
path: "~/.cache/bazelisk"
key: ${{runner.os}}-bazelisk-${{ hashFiles('batfish/.bazelversion') }}
- name: Bazel cache
uses: actions/cache@v5
with:
path: "~/.cache/bazel"
key: ${{runner.os}}-bazel-build-${{ hashFiles('batfish/.bazelversion', 'batfish/WORKSPACE', 'batfish/maven_install.json') }}-${{ steps.date.outputs.ymd }}
restore-keys: |
${{runner.os}}-bazel-build-${{ hashFiles('batfish/.bazelversion', 'batfish/WORKSPACE', 'batfish/maven_install.json') }}-test-
${{runner.os}}-bazel-build-${{ hashFiles('batfish/.bazelversion', 'batfish/WORKSPACE', 'batfish/maven_install.json') }}-
${{runner.os}}-bazel-build-
- uses: actions/setup-java@v5
with:
distribution: "temurin"
java-version: "17"
- name: Build JAR
run: |
pushd batfish
echo -n "${{ needs.bf_version.outputs.bf_version }}" > projects/VERSION
bazel build //projects/allinone:allinone_main_deploy.jar
popd
cp batfish/bazel-bin/projects/allinone/allinone_main_deploy.jar allinone-bundle.jar
java -jar allinone-bundle.jar -version
java -jar allinone-bundle.jar -version | grep "Batfish version: ${{ needs.bf_version.outputs.bf_version }}"
- name: Questions tar
run: |
TMP_DIR=$(mktemp -d)
QUESTION_DIR=${TMP_DIR}/questions
mkdir -p ${QUESTION_DIR}
cp -r batfish/questions/{stable,experimental} ${QUESTION_DIR}
tar -czf questions.tgz -C ${TMP_DIR} questions
- name: Upload JAR
uses: actions/upload-artifact@v7
with:
name: bf_jar
path: allinone-bundle.jar
- name: Upload questions
uses: actions/upload-artifact@v7
with:
name: bf_questions
path: questions.tgz
pybf_build:
runs-on: ubuntu-latest
needs:
- bf_version
steps:
- uses: actions/checkout@v6
- name: Checkout pybf repo
uses: actions/checkout@v6
with:
repository: "${{ inputs.BATFISH_GITHUB_PYBATFISH_REPO }}"
path: pybatfish
ref: "${{ needs.bf_version.outputs.pybf_resolved_sha }}"
- name: Update version number
run: |
cd pybatfish
sed -i.bak -e "s/^__version__ = .*$/__version__ = \"${{ needs.bf_version.outputs.bf_version }}\"/" pybatfish/__init__.py
sed -i.bak -e "s/^version = .*$/version = \"${{ needs.bf_version.outputs.bf_version }}\"/" pyproject.toml
rm -f pybatfish/__init__.py.bak pyproject.toml.bak
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Build wheel
run: |
cd pybatfish
pip install --upgrade setuptools wheel build
python -m build
- name: Tar tests and notebooks
run: |
tar -czf pybatfish-tests.tgz -C pybatfish tests
tar -czf pybatfish-notebooks.tgz -C pybatfish jupyter_notebooks
- name: Upload pybf wheel
uses: actions/upload-artifact@v7
with:
name: pybf_whl
path: pybatfish/dist/*
- name: Upload tests
uses: actions/upload-artifact@v7
with:
name: pybf_tests
path: pybatfish-tests.tgz
- name: Upload notebooks
uses: actions/upload-artifact@v7
with:
name: pybf_notebooks
path: pybatfish-notebooks.tgz
image_build:
runs-on: ${{ matrix.runner }}
needs:
- bf_build
- pybf_build
- bf_version
strategy:
matrix:
include:
- runner: ubuntu-latest
bf_artifact: bf_image
allinone_artifact: allinone_image
- runner: ubuntu-24.04-arm
bf_artifact: bf_image_arm64
allinone_artifact: allinone_image_arm64
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download jar
uses: actions/download-artifact@v8
with:
name: bf_jar
- name: Download questions
uses: actions/download-artifact@v8
with:
name: bf_questions
- name: Setup Batfish image assets
run: |
mkdir assets
tar xzf questions.tgz -C assets
cp allinone-bundle.jar assets
cp log4j2.yaml assets
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Batfish image
uses: docker/build-push-action@v7
with:
push: false
file: batfish.dockerfile
build-args: ASSETS=./assets
tags: batfish/batfish:test-${{ needs.bf_version.outputs.bf_version }}
labels: |
org.batfish.batfish-tag=${{ needs.bf_version.outputs.bf_sha }}
org.batfish.batfish-version=${{ needs.bf_version.outputs.bf_version }}
outputs: type=docker,dest=/tmp/bf.tar
context: .
- name: Upload Batfish image
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.bf_artifact }}
path: /tmp/bf.tar
- name: Download pybf whl
uses: actions/download-artifact@v8
with:
name: pybf_whl
- name: Download pybf notebooks
uses: actions/download-artifact@v8
with:
name: pybf_notebooks
- name: Setup Allinone image assets
run: |
cp pybatfish-*.whl assets
TEMP_DIR=$(mktemp -d)
tar xzf pybatfish-notebooks.tgz -C ${TEMP_DIR}
cp -r ${TEMP_DIR}/jupyter_notebooks/ assets/notebooks/
# Script that starts Batfish + Jupyter server
cp wrapper.sh assets
- name: Build allinone image
uses: docker/build-push-action@v7
with:
push: false
file: allinone.dockerfile
build-args: ASSETS=./assets
tags: batfish/allinone:test-${{ needs.bf_version.outputs.bf_version }}
labels: |
org.batfish.allinone-tag=${{ needs.bf_version.outputs.bf_sha }}_${{ needs.bf_version.outputs.pybf_sha }}
org.batfish.batfish-tag=${{ needs.bf_version.outputs.bf_sha }}
org.batfish.pybatfish-tag=${{ needs.bf_version.outputs.pybf_sha }}
org.batfish.batfish-version=${{ needs.bf_version.outputs.bf_version }}
outputs: type=docker,dest=/tmp/allinone.tar
context: .
- name: Upload allinone image
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.allinone_artifact }}
path: /tmp/allinone.tar