Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
355 lines (320 loc) · 12.6 KB
/
Copy pathaction.yml
File metadata and controls
355 lines (320 loc) · 12.6 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
name: Run Calkit
description: >
Run a Calkit project pipeline and optionally commit and push results to Git
and DVC remotes.
branding:
icon: arrow-right
color: green
inputs:
save:
description: Whether or not to save (commit and push) results to Git and DVC remotes.
default: "true"
dvc_token:
description:
DVC token for pushing results. If not provided, will be obtained
via GitHub OIDC.
required: false
pull_dvc:
description: Whether or not to pull DVC data before running.
required: false
default: "true"
cache_dvc:
description: Whether or not to cache DVC data.
required: false
default: "true"
run_args:
description: Arguments passed to calkit run command.
required: false
default: ""
outputs: {}
runs:
using: composite
steps:
# This repo is archived, so a log annotation is the only way left to
# tell the workflows still pinned here where the action went
- name: Deprecation notice
shell: bash
run: |
echo "::warning title=calkit/run-action is deprecated::This action has moved to calkit/calkit/actions/run, and this repo is archived, so it will not receive fixes. Run \`calkit update github-actions\` in your project to migrate, or change \`uses:\` to calkit/calkit/actions/run@<calkit version>."
- name: Check for uv and Calkit
id: tools
shell: bash
run: |
set -euo pipefail
if command -v uv >/dev/null 2>&1; then
echo "uv_missing=false" >> "$GITHUB_OUTPUT"
else
echo "uv_missing=true" >> "$GITHUB_OUTPUT"
fi
if command -v calkit >/dev/null 2>&1; then
echo "calkit_missing=false" >> "$GITHUB_OUTPUT"
else
echo "calkit_missing=true" >> "$GITHUB_OUTPUT"
fi
# uv is only needed up front to install Calkit; uv-venv projects that
# need uv but already have Calkit are handled by the uv step after
# detection.
- name: Setup uv
if: ${{ steps.tools.outputs.uv_missing == 'true' && steps.tools.outputs.calkit_missing == 'true' }}
uses: astral-sh/setup-uv@v5
- name: Install Calkit
if: ${{ steps.tools.outputs.calkit_missing == 'true' }}
shell: bash
run: |
uv tool install calkit-python
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Detect setup requirements
id: detect
shell: bash
run: |
set -euo pipefail
# Let Calkit parse its own config so we only look at the
# `environments` section (a real YAML parse that also resolves
# includes), rather than grepping every `kind:` in the file --
# pipeline stages, dependencies, datasets, etc. all use `kind:` too.
kinds=$(calkit list environments 2>/dev/null \
| grep -E '^[[:space:]]+kind:' \
| sed -E 's/^[[:space:]]+kind:[[:space:]]*//; s/[[:space:]]+#.*$//' \
| tr -d "\"'" | sort -u || true)
echo "Detected environment kinds: $(echo "$kinds" | paste -sd, -)"
has_kind() {
printf '%s\n' "$kinds" | grep -qx "$1"
}
if command -v python >/dev/null 2>&1 || command -v python3 >/dev/null 2>&1; then
python_missing=false
else
python_missing=true
fi
if command -v uv >/dev/null 2>&1; then
uv_missing=false
else
uv_missing=true
fi
if command -v conda >/dev/null 2>&1; then
conda_missing=false
else
conda_missing=true
fi
if command -v pixi >/dev/null 2>&1; then
pixi_missing=false
else
pixi_missing=true
fi
# Calkit manages Julia versions via juliaup (e.g. `juliaup add
# 1.11.7` for a `julia: "1.11.7"` environment), so juliaup -- not a
# fixed Julia -- is what must be present. We deliberately gate only on
# juliaup and ignore any plain `julia` on the runner: hosted runner
# images ship a pinned Julia that usually won't match the project's
# required version, and without juliaup Calkit can't install the right
# one. Users who manage Julia themselves should install juliaup, which
# this then detects and leaves alone.
if command -v juliaup >/dev/null 2>&1; then
juliaup_missing=false
else
juliaup_missing=true
fi
if command -v Rscript >/dev/null 2>&1 || command -v R >/dev/null 2>&1; then
r_missing=false
else
r_missing=true
fi
if command -v matlab >/dev/null 2>&1; then
matlab_missing=false
else
matlab_missing=true
fi
if command -v docker >/dev/null 2>&1 && docker buildx version >/dev/null 2>&1; then
docker_buildx_missing=false
else
docker_buildx_missing=true
fi
needs_python=false
needs_uv=false
needs_conda=false
needs_pixi=false
needs_julia=false
needs_r=false
needs_matlab=false
needs_docker=false
docker_cli_missing=false
unsupported_kinds=""
if has_kind "uv-venv" || has_kind "venv" || has_kind "uv"; then
if [ "$python_missing" = true ]; then
needs_python=true
fi
fi
# uv is installed up front to install Calkit, so it is normally
# already present here; this covers the case where Calkit was
# pre-installed (so we skipped the initial uv setup) but uv is not.
if has_kind "uv-venv" || has_kind "uv"; then
if [ "$uv_missing" = true ]; then
needs_uv=true
fi
fi
if has_kind "conda"; then
if [ "$conda_missing" = true ]; then
needs_conda=true
fi
if [ "$python_missing" = true ]; then
needs_python=true
fi
fi
if has_kind "pixi"; then
if [ "$pixi_missing" = true ]; then
needs_pixi=true
fi
fi
if has_kind "julia"; then
if [ "$juliaup_missing" = true ]; then
needs_julia=true
fi
fi
if has_kind "renv"; then
if [ "$r_missing" = true ]; then
needs_r=true
fi
fi
if has_kind "matlab"; then
if [ "$matlab_missing" = true ]; then
needs_matlab=true
fi
fi
if has_kind "docker"; then
if command -v docker >/dev/null 2>&1; then
if [ "$docker_buildx_missing" = true ]; then
needs_docker=true
fi
else
docker_cli_missing=true
fi
fi
# These kinds do not have a direct setup action in this composite action.
if has_kind "ssh"; then unsupported_kinds="${unsupported_kinds}ssh,"; fi
if has_kind "slurm"; then unsupported_kinds="${unsupported_kinds}slurm,"; fi
if has_kind "pbs"; then unsupported_kinds="${unsupported_kinds}pbs,"; fi
if has_kind "nix"; then unsupported_kinds="${unsupported_kinds}nix,"; fi
unsupported_kinds="${unsupported_kinds%,}"
echo "needs_python=${needs_python}" >> "$GITHUB_OUTPUT"
echo "needs_uv=${needs_uv}" >> "$GITHUB_OUTPUT"
echo "needs_conda=${needs_conda}" >> "$GITHUB_OUTPUT"
echo "needs_pixi=${needs_pixi}" >> "$GITHUB_OUTPUT"
echo "needs_julia=${needs_julia}" >> "$GITHUB_OUTPUT"
echo "needs_r=${needs_r}" >> "$GITHUB_OUTPUT"
echo "needs_matlab=${needs_matlab}" >> "$GITHUB_OUTPUT"
echo "needs_docker=${needs_docker}" >> "$GITHUB_OUTPUT"
echo "docker_cli_missing=${docker_cli_missing}" >> "$GITHUB_OUTPUT"
echo "unsupported_kinds=${unsupported_kinds}" >> "$GITHUB_OUTPUT"
- name: Setup uv for uv and uv-venv environments
if: ${{ steps.detect.outputs.needs_uv == 'true' }}
uses: astral-sh/setup-uv@v5
- name: Setup Python
if: ${{ steps.detect.outputs.needs_python == 'true' }}
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Setup Miniconda
if: ${{ steps.detect.outputs.needs_conda == 'true' }}
uses: conda-incubator/setup-miniconda@v3
with:
auto-activate-base: true
conda-remove-defaults: true
- name: Setup Pixi
if: ${{ steps.detect.outputs.needs_pixi == 'true' }}
uses: prefix-dev/setup-pixi@v0.9.6
with:
run-install: false
# Install juliaup (not a fixed Julia) so Calkit can install and select
# the exact Julia version(s) declared in each environment via
# `juliaup add`. The channel here is just a default bootstrap install.
- name: Setup juliaup
if: ${{ steps.detect.outputs.needs_julia == 'true' }}
uses: julia-actions/install-juliaup@v2
with:
channel: "1"
- name: Setup R
if: ${{ steps.detect.outputs.needs_r == 'true' }}
uses: r-lib/actions/setup-r@v2
- name: Setup MATLAB
if: ${{ steps.detect.outputs.needs_matlab == 'true' }}
uses: matlab-actions/setup-matlab@v2
- name: Setup Docker Buildx
if: ${{ steps.detect.outputs.needs_docker == 'true' }}
uses: docker/setup-buildx-action@v3
- name: Report unsupported environment kinds
if: ${{ steps.detect.outputs.unsupported_kinds != '' }}
shell: bash
run: |
echo "::notice::Detected environment kinds without explicit setup action: ${{ steps.detect.outputs.unsupported_kinds }}"
- name: Report missing Docker CLI for docker environments
if: ${{ steps.detect.outputs.docker_cli_missing == 'true' }}
shell: bash
run: |
echo "::notice::Detected kind 'docker' in calkit.yaml, but Docker CLI is not available on this runner. Install Docker on the runner to use docker environments."
- name: Restore DVC cache for current branch
if: ${{ inputs.cache_dvc == 'true' }}
id: cache-dvc-restore
uses: actions/cache/restore@v5
with:
path: .dvc/cache
key: >-
${{ runner.os }}-dvc-cache-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-dvc-cache-${{ github.head_ref || github.ref_name }}-
${{ runner.os }}-dvc-cache-${{ github.event.repository.default_branch }}-
- name: Get GitHub OIDC token
if: ${{ !inputs.dvc_token && (inputs.save == 'true' || inputs.pull_dvc ==
'true') }}
id: get-oidc-token
shell: bash
run: |
OIDC_TOKEN=$(curl -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=calkit.io" -s | jq -r '.value')
if [ -z "$OIDC_TOKEN" ] || [ "$OIDC_TOKEN" == "null" ]; then
echo "Failed to obtain OIDC token"
exit 1
fi
echo "::add-mask::$OIDC_TOKEN"
echo "oidc-token=$OIDC_TOKEN" >> $GITHUB_OUTPUT
- name: Exchange OIDC token for Calkit token
if: ${{ !inputs.dvc_token && (inputs.save == 'true' || inputs.pull_dvc ==
'true') }}
id: get-calkit-token
shell: bash
run: |
CALKIT_TOKEN=$(curl -X POST https://api.calkit.io/login/github-oidc \
-H "Authorization: Bearer ${{ steps.get-oidc-token.outputs.oidc-token }}" \
-s | jq -r '.access_token')
if [ -z "$CALKIT_TOKEN" ] || [ "$CALKIT_TOKEN" == "null" ]; then
echo "Failed to obtain Calkit token"
exit 1
fi
echo "::add-mask::$CALKIT_TOKEN"
echo "calkit-token=$CALKIT_TOKEN" >> $GITHUB_OUTPUT
- run: calkit config remote-auth
if: ${{ inputs.save == 'true' || inputs.pull_dvc == 'true' }}
shell: bash
env:
CALKIT_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
CALKIT_DVC_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
- run: calkit dvc pull
if: ${{ inputs.pull_dvc == 'true' }}
shell: bash
continue-on-error: true
env:
CALKIT_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
CALKIT_DVC_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
- run: calkit run ${{ inputs.run_args }}
shell: bash
- run: calkit save -am "Run pipeline"
if: ${{ inputs.save == 'true' }}
shell: bash
env:
CALKIT_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
CALKIT_DVC_TOKEN: ${{ inputs.dvc_token || steps.get-calkit-token.outputs.calkit-token }}
- name: Save DVC cache
if: ${{ inputs.cache_dvc == 'true' }}
id: cache-dvc-save
uses: actions/cache/save@v5
with:
path: .dvc/cache
key: >-
${{ runner.os }}-dvc-cache-${{ github.head_ref || github.ref_name }}-${{ github.sha }}