Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Taskfile contribution guidelines to use utility tasks in yscope-dev-utils. #19

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 8 additions & 57 deletions docs/dev-guide/contrib-guides-taskfiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,79 +101,29 @@ child2:
### `generates` and glob patterns

Don't use `generates` entries with glob patterns unless you've accounted for the limitations above.
Instead, you can manually checksum the generated files using the utility tasks below:
Instead, we can checksum the generated files ourselves using the utility tasks in [yscope-dev-utils]
as follows:

```yaml
vars:
CHECKSUM_TAR_BASE_ARGS: >-
--group=0
--mtime='UTC 1970-01-01'
--numeric-owner
--owner=0
--sort=name

compute-checksum:
desc: "Tries to compute a checksum for the given directory and output it to a file."
internal: true
silent: true
requires:
vars: ["DATA_DIR", "OUTPUT_FILE"]
cmds:
- >-
tar cf -
--directory "{{.DATA_DIR}}"
--group=0
--mtime='UTC 1970-01-01'
--numeric-owner
--owner=0
--sort=name
{{.CHECKSUM_TAR_BASE_ARGS}} . 2> /dev/null
| md5sum > {{.OUTPUT_FILE}}
# Ignore errors so that dependent tasks don't fail
ignore_error: true

validate-checksum:
desc: "Validates the checksum of the given directory matches the checksum in the given file, or
deletes the checksum file otherwise."
internal: true
silent: true
requires:
vars: ["CHECKSUM_FILE", "DATA_DIR"]
vars:
TMP_CHECKSUM_FILE: "{{.CHECKSUM_FILE}}.tmp"
cmds:
- task: "compute-checksum"
vars:
DATA_DIR: "{{.DATA_DIR}}"
OUTPUT_FILE: "{{.TMP_CHECKSUM_FILE}}"
- defer: "rm -f '{{.TMP_CHECKSUM_FILE}}'"
# Check that the directory exists and the checksum matches; otherwise delete the checksum file
- >-
(
test -d "{{.DATA_DIR}}"
&& diff -q '{{.TMP_CHECKSUM_FILE}}' '{{.CHECKSUM_FILE}}' 2> /dev/null
) || rm -f '{{.CHECKSUM_FILE}}'
```
includes:
utils: "tools/yscope-dev-utils/tasks/utils.yml"

You can use the utility tasks as follows:

```yaml
my-task:
vars:
CHECKSUM_FILE: "checksum.txt"
OUTPUT_DIR: "build/my-task"
OUTPUT_DIR: "build/{{.TASK}}"
sources: ["source.txt"]
generates: ["{{.CHECKSUM_FILE}}"]
deps:
- task: "validate-checksum"
- task: "utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
DATA_DIR: "{{.OUTPUT_DIR}}"
cmds:
- "mkdir -p '{{.OUTPUT_DIR}}'"
- "touch '{{.OUTPUT_DIR}}/output.txt'"
# This command must be last
- task: "compute-checksum"
- task: "utils:compute-checksum"
vars:
DATA_DIR: "{{.OUTPUT_DIR}}"
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
Expand Down Expand Up @@ -280,3 +230,4 @@ my-task:

[Taskfiles]: https://taskfile.dev/usage/
[task-attrs]: https://taskfile.dev/api/#task
[yscope-dev-utils]: https://github.com/y-scope/yscope-dev-utils/blob/main/taskfiles/utils.yml