Skip to content

feat(taskfiles)!: Split utils taskfile by category; Rename extension from yml to yaml.#18

Merged
davidlion merged 6 commits into
y-scope:mainfrom
davidlion:refactor-taskfiles
Feb 5, 2025
Merged

feat(taskfiles)!: Split utils taskfile by category; Rename extension from yml to yaml.#18
davidlion merged 6 commits into
y-scope:mainfrom
davidlion:refactor-taskfiles

Conversation

@davidlion

@davidlion davidlion commented Feb 3, 2025

Copy link
Copy Markdown
Member

Description

Previously, all taskfile utility tasks were in a single file, utils.yml. This PR breaks up that file and changes the extension to .yaml to follow guidelines. Additionally, utils.yaml provides a "meta" taskfile that includes all categorized files. Including utils.yaml will behave as utils.yml did previously.

There are no functional changes to any of the actual content. There is one small alphabetization fix for the arguments in a compute-checksum call.

Validation performed

Tested manually with clp-ffi-go tasks.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced streamlined automation tasks for text replacement and Python environment creation.
    • Added functionality for generating and validating file checksums to bolster data integrity.
    • Enabled secure file downloading with automated extraction and retry options.
    • Provided support for configuring, building, and installing projects using modern build tools.
    • Enhanced C++ code quality with automated linting and static analysis.
    • Adopted a modular configuration approach to simplify utility management.

@coderabbitai

coderabbitai Bot commented Feb 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request introduces several new YAML configuration files and tasks to facilitate various automation operations. New tasks include text replacement and virtual environment creation, checksum computation and validation, remote file downloading with extraction, CMake project configuration/build and installation, as well as C++ linting using clang-format and clang-tidy. Additionally, a main utility configuration file is provided to reference and flatten these individual taskfiles for streamlined management.

Changes

File Change Summary
taskfiles/utils-misc.yaml Added tasks: replace-text (replaces specified text in a file using sed with temporary file handling) and create-venv (removes an existing directory, creates a new Python virtual environment, adjusts the activation script, activates the environment, and installs packages).
taskfiles/utils.yaml New YAML configuration file with version "3", which includes references to other taskfiles: utils-checksum.yaml, utils-cmake.yaml, utils-cpp-lint.yaml, utils-remote.yaml, and utils-misc.yaml for modular organization of utility tasks.
taskfiles/utils-checksum.yaml Introduced tasks: compute-checksum (creates an archive of files, computes md5sum, and writes the output) and validate-checksum (generates a temporary checksum, verifies file existence, compares checksums, and deletes the original file if discrepancies occur).
taskfiles/utils-remote.yaml Added tasks: curl (downloads a file from a URL with a retry mechanism and SHA256 verification) and download-and-extract-tar (downloads a tarball via the curl task, validates its checksum, and extracts its contents according to inclusion/exclusion patterns).
taskfiles/utils-cmake.yaml Introduced tasks: cmake-config-and-build (configures and builds a CMake project using supplied source and build directories and optional job counts) and cmake-install (installs the built project using a specified installation prefix).
taskfiles/utils-cpp-lint.yaml Added tasks: clang-format (searches for C++ source files, formats them using clang-format via an activated virtual environment) and clang-tidy (performs static analysis on the located C++ files using clang-tidy).

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant VT as Create-Venv Task
    participant FS as Filesystem
    participant SHELL as Shell Environment

    U->>VT: Initiate virtual environment creation
    VT->>FS: Remove existing virtual environment directory (if exists)
    VT->>SHELL: Create new Python virtual environment
    VT->>FS: Modify activation script (remove calls to hash)
    VT->>SHELL: Activate virtual environment
    VT->>SHELL: Install Python packages from requirements file
Loading
sequenceDiagram
    participant U as User
    participant DET as Download-&-Extract Task
    participant CURL as Curl Task
    participant VC as Validate-Checksum Task
    participant TAR as Tar Extractor

    U->>DET: Start download & extraction process
    DET->>CURL: Request file download with retry logic
    CURL-->>DET: Return downloaded file (or error if failed)
    DET->>VC: Validate downloaded file checksum
    VC-->>DET: Return validation result
    DET->>TAR: Extract tarball contents with defined patterns
Loading

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • junhaoliao

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6b524 and a45a403.

📒 Files selected for processing (2)
  • taskfiles/utils-cmake.yaml (1 hunks)
  • taskfiles/utils.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • taskfiles/utils.yaml
  • taskfiles/utils-cmake.yaml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
taskfiles/utils-cpp.yaml (1)

