Skip to content

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Oct 9, 2025

Closes #

What I did

  • This PR introduces a --fix option to the check script for automatically correcting parallelism counts in workflow files.

Usage (at the root):

yarn get-template --fix

How it looks like:
image

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Added a CLI --fix option to automatically update parallelism settings in workflow configurations while preserving formatting and comments.
    • Provides detailed confirmations of which jobs were updated and per-workflow summaries when fixes are applied.
  • Improvements

    • Enhanced error messaging and guidance when inconsistencies are detected without using --fix.
    • Check mode still validates and reports mismatches without applying changes.
  • Chores

    • Updated CLI parsing to support the new --fix behavior.

- Introduced a `--fix` option to the script for automatically correcting parallelism counts in workflow files.
- Implemented logic to read and update parallelism values in the corresponding YAML files while preserving formatting and comments.
- Enhanced error messages to guide users on regenerating the main config file after fixes.
@yannbf yannbf added build Internal-facing build tooling & test updates ci:normal labels Oct 9, 2025
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

📝 Walkthrough

Walkthrough

Adds an optional --fix mode to the CircleCI parallelism checker: propagates a fix flag through run and checkParallelism, collects mismatched jobs, and when requested edits workflow YAML files (text-based updates) to insert/update parallelism lines; otherwise errors with guidance.

Changes

Cohort / File(s) Summary
CircleCI parallelism check & auto-fix
scripts/get-template.ts
- Import writeFile from node:fs/promises and add WORKFLOWS_DIR constant.
- Extend checkParallelism(cadence?, scriptName?, fix=false) to collect fixes (cadence, job, old/new parallelism) and optionally apply them.
- When fix is true, group fixes by workflow YAML, edit files as text to update/insert parallelism: lines (preserving formatting/comments), and write back; when false, throw an error with rerun guidance.
- Update run({ cadence, task, check, fix }) and RunOptions to include fix; add --fix CLI flag; adjust reporting to list applied fixes and prompt regen/validation.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as get-template.ts
  participant CP as checkParallelism()
  participant FS as FileSystem
  participant WF as Workflow YAMLs

  U->>CLI: run (--check? --fix?)
  CLI->>CP: checkParallelism(cadence?, task?, fix)
  CP->>CP: compute expected vs actual parallelism
  alt mismatches & fix==true
    CP->>FS: read affected `WORKFLOWS_DIR` files (text)
    CP->>CP: build per-workflow text patches (insert/update `parallelism:`)
    CP->>FS: write patched workflow files
    CP-->>CLI: return applied-fixes summary
    CLI-->>U: print fixes + regen/validate prompt
  else mismatches & fix==false
    CP-->>CLI: throw error with instruction to rerun with --fix
    CLI-->>U: display error/instructions
  else no mismatches
    CP-->>CLI: success (no changes)
    CLI-->>U: success message
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yann/autofix-parallelism-command

📜 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 0dc8429 and 1c793c7.

📒 Files selected for processing (1)
  • scripts/get-template.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • scripts/get-template.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • scripts/get-template.ts
🧬 Code graph analysis (1)
scripts/get-template.ts (2)
code/lib/cli-storybook/src/sandbox-templates.ts (2)
  • Cadence (18-18)
  • allTemplates (824-828)
scripts/task.ts (2)
  • TaskKey (106-106)
  • tasks (82-105)
🪛 ast-grep (0.39.6)
scripts/get-template.ts

[warning] 196-196: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(^\\s*-\\s+${job}:\\s*$, 'm')
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

nx-cloud bot commented Oct 9, 2025

View your CI Pipeline Execution ↗ for commit e78edc0

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 46s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-13 13:06:50 UTC

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a47e297 and 0dc8429.

📒 Files selected for processing (1)
  • scripts/get-template.ts (7 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to ESLint and Prettier rules across all JS/TS source files

Files:

  • scripts/get-template.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode

Files:

  • scripts/get-template.ts
🧬 Code graph analysis (1)
scripts/get-template.ts (2)
code/lib/cli-storybook/src/sandbox-templates.ts (2)
  • Cadence (18-18)
  • allTemplates (824-828)
scripts/task.ts (2)
  • TaskKey (106-106)
  • tasks (82-105)
🪛 ast-grep (0.39.6)
scripts/get-template.ts

[warning] 196-196: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(^\\s*-\\s+${job}:\\s*$, 'm')
Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html

(regexp-from-variable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Danger JS
  • GitHub Check: get-branch
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest

yannbf and others added 2 commits October 13, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:normal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants