Skip to content

Commit 2172b33

Browse files
authored
Use TAG to set build sha, use HANDLE to set latest / PR handle (#36)
* Use TAG to set build sha, use HANDLE to set latest / PR handle * Use hyphen, not equals * Use github.sha, not github.ref * Actually, use Head sha on PR, sha on main
1 parent 8306222 commit 2172b33

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
VERSION: ${{ matrix.version }}
6969
TARGET: python_${VERSION//./_}
7070
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
71-
GITHUB_SHA: ${{ github.sha }}
71+
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
7272
steps:
7373
- uses: actions/checkout@v3
7474
- name: Install Task
@@ -118,7 +118,7 @@ jobs:
118118
env:
119119
VERSION: ${{ matrix.version }}
120120
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
121-
GITHUB_SHA: ${{ github.ref }}
121+
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
122122
steps:
123123
- uses: actions/checkout@v3
124124
- name: Install Task
@@ -156,7 +156,7 @@ jobs:
156156
env:
157157
VERSION: ${{ matrix.version }}
158158
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
159-
GITHUB_SHA: ${{ github.ref }}
159+
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
160160
steps:
161161
- uses: actions/checkout@v3
162162
- name: Install Task

docker-bake.hcl

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
# Environment variable for configuring
66
# the ":$tag" for build Docker images
7+
variable "HANDLE" {
8+
default = ""
9+
}
10+
711
variable "TAG" {
8-
default = "latest"
12+
default = ""
913
}
1014

1115
# Github SHA, which is used for the revision label
@@ -143,7 +147,8 @@ target "python_base_3_9" {
143147
inherits = ["base"]
144148
context = "python/base/3.9"
145149
tags = [
146-
"ghcr.io/noteable-io/kernel-python-3.9-base:${TAG}"
150+
"ghcr.io/noteable-io/kernel-python-3.9-base:${TAG}",
151+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.9-base:${HANDLE}" : ""
147152
]
148153
}
149154

@@ -152,7 +157,8 @@ target "python_base_3_10" {
152157
inherits = ["base"]
153158
context = "python/base/3.10"
154159
tags = [
155-
"ghcr.io/noteable-io/kernel-python-3.10-base:${TAG}"
160+
"ghcr.io/noteable-io/kernel-python-3.10-base:${TAG}",
161+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.10-base:${HANDLE}" : ""
156162
]
157163
}
158164

@@ -161,7 +167,8 @@ target "python_base_3_11" {
161167
inherits = ["base"]
162168
context = "python/base/3.11"
163169
tags = [
164-
"ghcr.io/noteable-io/kernel-python-3.11-base:${TAG}"
170+
"ghcr.io/noteable-io/kernel-python-3.11-base:${TAG}",
171+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.11-base:${HANDLE}" : ""
165172
]
166173
}
167174

@@ -172,7 +179,8 @@ target "python_base_3_9_gpu" {
172179
base = "target:python_base_3_9"
173180
}
174181
tags = [
175-
"ghcr.io/noteable-io/kernel-gpu-python-3.9-base:${TAG}"
182+
"ghcr.io/noteable-io/kernel-gpu-python-3.9-base:${TAG}",
183+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.9-base:${HANDLE}" : ""
176184
]
177185
}
178186

@@ -183,7 +191,8 @@ target "python_base_3_10_gpu" {
183191
base = "target:python_base_3_10"
184192
}
185193
tags = [
186-
"ghcr.io/noteable-io/kernel-gpu-python-3.10-base:${TAG}"
194+
"ghcr.io/noteable-io/kernel-gpu-python-3.10-base:${TAG}",
195+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.10-base:${HANDLE}" : ""
187196
]
188197
}
189198

@@ -194,7 +203,8 @@ target "python_base_3_11_gpu" {
194203
base = "target:python_base_3_11"
195204
}
196205
tags = [
197-
"ghcr.io/noteable-io/kernel-gpu-python-3.11-base:${TAG}"
206+
"ghcr.io/noteable-io/kernel-gpu-python-3.11-base:${TAG}",
207+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.11-base:${HANDLE}" : ""
198208
]
199209
}
200210

@@ -206,7 +216,8 @@ target "python_noteable_3_9" {
206216
}
207217
target = "main"
208218
tags = [
209-
"ghcr.io/noteable-io/kernel-python-3.9-noteable:${TAG}"
219+
"ghcr.io/noteable-io/kernel-python-3.9-noteable:${TAG}",
220+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.9-noteable:${HANDLE}" : ""
210221
]
211222
}
212223

@@ -218,7 +229,8 @@ target "python_noteable_3_10" {
218229
}
219230
target = "main"
220231
tags = [
221-
"ghcr.io/noteable-io/kernel-python-3.10-noteable:${TAG}"
232+
"ghcr.io/noteable-io/kernel-python-3.10-noteable:${TAG}",
233+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.10-noteable:${HANDLE}" : ""
222234
]
223235
}
224236

@@ -230,7 +242,8 @@ target "python_noteable_3_9_gpu" {
230242
}
231243
target = "gpu"
232244
tags = [
233-
"ghcr.io/noteable-io/kernel-gpu-python-3.9-noteable:${TAG}"
245+
"ghcr.io/noteable-io/kernel-gpu-python-3.9-noteable:${TAG}",
246+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.9-noteable:${HANDLE}" : ""
234247
]
235248
}
236249

