diff --git a/.changeset/twenty-teeth-pay.md b/.changeset/twenty-teeth-pay.md new file mode 100644 index 0000000..39d97a8 --- /dev/null +++ b/.changeset/twenty-teeth-pay.md @@ -0,0 +1,5 @@ +--- +"debarrel": minor +--- + +Multiple workflows in debarreling codemod diff --git a/codemods/debarrel/codemod.yaml b/codemods/debarrel/codemod.yaml index 4434cd8..21dc09f 100644 --- a/codemods/debarrel/codemod.yaml +++ b/codemods/debarrel/codemod.yaml @@ -5,7 +5,6 @@ version: "0.6.1" description: "Debarrel JS/TS codebases. Removing barrel files and replacing import statements." author: "Mo Mohebifar " license: "MIT" -workflow: "workflow.yaml" repository: https://github.com/codemod/useful-codemods targets: @@ -18,3 +17,13 @@ registry: visibility: "public" capabilities: ["fs"] + +workflows: + - name: regular + description: "Just debarrel the whole codebase at once!" + default: true + path: workflow.yaml + - name: sharded + description: "A sharded version of the main workflow, which can be used to break down the migration into parallel tasks." + default: false + path: workflow-sharded.yaml diff --git a/codemods/debarrel/workflow-sharded.yaml b/codemods/debarrel/workflow-sharded.yaml new file mode 100644 index 0000000..34ed5ce --- /dev/null +++ b/codemods/debarrel/workflow-sharded.yaml @@ -0,0 +1,122 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/codemod/codemod/refs/heads/main/schemas/workflow.json + +version: "1" + +state: + schema: + shards: + type: array + items: + type: object + properties: + name: + type: string + team: + type: string + directory: + type: string + _meta_shard: + type: number + _meta_files: + type: array + items: + type: string + +params: + schema: + shardingMethod: + name: "Sharding Method" + description: "The method to use for sharding" + type: string + default: "codeowner" + oneOf: + - type: string + enum: + - "codeowner" + - "directory" + shardingDirectoryTarget: + name: "Sharding Directory Target" + description: "When sharding by directory, the directory to target for the codemod" + type: string + default: "./src" + pr_size: + name: "PR Size" + description: "The maximum number of files to include in each PR" + type: number + default: 20 + +nodes: + - id: evaluate-shards + name: Evaluate Shards + trigger: + type: automatic + steps: + - name: "Evaluate shards by directory" + if: params.shardingMethod == "directory" + shard: + method: + type: directory + max_files_per_shard: ${{ params.pr_size }} + target: ${{ params.shardingDirectoryTarget }} + output_state: shards + js-ast-grep: + js_file: scripts/codemod.ts + language: "tsx" + semantic_analysis: workspace + include: + - "**/*.ts" + - "**/*.tsx" + - "**/*.jsx" + - "**/*.js" + - "**/*.mjs" + - name: "Evaluate shards by codeowner" + if: params.shardingMethod == "codeowner" + shard: + method: + type: codeowner + max_files_per_shard: ${{ params.pr_size }} + target: "." + output_state: shards + js-ast-grep: + js_file: scripts/codemod.ts + language: "tsx" + semantic_analysis: workspace + include: + - "**/*.ts" + - "**/*.tsx" + - "**/*.jsx" + - "**/*.js" + - "**/*.mjs" + + - id: apply-transforms + name: Apply AST Transformations + trigger: + type: manual + depends_on: + - evaluate-shards + strategy: + type: matrix + from_state: shards + pull_request: + title: "[DRAFT] refactor: Run debarrel shard ${{ matrix.name }}" + body: "This pull request runs debarrel for shard ${{ matrix.name }}." + draft: true + steps: + - id: debarrel-js-ast-grep + name: "Debarrel: rewrite imports and clean up barrels" + js-ast-grep: + js_file: scripts/codemod.ts + language: "tsx" + semantic_analysis: workspace + + - id: install-skill + name: Install Skill + trigger: + type: manual + depends_on: + - apply-transforms + steps: + - name: "Install debarrel skill" + install-skill: + package: "debarrel" + path: "./agents/skill/SKILL.md" diff --git a/codemods/debarrel/workflow.yaml b/codemods/debarrel/workflow.yaml index 34ed5ce..b852789 100644 --- a/codemods/debarrel/workflow.yaml +++ b/codemods/debarrel/workflow.yaml @@ -2,105 +2,9 @@ version: "1" -state: - schema: - shards: - type: array - items: - type: object - properties: - name: - type: string - team: - type: string - directory: - type: string - _meta_shard: - type: number - _meta_files: - type: array - items: - type: string - -params: - schema: - shardingMethod: - name: "Sharding Method" - description: "The method to use for sharding" - type: string - default: "codeowner" - oneOf: - - type: string - enum: - - "codeowner" - - "directory" - shardingDirectoryTarget: - name: "Sharding Directory Target" - description: "When sharding by directory, the directory to target for the codemod" - type: string - default: "./src" - pr_size: - name: "PR Size" - description: "The maximum number of files to include in each PR" - type: number - default: 20 - nodes: - - id: evaluate-shards - name: Evaluate Shards - trigger: - type: automatic - steps: - - name: "Evaluate shards by directory" - if: params.shardingMethod == "directory" - shard: - method: - type: directory - max_files_per_shard: ${{ params.pr_size }} - target: ${{ params.shardingDirectoryTarget }} - output_state: shards - js-ast-grep: - js_file: scripts/codemod.ts - language: "tsx" - semantic_analysis: workspace - include: - - "**/*.ts" - - "**/*.tsx" - - "**/*.jsx" - - "**/*.js" - - "**/*.mjs" - - name: "Evaluate shards by codeowner" - if: params.shardingMethod == "codeowner" - shard: - method: - type: codeowner - max_files_per_shard: ${{ params.pr_size }} - target: "." - output_state: shards - js-ast-grep: - js_file: scripts/codemod.ts - language: "tsx" - semantic_analysis: workspace - include: - - "**/*.ts" - - "**/*.tsx" - - "**/*.jsx" - - "**/*.js" - - "**/*.mjs" - - id: apply-transforms name: Apply AST Transformations - trigger: - type: manual - depends_on: - - evaluate-shards - strategy: - type: matrix - from_state: shards - pull_request: - title: "[DRAFT] refactor: Run debarrel shard ${{ matrix.name }}" - body: "This pull request runs debarrel for shard ${{ matrix.name }}." - draft: true steps: - id: debarrel-js-ast-grep name: "Debarrel: rewrite imports and clean up barrels" @@ -108,15 +12,3 @@ nodes: js_file: scripts/codemod.ts language: "tsx" semantic_analysis: workspace - - - id: install-skill - name: Install Skill - trigger: - type: manual - depends_on: - - apply-transforms - steps: - - name: "Install debarrel skill" - install-skill: - package: "debarrel" - path: "./agents/skill/SKILL.md"