Skip to content

Commit a40a661

Browse files
Taskfile: Replace utility tasks with ones from yscope-dev-utils. (#456)
1 parent 628ba3d commit a40a661

File tree

5 files changed

+35
-109
lines changed

5 files changed

+35
-109
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@
2323
[submodule "components/core/submodules/abseil-cpp"]
2424
path = components/core/submodules/abseil-cpp
2525
url = https://github.com/abseil/abseil-cpp.git
26+
[submodule "tools/yscope-dev-utils"]
27+
path = tools/yscope-dev-utils
28+
url = https://github.com/y-scope/yscope-dev-utils.git

Taskfile.yml

+19-97
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: "3"
33
includes:
44
docs: "docs/tasks.yml"
55
lint: "lint-tasks.yml"
6+
utils: "tools/yscope-dev-utils/taskfiles/utils.yml"
67

78
vars:
89
# Paths
@@ -60,7 +61,7 @@ tasks:
6061
- "init"
6162
- "job-orchestration"
6263
- "package-venv"
63-
- task: "validate-checksum"
64+
- task: "utils:validate-checksum"
6465
vars:
6566
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
6667
DATA_DIR: "{{.OUTPUT_DIR}}"
@@ -97,7 +98,7 @@ tasks:
9798
cd "{{.OUTPUT_DIR}}/var/www/programs/server"
9899
PATH="{{.G_WEBUI_NODEJS_BIN_DIR}}":$PATH npm install
99100
# This command must be last
100-
- task: "compute-checksum"
101+
- task: "utils:compute-checksum"
101102
vars:
102103
DATA_DIR: "{{.OUTPUT_DIR}}"
103104
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -163,7 +164,7 @@ tasks:
163164
deps:
164165
- "init"
165166
- "meteor"
166-
- task: "validate-checksum"
167+
- task: "utils:validate-checksum"
167168
vars:
168169
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
169170
DATA_DIR: "{{.OUTPUT_DIR}}"
@@ -187,7 +188,7 @@ tasks:
187188
# Remove temp files generated by `meteor build` before checksum
188189
- "find node_modules -type f -name '.meteor-portable-2.json' -exec rm {} +"
189190
# This command must be last
190-
- task: "compute-checksum"
191+
- task: "utils:compute-checksum"
191192
vars:
192193
DATA_DIR: "{{.OUTPUT_DIR}}"
193194
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -223,14 +224,14 @@ tasks:
223224
OUTPUT_DIR: "submodules"
224225
deps:
225226
- "init"
226-
- task: "validate-checksum"
227+
- task: "utils:validate-checksum"
227228
vars:
228229
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
229230
DATA_DIR: "{{.OUTPUT_DIR}}"
230231
cmds:
231232
- "tools/scripts/deps-download/download-all.sh"
232233
# This command must be last
233-
- task: "compute-checksum"
234+
- task: "utils:compute-checksum"
234235
vars:
235236
DATA_DIR: "{{.OUTPUT_DIR}}"
236237
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -251,7 +252,7 @@ tasks:
251252
TAR_PATH: "{{.OUTPUT_TMP_DIR}}/{{.TAR_NAME}}"
252253
deps:
253254
- "init"
254-
- task: "validate-checksum"
255+
- task: "utils:validate-checksum"
255256
vars:
256257
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
257258
DATA_DIR: "{{.OUTPUT_DIR}}"
@@ -266,7 +267,7 @@ tasks:
266267
- "mv '{{.EXTRACTED_DIR}}' '{{.OUTPUT_DIR}}'"
267268
- "rm -rf '{{.OUTPUT_TMP_DIR}}'"
268269
# This command must be last
269-
- task: "compute-checksum"
270+
- task: "utils:compute-checksum"
270271
vars:
271272
DATA_DIR: "{{.OUTPUT_DIR}}"
272273
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -337,12 +338,12 @@ tasks:
337338
# `/parents/A` -> `/parents/B` rather than `/parents/A` -> `/parents/B/A`
338339
- "rsync --archive '{{.G_PACKAGE_BUILD_DIR}}/' '{{.OUTPUT_DIR}}'"
339340
# Set the storage engine for the package
340-
- task: "replace-text"
341+
- task: "utils:replace-text"
341342
vars:
342343
FILE_PATH: "{{.OUTPUT_DIR}}/lib/python3/site-packages/clp_py_utils/clp_config.py"
343344
SED_EXP: >-
344345
s/([[:space:]]*storage_engine: str = ")[^"]+"/\1{{.STORAGE_ENGINE}}"/
345-
- task: "replace-text"
346+
- task: "utils:replace-text"
346347
vars:
347348
FILE_PATH: "{{.OUTPUT_DIR}}/etc/clp-config.yml"
348349
SED_EXP: >-
@@ -364,18 +365,18 @@ tasks:
364365
OUTPUT_DIR: "{{.G_PACKAGE_VENV_DIR}}"
365366
deps:
366367
- "init"
367-
- task: "validate-checksum"
368+
- task: "utils:validate-checksum"
368369
vars:
369370
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
370371
DATA_DIR: "{{.OUTPUT_DIR}}"
371372
cmds:
372-
- task: "create-venv"
373+
- task: "utils:create-venv"
373374
vars:
374375
LABEL: "package"
375376
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
376377
REQUIREMENTS_FILE: "requirements.txt"
377378
# This command must be last
378-
- task: "compute-checksum"
379+
- task: "utils:compute-checksum"
379380
vars:
380381
DATA_DIR: "{{.OUTPUT_DIR}}"
381382
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -427,15 +428,15 @@ tasks:
427428
deps:
428429
- "init"
429430
- "meteor"
430-
- task: "validate-checksum"
431+
- task: "utils:validate-checksum"
431432
vars:
432433
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
433434
DATA_DIR: "{{.OUTPUT_DIR}}"
434435
cmds:
435436
- "rm -rf '{{.OUTPUT_DIR}}'"
436437
- "PATH='{{.G_METEOR_BUILD_DIR}}':$PATH meteor npm install --production"
437438
# This command must be last
438-
- task: "compute-checksum"
439+
- task: "utils:compute-checksum"
439440
vars:
440441
DATA_DIR: "{{.OUTPUT_DIR}}"
441442
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -456,18 +457,18 @@ tasks:
456457
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.COMPONENT}}-venv.md5"
457458
deps:
458459
- "init"
459-
- task: "validate-checksum"
460+
- task: "utils:validate-checksum"
460461
vars:
461462
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
462463
DATA_DIR: "{{.OUTPUT_DIR}}"
463464
cmds:
464-
- task: "create-venv"
465+
- task: "utils:create-venv"
465466
vars:
466467
LABEL: "{{.COMPONENT}}"
467468
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
468469
REQUIREMENTS_FILE: "{{.ROOT_DIR}}/requirements.txt"
469470
# This command must be last
470-
- task: "compute-checksum"
471+
- task: "utils:compute-checksum"
471472
vars:
472473
DATA_DIR: "{{.OUTPUT_DIR}}"
473474
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -487,87 +488,8 @@ tasks:
487488
cmds:
488489
- "rm -rf dist"
489490