@@ -242,7 +255,8 @@ target "python_noteable_3_10_gpu" {
242255
}
243256
target = "gpu"
244257
tags = [
245-
"ghcr.io/noteable-io/kernel-gpu-python-3.10-noteable:${TAG}"
258+
"ghcr.io/noteable-io/kernel-gpu-python-3.10-noteable:${TAG}",
259+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.10-noteable:${HANDLE}" : ""
246260
]
247261
}
248262

@@ -254,7 +268,8 @@ target "python_datascience_3_9" {
254268
}
255269
target = "main"
256270
tags = [
257-
"ghcr.io/noteable-io/kernel-python-3.9-datascience:${TAG}"
271+
"ghcr.io/noteable-io/kernel-python-3.9-datascience:${TAG}",
272+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.9-datascience:${HANDLE}" : ""
258273
]
259274
}
260275

@@ -266,7 +281,8 @@ target "python_datascience_3_10" {
266281
}
267282
target = "main"
268283
tags = [
269-
"ghcr.io/noteable-io/kernel-python-3.10-datascience:${TAG}"
284+
"ghcr.io/noteable-io/kernel-python-3.10-datascience:${TAG}",
285+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.10-datascience:${HANDLE}" : ""
270286
]
271287
}
272288

@@ -278,7 +294,8 @@ target "python_datascience_3_11" {
278294
}
279295
target = "main"
280296
tags = [
281-
"ghcr.io/noteable-io/kernel-python-3.11-datascience:${TAG}"
297+
"ghcr.io/noteable-io/kernel-python-3.11-datascience:${TAG}",
298+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-python-3.11-datascience:${HANDLE}" : ""
282299
]
283300
}
284301

@@ -290,7 +307,8 @@ target "python_datascience_3_9_gpu" {
290307
}
291308
target = "gpu"
292309
tags = [
293-
"ghcr.io/noteable-io/kernel-gpu-python-3.9-datascience:${TAG}"
310+
"ghcr.io/noteable-io/kernel-gpu-python-3.9-datascience:${TAG}",
311+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.9-datascience:${HANDLE}" : ""
294312
]
295313
}
296314

@@ -302,7 +320,8 @@ target "python_datascience_3_10_gpu" {
302320
}
303321
target = "gpu"
304322
tags = [
305-
"ghcr.io/noteable-io/kernel-gpu-python-3.10-datascience:${TAG}"
323+
"ghcr.io/noteable-io/kernel-gpu-python-3.10-datascience:${TAG}",
324+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.10-datascience:${HANDLE}" : ""
306325
]
307326
}
308327

@@ -314,7 +333,8 @@ target "python_datascience_3_11_gpu" {
314333
}
315334
target = "gpu"
316335
tags = [
317-
"ghcr.io/noteable-io/kernel-gpu-python-3.11-datascience:${TAG}"
336+
"ghcr.io/noteable-io/kernel-gpu-python-3.11-datascience:${TAG}",
337+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-gpu-python-3.11-datascience:${HANDLE}" : ""
318338
]
319339
}
320340

@@ -323,7 +343,8 @@ target "rlang_base_4_3_0" {
323343
inherits = ["base"]
324344
context = "r/base/4.3.0"
325345
tags = [
326-
"ghcr.io/noteable-io/kernel-r-4.3.0-base:${TAG}"
346+
"ghcr.io/noteable-io/kernel-r-4.3.0-base:${TAG}",
347+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-r-4.3.0-base:${HANDLE}" : ""
327348
]
328349
}
329350

@@ -335,7 +356,8 @@ target "rlang_datascience_4_3_0" {
335356
}
336357
target = "main"
337358
tags = [
338-
"ghcr.io/noteable-io/kernel-r-4.3.0-datascience:${TAG}"
359+
"ghcr.io/noteable-io/kernel-r-4.3.0-datascience:${TAG}",
360+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-r-4.3.0-datascience:${HANDLE}" : ""
339361
]
340362
}
341363

@@ -347,7 +369,8 @@ target "rlang_noteable_4_3_0" {
347369
}
348370
target = "main"
349371
tags = [
350-
"ghcr.io/noteable-io/kernel-r-4.3.0-noteable:${TAG}"
372+
"ghcr.io/noteable-io/kernel-r-4.3.0-noteable:${TAG}",
373+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-r-4.3.0-noteable:${HANDLE}" : ""
351374
]
352375
}
353376

@@ -356,6 +379,7 @@ target "rust_base_1_70_0" {
356379
inherits = ["base"]
357380
context = "rust/base/1.70"
358381
tags = [
359-
"ghcr.io/noteable-io/kernel-rust-1.70-base:${TAG}"
382+
"ghcr.io/noteable-io/kernel-rust-1.70-base:${TAG}",
383+
notequal("", HANDLE) ? "ghcr.io/noteable-io/kernel-rust-1.70-base:${HANDLE}" : ""
360384
]
361385
}

scripts/set-variables.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ PR_NUMBER=${3:-0}
1515
TIMESTAMP=$(date)
1616

1717
if [[ "${REF}" == "main" ]]; then
18-
tag="latest"
18+
echo "HANDLE=latest" >> "${GITHUB_ENV}"
1919
elif [[ "${EVENT}" == "pull_request" ]]; then
20-
tag="pr-${PR_NUMBER}"
21-
else
22-
tag="${REF}"
20+
echo "HANDLE=pr-${PR_NUMBER}" >> "${GITHUB_ENV}"
2321
fi
24-
25-
echo "TAG=${tag}" >> "${GITHUB_ENV}"
22+
echo "TAG=${GITHUB_SHA}" >> "${GITHUB_ENV}"
2623
echo "TIMESTAMP=${TIMESTAMP}" >> "${GITHUB_ENV}"

0 commit comments

Comments
 (0)