Skip to content

refactor: make shareable components abstract - #61

Merged
bepri merged 11 commits into
mainfrom
work/refactor-common-components/CRAFT-5201
Jun 23, 2026
Merged

refactor: make shareable components abstract#61
bepri merged 11 commits into
mainfrom
work/refactor-common-components/CRAFT-5201

Conversation

@bepri

@bepri bepri commented Jun 16, 2026

Copy link
Copy Markdown
Member

This PR prepares for the creation of other Node-based Craft Actions by refactoring the pieces of Rockcraft's pack action that seemed shareable out into "common" modules. I tried my best to keep the task focused and break up the commits, but frankly this was just a very loud PR. Sorry.

I made a temporary repository with two CI runs to validate this: https://github.com/bepri/test-actions/actions

The first run was the simplest case, just rockcraft init with a standard, optionless call to this action. The second run used an unmaintained base and customized many of the options.

@bepri bepri self-assigned this Jun 16, 2026
@bepri bepri changed the title refactor: move shareable methods into tools file refactor: make shareable components abstract Jun 16, 2026
Comment thread src/craft-builder.ts
Comment thread src/pack-action.ts
Comment thread src/rockcraft-pack.ts
Comment thread tests/craft-builder.test.ts
@bepri
bepri force-pushed the work/refactor-common-components/CRAFT-5201 branch from b116065 to c86b9cb Compare June 16, 2026 15:22
Comment thread scripts/pack.mjs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Rockcraft pack action to extract reusable, tool-agnostic building blocks (a shared CraftBuilder base class and a shared runPackAction/input reader), in preparation for additional Node-based Craft Actions.

Changes:

  • Introduced an abstract CraftBuilder (common pack/test execution, artifact discovery, pro/verbosity handling) and updated RockcraftBuilder to extend it.
  • Added a shared pack-action helper (readBaseInputs, runPackAction) and migrated rockcraft-pack-action to use it.
  • Generalized tool capability checks (haveFlag, haveSubcommand) and updated/added unit tests accordingly; simplified bundling via scripts/pack.mjs.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/tools.test.ts Updates tests to cover ensureCraftTool, haveFlag, and haveSubcommand.
tests/rockcraft-pack.test.ts Refactors tests to align with the new CraftBuilder-based implementation and focuses on Rockcraft-specific behavior (--ignore).
tests/pack-action.test.ts Adds unit tests for the new shared readBaseInputs and runPackAction.
tests/craft-builder.test.ts Adds comprehensive tests for the new CraftBuilder behavior (pack/test flow, flags, artifact discovery).
src/tools.ts Generalizes Rockcraft-specific helpers into haveFlag, haveSubcommand, and ensureCraftTool.
src/rockcraft-pack.ts Converts RockcraftBuilder into a CraftBuilder subclass and moves shared logic to the base class.
src/rockcraft-pack-action.ts Switches the action entrypoint to the new shared pack-action helpers (but currently instantiates the builder at module scope).
src/pack-action.ts Adds shared input parsing and standardized pack+artifact output logic.
src/craft-builder.ts Introduces the abstract shared builder implementation used by tool-specific builders.
scripts/pack.mjs Adds a dedicated esbuild bundling script.
package.json Updates pack script to use scripts/pack.mjs.
dist/rockcraft-pack-action/index.js Updates the bundled output to reflect the refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/rockcraft-pack-action.ts Outdated
@steinbro
steinbro requested review from smethnani and tigarmo June 17, 2026 13:54

@smethnani smethnani left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks great!

Comment thread dist/rockcraft-pack/index.js

@alesancor1 alesancor1 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.

Many comments, but honestly the refactor is really good.

My comments are mostly regarding the repository structure and file names. The logic itself looks good to me, fantastic work!

Afaict none of the suggestions below would alter the current behaviour of the action, since it's just moving stuff around and removing some unnecessary checks:

Comment thread dist/rockcraft-pack/index.js
Comment thread scripts/pack.mjs
Comment thread scripts/pack.mjs Outdated
Comment thread src/craft-builder.ts
Comment thread src/craft-builder.ts Outdated
Comment thread src/craft-builder.ts
Comment thread src/rockcraft-pack-action.ts Outdated
Comment thread src/rockcraft-pack.ts
Comment thread src/tools.ts
Comment thread tests/craft-builder.test.ts

@alesancor1 alesancor1 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.

LGTM!

Looking forward to see more actions coming in once the new structure is in place!

@bepri
bepri merged commit 43e7369 into main Jun 23, 2026
7 checks passed
@bepri
bepri deleted the work/refactor-common-components/CRAFT-5201 branch June 23, 2026 13:14
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.

5 participants