490-
create-venv:
491-
internal: true
492-
requires:
493-
vars: ["LABEL", "OUTPUT_DIR", "REQUIREMENTS_FILE"]
494-
label: "create-venv-{{.LABEL}}"
495-
cmds:
496-
- "rm -rf '{{.OUTPUT_DIR}}'"
497-
- "python3 -m venv '{{.OUTPUT_DIR}}'"
498-
# Remove calls to `hash` from the venv activation script since Task uses `gosh` rather than
499-
# `bash`.
500-
# NOTE: Older versions of Python's venv would only call `hash` if they detected the running
501-
# shell was one that had the command, but that's not the case in newer versions.
502-
- task: "replace-text"
503-
vars:
504-
FILE_PATH: "{{.OUTPUT_DIR}}/bin/activate"
505-
SED_EXP: >-
506-
s/^([[:space:]]*)hash[[:space:]]+.*/\1true/g
507-
- |-
508-
. "{{.OUTPUT_DIR}}/bin/activate"
509-
pip3 install --upgrade pip
510-
pip3 install --upgrade -r "{{.REQUIREMENTS_FILE}}"
511-
512491
init:
513492
internal: true
514493
run: "once"
515494
silent: true
516495
cmd: "mkdir -p '{{.G_BUILD_DIR}}'"
517-
518-
compute-checksum:
519-
desc: "Tries to compute a checksum for the given directory and output it to a file."
520-
internal: true
521-
# Ignore errors so that dependent tasks don't fail
522-
ignore_error: true
523-
silent: true
524-
requires:
525-
vars: ["DATA_DIR", "OUTPUT_FILE"]
526-
cmds:
527-
- >-
528-
tar cf -
529-
--directory "{{.DATA_DIR}}"
530-
--group=0
531-
--mtime='UTC 1970-01-01'
532-
--numeric-owner
533-
--owner=0
534-
--sort=name
535-
{{.CHECKSUM_TAR_BASE_ARGS}} . 2> /dev/null
536-
| md5sum > {{.OUTPUT_FILE}}
537-
538-
validate-checksum:
539-
desc: "Validates the checksum of the given directory matches the checksum in the given file, or
540-
deletes the checksum file otherwise."
541-
internal: true
542-
silent: true
543-
requires:
544-
vars: ["CHECKSUM_FILE", "DATA_DIR"]
545-
vars:
546-
TMP_CHECKSUM_FILE: "{{.CHECKSUM_FILE}}.tmp"
547-
cmds:
548-
- task: "compute-checksum"
549-
vars:
550-
DATA_DIR: "{{.DATA_DIR}}"
551-
OUTPUT_FILE: "{{.TMP_CHECKSUM_FILE}}"
552-
- defer: "rm -f '{{.TMP_CHECKSUM_FILE}}'"
553-
# Check that the directory exists and the checksum matches; otherwise delete the checksum file
554-
- >-
555-
(
556-
test -d "{{.DATA_DIR}}"
557-
&& diff -q '{{.TMP_CHECKSUM_FILE}}' '{{.CHECKSUM_FILE}}' 2> /dev/null
558-
) || rm -f '{{.CHECKSUM_FILE}}'
559-
560-
replace-text:
561-
desc: "Task to replace some text in a file using sed."
562-
internal: true
563-
requires:
564-
vars: ["FILE_PATH", "SED_EXP"]
565-
cmds:
566-
- |-
567-
# NOTE:
568-
# 1. We can't use `sed -i` since `-i` has different syntax on Linux and macOS
569-
# 2. We can't use `--regexp` instead of `-E` since `--regexp` is not supported on macOS
570-
src="{{.FILE_PATH}}"
571-
dst="{{.FILE_PATH}}.tmp"
572-
sed -E '{{.SED_EXP}}' "${src}" > "${dst}"
573-
mv "${dst}" "${src}"