49-76: CMake Configuration and Build Task:
This task is well-structured, with variable defaults defined for optional parameters (CONF_ARGS and JOBS) and a descriptive label. One point to consider is the handling of the JOBS parameter: if it is left empty, the --parallel flag might still be passed with an empty string, which could lead to unexpected behaviour in CMake. You might refactor this section to conditionally include the --parallel flag only when JOBS is provided.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5213d and 7333c2b.

📒 Files selected for processing (3)
  • taskfiles/utils-cpp.yaml (1 hunks)
  • taskfiles/utils-misc.yaml (1 hunks)
  • taskfiles/utils.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • taskfiles/utils.yaml
🔇 Additional comments (7)
taskfiles/utils-cpp.yaml (4)

1-5: Initial Configuration and Shell Options:
The version declaration, shell options (set and shopt), and overall initial configuration are clear and succinct. This foundation helps ensure that the subsequent shell commands execute reliably.


11-27: Clang-Format Task Definition:
The task for clang-format is well-documented with inline comments and clear parameter definitions. The templating for iterating over the source paths is correctly applied, and the command chain (activating the virtual environment, using find with proper file matching, piping to clang-format with specified flags and error handling) is structured appropriately.


28-44: Clang-Tidy Task Definition:
The clang-tidy task mirrors the clang-format task effectively, with clear documentation of parameters and a similar command structure. The activation of the virtual environment and file selection logic appears sound. It would be beneficial to double-check that the virtual environment contains the correct tools and that the provided flags work as intended.


77-90: CMake Install Task:
The CMake install task is defined cleanly, with required parameters clearly stated and a straightforward command to install the project from the specified build directory. Everything appears in order with this segment.

taskfiles/utils-misc.yaml (3)

205-223: Clarify and Document the Reordering for STRING UTILS

The "STRING UTILS" section (which contains the replace-text task) has been relocated within the file. Although no content was altered, this section now appears later in the file due to the new alphabetical ordering. To avoid confusion for future maintainers and reviewers, please consider adding a comment that documents the intent behind this reordering and confirms that the change does not affect task execution order.


224-249: Verify the Reordering of VENV UTILS Tasks

Similarly, the "VENV UTILS" section (including the create-venv task) has been moved as part of the alphabetical reorganisation. The functionality remains unchanged, but the diff may be confusing without explicit clarification. Please ensure that documentation or commit messages clearly note that this reordering is intentional and that no dependent processes rely on a specific order.


1-249: Overall Verification of Taskfile Reorganisation

The file now presents task categories sorted alphabetically (i.e. "CHECKSUM UTILS," "REMOTE UTILS," "STRING UTILS," and "VENV UTILS"). While this arrangement should improve maintainability, please double-check that no implicit execution dependencies rely on the previous ordering. Updating documentation to note this intentional design change will help prevent future confusion.

@kirkrodrigues kirkrodrigues left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not mandatory, but do you want to split checksum-utils and remote-utils into their own files?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
taskfiles/utils-misc.yaml (1)

7-21: Review of 'replace-text' task:
The task is well-documented and clearly explains the cross-platform nuances of using sed (e.g. the differences in -i syntax between Linux and macOS). One suggestion is to consider adding error checking after the sed command so that if the temporary file isn’t created successfully, the task can fail gracefully.

taskfiles/utils-checksum.yaml (2)

11-47: Review of 'compute-checksum' task:
The task makes good use of tar with fixed owner and timestamp settings to ensure a consistent checksum, which is important for reproducibility. While the use of ignore_error helps prevent cascading failures, consider logging errors from tar to aid in debugging if the checksum computation doesn’t behave as expected.


49-81: Review of 'validate-checksum' task:
This task effectively reuses the compute-checksum function to validate file integrity. The inline shell block is concise; however, ensure that the loop iterating over .INCLUDE_PATTERNS adequately quotes paths—especially if they contain spaces—to avoid potential false negatives. It might also be helpful to provide more verbose output when the checksum validation fails.

taskfiles/utils-remote.yaml (2)

27-50: Review of 'curl' command block:
The download loop is robust, featuring a clear maximum attempt limit and a pause between retries. Adding more detailed logging (such as printing the current attempt number) could be useful for diagnosing download issues during execution.


51-121: Review of 'download-and-extract-tar' task:
This comprehensive task successfully combines downloading, extraction, and checksum validation. The use of default parameters for file paths and the delegation to dependent tasks promotes modularity. Ensure that the include and exclude patterns for tar are correctly quoted to handle special characters or spaces, and consider emitting a message upon successful extraction for enhanced clarity during task execution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18b72dd and 18d1576.

