-
Notifications
You must be signed in to change notification settings - Fork 9
fix(taskfiles): Output unexpected errors in checksum tasks; Call gtar on macos; Add unit tests for checksum tasks (fixes #67). #81
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
c72511e
394d45f
3b5a816
9c935f9
07b88fc
20802e7
a2ff6f4
194440e
3a92d53
c31ef24
07fd3e4
4ec6588
93a6296
5a230b9
01280e1
b6df417
882c5be
fbe8a72
8534c24
40d4579
bbb32bc
d53221e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,20 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||
| version: "3" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| set: ["u", "pipefail"] | ||||||||||||||||||||||||||||||||||||||||||
| shopt: ["globstar"] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| tasks: | ||||||||||||||||||||||||||||||||||||||||||
| # Compute the checksum of the given path include patterns saving the result to `CHECKSUM_FILE`. A | ||||||||||||||||||||||||||||||||||||||||||
| # calling task can set `FAIL` to false if they wish to continue after errors. | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # @param {string} CHECKSUM_FILE | ||||||||||||||||||||||||||||||||||||||||||
| # @param {string[]} INCLUDE_PATTERNS Path wildcard patterns to compute the checksum for. | ||||||||||||||||||||||||||||||||||||||||||
| # @param {string[]} [EXCLUDE_PATTERNS] Path wildcard patterns, relative to any `INCLUDE_PATTERNS`, | ||||||||||||||||||||||||||||||||||||||||||
| # to exclude from the checksum. | ||||||||||||||||||||||||||||||||||||||||||
| # @param {string} [FAIL="true"] If set to "false" the task will not fail. | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| compute: | ||||||||||||||||||||||||||||||||||||||||||
| desc: "Tries to compute a checksum for the given paths and output it to a file." | ||||||||||||||||||||||||||||||||||||||||||
| internal: true | ||||||||||||||||||||||||||||||||||||||||||
| label: "{{.TASK}}-{{.CHECKSUM_FILE}}" | ||||||||||||||||||||||||||||||||||||||||||
| silent: true | ||||||||||||||||||||||||||||||||||||||||||
| vars: | ||||||||||||||||||||||||||||||||||||||||||
| FAIL: "{{if eq \"false\" .FAIL}}false{{else}}true{{end}}" | ||||||||||||||||||||||||||||||||||||||||||
| TAR: "{{if eq OS \"darwin\"}}gtar{{else}}tar{{end}}" | ||||||||||||||||||||||||||||||||||||||||||
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| TAR: "{{if eq OS \"darwin\"}}gtar{{else}}tar{{end}}" | |
| TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp" | |
| TAR: | |
| sh: | | |
| if command -v gtar >/dev/null 2>&1; then echo gtar; else echo tar; fi | |
| TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp" |
🤖 Prompt for AI Agents
In exports/taskfiles/utils/checksum.yaml around lines 23-24, replace the
OS-based TAR selection with a runtime capability check that prefers gtar when
present and falls back to tar; specifically, change the template expression to
run a shell command like `command -v gtar` (or `which gtar`) at runtime and use
gtar if it exists, otherwise use tar, keeping TMP_ERR_LOG unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will improve this once we add Linux/Alphine CIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bill-hbrhbr, understood! That makes sense to defer this until you have Linux/Alpine CI environments to properly test the capability detection. Would you like me to create a GitHub issue to track this improvement for when the CI infrastructure is ready?
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add MD5_CMD and temp artifact vars for portability and atomic writes
md5sum is not present by default on macOS; Homebrew installs gmd5sum. Also, writing directly to CHECKSUM_FILE risks partial files on failure. Introduce MD5_CMD and temp files now (used in compute refactor below).
Apply:
TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp"
+ TMP_TAR_FILE: "{{.CHECKSUM_FILE}}.tar.tmp"
+ TMP_CHECKSUM_FILE: "{{.CHECKSUM_FILE}}.tmp"
+ MD5_CMD:
+ sh: |
+ if command -v gmd5sum >/dev/null 2>&1; then
+ echo gmd5sum
+ elif command -v md5sum >/dev/null 2>&1; then
+ echo md5sum
+ elif command -v md5 >/dev/null 2>&1; then
+ # macOS fallback; -r prints digest first to match *md5sum output style
+ echo 'md5 -r'
+ else
+ echo 'false' # no-op that will fail
+ fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| TAR: "{{if eq OS \"darwin\"}}gtar{{else}}tar{{end}}" | |
| TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp" | |
| requires: | |
| TAR: "{{if eq OS \"darwin\"}}gtar{{else}}tar{{end}}" | |
| TMP_ERR_LOG: "{{.CHECKSUM_FILE}}.log.tmp" | |
| TMP_TAR_FILE: "{{.CHECKSUM_FILE}}.tar.tmp" | |
| TMP_CHECKSUM_FILE: "{{.CHECKSUM_FILE}}.tmp" | |
| MD5_CMD: | |
| sh: | | |
| if command -v gmd5sum >/dev/null 2>&1; then | |
| echo gmd5sum | |
| elif command -v md5sum >/dev/null 2>&1; then | |
| echo md5sum | |
| elif command -v md5 >/dev/null 2>&1; then | |
| # macOS fallback; -r prints digest first to match *md5sum output style | |
| echo 'md5 -r' | |
| else | |
| echo 'false' # no-op that will fail | |
| fi | |
| requires: |
🤖 Prompt for AI Agents
In exports/taskfiles/utils/checksum.yaml around lines 23-25, add a
platform-aware MD5_CMD variable and explicit temp artifact vars for atomic
writes: define MD5_CMD to use gmd5sum on darwin and md5sum otherwise, and add
CHECKSUM_TMP (e.g. "{{.CHECKSUM_FILE}}.tmp") and retain TMP_ERR_LOG (or rename
to CHECKSUM_ERR_LOG if desired) so compute steps can write to temp files and
then atomically mv to CHECKSUM_FILE; update downstream steps to use these new
vars for generating checksums and error logs.
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| version: "3" | ||
|
|
||
| includes: | ||
| checksum: | ||
| internal: true | ||
| taskfile: "../../exports/taskfiles/utils/checksum.yaml" | ||
|
|
||
| tasks: | ||
| default: | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cmds: | ||
| - task: "checksum-test-rerun" | ||
| - task: "checksum-test-skip" | ||
| - task: "checksum-test-update" | ||
|
|
||
| checksum-test-rerun: | ||
| vars: | ||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||
| SRC_DIR: "{{.OUTPUT_DIR}}/src" | ||
|
|
||
| CHECKSUM_FILE: "{{.SRC_DIR}}.md5" | ||
| CHECKSUM_FILE_REF: "{{.CHECKSUM_FILE}}.ref" | ||
| FILE_0: "{{.SRC_DIR}}/0.txt" | ||
| FILE_1: "{{.SRC_DIR}}/1.txt" | ||
| cmds: | ||
| - task: "checksum-test-init" | ||
| vars: | ||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_0}}" | ||
| - "mv '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF}}'" | ||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_1}}" | ||
|
|
||
| # Test create-dir-with-checksum ran the second time and created a different checksum. | ||
| - "test ! -e '{{.FILE_0}}'" | ||
| - "test -e '{{.FILE_1}}'" | ||
| - |- | ||
| if ! cmp -s '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF}}'; then | ||
| exit 0 | ||
| fi | ||
| exit 1 | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| checksum-test-skip: | ||
| vars: | ||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||
| SRC_DIR: "{{.OUTPUT_DIR}}/src" | ||
|
|
||
| CHECKSUM_FILE: "{{.SRC_DIR}}.md5" | ||
| CHECKSUM_MOD_TS: "{{.CHECKSUM_FILE}}-mod-ts.txt" | ||
| FILE_0: "{{.SRC_DIR}}/0.txt" | ||
| FILE_1: "{{.SRC_DIR}}/1.txt" | ||
| cmds: | ||
| - task: "checksum-test-init" | ||
| vars: | ||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_0}}" | ||
| - "date -r '{{.CHECKSUM_FILE}}' > '{{.CHECKSUM_MOD_TS}}'" | ||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_1}}" | ||
|
|
||
| # Test create-dir-with-checksum didn't run the second time and the checksum is unmodified. | ||
| - "test -e '{{.FILE_0}}'" | ||
| - "test ! -e '{{.FILE_1}}'" | ||
| - "cmp -s '{{.CHECKSUM_MOD_TS}}' <(date -r '{{.CHECKSUM_FILE}}')" | ||
|
|
||
| checksum-test-update: | ||
| vars: | ||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||
| SRC_DIR: "{{.OUTPUT_DIR}}/src" | ||
|
|
||
| CHECKSUM_FILE: "{{.SRC_DIR}}.md5" | ||
| CHECKSUM_FILE_REF0: "{{.CHECKSUM_FILE}}.ref0" | ||
| CHECKSUM_FILE_REF1: "{{.CHECKSUM_FILE}}.ref1" | ||
| FILE_0: "{{.SRC_DIR}}/0.txt" | ||
| FILE_1: "{{.SRC_DIR}}/1.txt" | ||
| cmds: | ||
| - task: "checksum-test-init" | ||
| vars: | ||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_0}}" | ||
| - "cp '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF0}}'" | ||
|
|
||
| - "cat '{{.CHECKSUM_FILE}}' > '{{.FILE_0}}'" | ||
| - task: "checksum:compute" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| INCLUDE_PATTERNS: ["{{.SRC_DIR}}"] | ||
| - "cp '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF1}}'" | ||
|
|
||
| - task: "create-dir-with-checksum" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| FILE_PATH: "{{.FILE_1}}" | ||
|
|
||
| # Test create-dir-with-checksum didn't run the second time and the updated checksum is | ||
| # different from the original. | ||
| - "test -e '{{.FILE_0}}'" | ||
| - "test ! -e '{{.FILE_1}}'" | ||
| - "cmp -s '{{.FILE_0}}' '{{.CHECKSUM_FILE_REF0}}'" | ||
| - "cmp -s '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF1}}'" | ||
| - |- | ||
| if ! cmp -s '{{.CHECKSUM_FILE}}' '{{.CHECKSUM_FILE_REF0}}'; then | ||
| exit 0 | ||
| fi | ||
| exit 1 | ||
Bill-hbrhbr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| checksum-test-init: | ||
| internal: true | ||
| requires: | ||
| vars: ["OUTPUT_DIR"] | ||
| cmds: | ||
| - "rm -rf '{{.OUTPUT_DIR}}'" | ||
| - "mkdir -p '{{.OUTPUT_DIR}}'" | ||
|
|
||
| create-dir-with-checksum: | ||
| internal: true | ||
| vars: | ||
| DIR: "{{dir .FILE_PATH}}" | ||
| requires: | ||
| vars: ["CHECKSUM_FILE", "FILE_PATH"] | ||
| sources: ["{{.TASKFILE}}"] | ||
| generates: ["{{.CHECKSUM_FILE}}"] | ||
| deps: | ||
| - task: "checksum:validate" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| INCLUDE_PATTERNS: ["{{.DIR}}"] | ||
| cmds: | ||
| - |- | ||
| rm -rf "{{.DIR}}" | ||
| mkdir -p "{{.DIR}}" | ||
| touch "{{.FILE_PATH}}" | ||
| - task: "checksum:compute" | ||
| vars: | ||
| CHECKSUM_FILE: "{{.CHECKSUM_FILE}}" | ||
| INCLUDE_PATTERNS: ["{{.DIR}}"] | ||
Uh oh!
There was an error while loading. Please reload this page.