docs/tasks.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tasks:
2525
dir: "{{.TASKFILE_DIR}}"
2626
deps:
2727
- ":init"
28-
- task: ":validate-checksum"
28+
- task: ":utils:validate-checksum"
2929
vars:
3030
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
3131
DATA_DIR: "{{.OUTPUT_DIR}}"
@@ -43,7 +43,7 @@ tasks:
4343
--builder html \
4444
src "{{.OUTPUT_DIR}}"
4545
# This command must be last
46-
- task: ":compute-checksum"
46+
- task: ":utils:compute-checksum"
4747
vars:
4848
DATA_DIR: "{{.OUTPUT_DIR}}"
4949
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -63,18 +63,18 @@ tasks:
6363
REQUIREMENTS_FILE: "docs/requirements.txt"
6464
deps:
6565
- ":init"
66-
- task: ":validate-checksum"
66+
- task: ":utils:validate-checksum"
6767
vars:
6868
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
6969
DATA_DIR: "{{.OUTPUT_DIR}}"
7070
cmds:
71-
- task: ":create-venv"
71+
- task: ":utils:create-venv"
7272
vars:
7373
LABEL: "docs"
7474
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
7575
REQUIREMENTS_FILE: "{{.REQUIREMENTS_FILE}}"
7676
# This command must be last
77-
- task: ":compute-checksum"
77+
- task: ":utils:compute-checksum"
7878
vars:
7979
DATA_DIR: "{{.OUTPUT_DIR}}"
8080
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -91,15 +91,15 @@ tasks:
9191
OUTPUT_DIR: "{{.G_NODE_DEPS_DIR}}"
9292
deps:
9393
- ":init"
94-
- task: ":validate-checksum"
94+
- task: ":utils:validate-checksum"
9595
vars:
9696
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
9797
DATA_DIR: "{{.OUTPUT_DIR}}"
9898
cmds:
9999
- "rm -rf '{{.OUTPUT_DIR}}'"
100100
- "npm --prefix '{{.OUTPUT_DIR}}' install http-server"
101101
# This command must be last
102-
- task: ":compute-checksum"
102+
- task: ":utils:compute-checksum"
103103
vars:
104104
DATA_DIR: "{{.OUTPUT_DIR}}"
105105
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"

lint-tasks.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ tasks:
166166
deps:
167167
- ":init"
168168
- ":webui-node-modules"
169-
- task: ":validate-checksum"
169+
- task: ":utils:validate-checksum"
170170
vars:
171171
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
172172
DATA_DIR: "{{.OUTPUT_DIR}}"
@@ -180,7 +180,7 @@ tasks:
180180
- "rm -rf '{{.OUTPUT_DIR}}'"
181181
- "PATH='{{.G_LINTER_NODEJS_BIN_DIR}}':$PATH npm update"
182182
# This command must be last
183-
- task: ":compute-checksum"
183+
- task: ":utils:compute-checksum"
184184
vars:
185185
DATA_DIR: "{{.OUTPUT_DIR}}"
186186
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
@@ -199,18 +199,18 @@ tasks:
199199
OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}"
200200
deps:
201201
- ":init"
202-
- task: ":validate-checksum"
202+
- task: ":utils:validate-checksum"
203203
vars:
204204
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
205205
DATA_DIR: "{{.OUTPUT_DIR}}"
206206
cmds:
207-
- task: ":create-venv"
207+
- task: ":utils:create-venv"
208208
vars:
209209
LABEL: "lint"
210210
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
211211
REQUIREMENTS_FILE: "lint-requirements.txt"
212212
# This command must be last
213-
- task: ":compute-checksum"
213+
- task: ":utils:compute-checksum"
214214
vars:
215215
DATA_DIR: "{{.OUTPUT_DIR}}"
216216
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"

tools/yscope-dev-utils

Submodule yscope-dev-utils added at ff1611e

0 commit comments

Comments
 (0)