📒 Files selected for processing (5)
  • taskfiles/utils-checksum.yaml (1 hunks)
  • taskfiles/utils-cpp.yaml (1 hunks)
  • taskfiles/utils-misc.yaml (1 hunks)
  • taskfiles/utils-remote.yaml (1 hunks)
  • taskfiles/utils.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • taskfiles/utils.yaml
  • taskfiles/utils-cpp.yaml
🔇 Additional comments (2)
taskfiles/utils-misc.yaml (1)

22-43: Review of 'create-venv' task:
This task efficiently automates the creation of a Python virtual environment and smartly reuses the replace-text subtask to modify the activation script for compatibility with the gosh shell. It would be beneficial to verify that the activation script exists before attempting to modify it. Additionally, adding some logging or error handling in case the rm -rf or venv creation commands fail could improve maintainability.

taskfiles/utils-remote.yaml (1)

12-26: Review of 'curl' task:
The curl task is thoughtfully constructed, including a retry mechanism and checksum verification using process substitution. One point to verify is that process substitution (using <(...)) is supported reliably across all target shell environments, as some shells may not support it.

Comment thread taskfiles/utils.yaml
Comment thread taskfiles/utils-cmake.yaml Outdated
cmake
--install "{{.BUILD_DIR}}"
--prefix "{{.INSTALL_PREFIX}}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@davidlion davidlion merged commit c8b5d5c into y-scope:main Feb 5, 2025
@davidlion davidlion deleted the refactor-taskfiles branch February 20, 2025 02:30
# downloaded tar file.
# @param {string[]} [EXCLUDE_PATTERNS] Path wildcard patterns that should not be extracted.
# @param {string[]} [INCLUDE_PATTERNS] Path wildcard patterns to extract.
# @param {int} [NUM_COMPONENTS_TO_STRIP=1] Number of leading path components to strip from the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifying NUM_COMPONENTS_TO_STRIP=0 always result in 1 being specified because sprig's default treats 0 as an empty value

https://masterminds.github.io/sprig/defaults.html#default

The definition of “empty” depends on type:

Numeric: 0

a mitigation is to write NUM_COMPONENTS_TO_STRIP="0" in the caller instead.

we should either:

  1. change the default value as 0
  2. check if the user explicitly specifies the var; only if the var is not specified, we default to 1.
  3. document the behaviour and mitigation / expected usage explicitly

@coderabbitai create an issue to track

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Create a GitHub issue to track the NUM_COMPONENTS_TO_STRIP parameter issue

gh issue create \
  --repo y-scope/yscope-dev-utils \
  --title "Fix NUM_COMPONENTS_TO_STRIP default behavior when 0 is specified" \
  --body "## Issue Description

In \`taskfiles/utils-remote.yaml\`, the \`download-and-extract-tar\` task has a parameter \`NUM_COMPONENTS_TO_STRIP\` with a default value of 1. However, due to sprig's \`default\` function treating numeric 0 as an empty value, explicitly setting \`NUM_COMPONENTS_TO_STRIP=0\` results in 1 being used instead.

Reference: https://masterminds.github.io/sprig/defaults.html#default

## Workaround

Users can specify \`NUM_COMPONENTS_TO_STRIP=\"0\"\` (as a string) in the caller to work around this issue.

## Potential Solutions

1. Change the default value to 0
2. Check if the user explicitly specifies the var; only if the var is not specified, default to 1
3. Document the behavior and mitigation/expected usage explicitly

## Context

- **PR**: https://github.com/y-scope/yscope-dev-utils/pull/18
- **Comment**: https://github.com/y-scope/yscope-dev-utils/pull/18#discussion_r2531515156
- **Reported by**: @junhaoliao" \
  --assignee junhaoliao

Length of output: 53


@junhaoliao, excellent catch on the sprig default function behavior! I've created issue #96 to track this.

The issue documents the problem, the workaround you mentioned (using NUM_COMPONENTS_TO_STRIP="0" as a string), and the three potential solutions you outlined. This should help ensure it gets addressed in a future update.


🧠 Learnings used
Learnt from: davidlion
Repo: y-scope/yscope-dev-utils PR: 16
File: taskfiles/utils.yml:296-299
Timestamp: 2024-11-15T02:34:27.126Z
Learning: In `taskfiles/utils.yml`, tasks are configured to fail if any command fails, so adding explicit error handling within commands is unnecessary.

Learnt from: Bill-hbrhbr
Repo: y-scope/yscope-dev-utils PR: 91
File: exports/taskfiles/utils/misc.yaml:70-90
Timestamp: 2025-10-13T19:09:44.404Z
Learning: In the yscope-dev-utils repository Taskfiles, prefer minimal guardrails that only protect against benevolent mistakes (e.g., enforcing absolute paths where required) rather than defensive checks like rejecting root paths, empty paths, or validating file vs directory types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants