Skip to content

feat: CXSPA-13564 auto feature toggle migration#21667

Open
StanislavSukhanov wants to merge 13 commits into
developfrom
feat/CXSPA-13564-auto-feature-toggle-migration
Open

feat: CXSPA-13564 auto feature toggle migration#21667
StanislavSukhanov wants to merge 13 commits into
developfrom
feat/CXSPA-13564-auto-feature-toggle-migration

Conversation

@StanislavSukhanov

@StanislavSukhanov StanislavSukhanov commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

CXSPA-13564 — Auto-add feature toggle migration entry on release

What does this PR do?

Automates two things that previously required manual steps on every Spartacus release:

  1. ng update migration — When a customer runs ng update @spartacus/schematics, outdated feature toggles in their provideFeatureToggles({...}) are automatically commented out with a // [REMOVED] marker, preventing TypeScript "does not exist in type" errors after upgrading.

  2. Auto-insertion of the migrations.json entry — A new npm run manage-migrations script (invoked from minor-release.yml) automatically upserts the migration entry for the current PUBLISHING_VERSION on every release. No manual edit of migrations.json needed.


Changes

core-libs/schematics/src/shared/utils/update-feature-toggles.ts (new)

The ng update migration logic:

  • Reads FeatureTogglesInterface from the installed node_modules/@spartacus/core/types/spartacus-core.d.ts to get valid toggle names
  • Finds the customer's spartacus-features.module.ts (checks common locations, falls back to tree walk)
  • Comments out any provideFeatureToggles({...}) key not present in the interface, prefixing it with // [REMOVED]
  • Handles multiple provideFeatureToggles({...}) blocks in the same file
  • Matches double-quoted, single-quoted, and unquoted toggle keys

core-libs/schematics/src/shared/utils/update-feature-toggles_spec.ts (new)

Full unit test coverage calling migrate() directly (no dependency on a committed migrations.json entry):

  • Unknown toggles commented out with [REMOVED]
  • All-valid and partial toggle sets leave the file unchanged
  • Graceful skips: missing interface file, missing module file, no provideFeatureToggles call
  • Alternative module locations (src/app/spartacus-features.module.ts)
  • Indentation preservation on commented lines

tools/config/manage-migrations.ts (new)

Standalone script that keeps migrations.json in sync with PUBLISHING_VERSION:

  • Check mode (npm run config:check-migrations): fails with a clear message if the entry for the current minor is missing or has the wrong version
  • Fix mode (npm run manage-migrations): upserts the entry — creates it if absent, updates version in-place if a same-minor entry exists with a different patch/pre-release
  • Key is minor-scoped (00-migration-v{major}_{minor}-update-feature-toggles) so patch/pre-release bumps of the same minor update the version rather than creating a duplicate entry

.github/workflows/minor-release.yml (updated)

Added a dedicated step after Run Config Update:

- name: Add feature-toggles migration entry
  run: |
    npm run manage-migrations

manage-migrations runs unconditionally — it handles all cases (create / update / no-op) internally.

package.json (updated)

Added script:

"manage-migrations": "ts-node ./tools/config/manage-migrations.ts --fix"

core-libs/schematics/copy-feature-toggles.js (updated)

Minor: switched require('fs') to require('node:fs') for explicit Node.js built-in resolution.


How the release pipeline uses this

minor-release.yml
  → bumps PUBLISHING_VERSION in tools/config/const.ts
  → runs npm run config:update  (deps, tsconfig, generate:deps — unchanged)
  → runs npm run manage-migrations
      → creates or updates entry in core-libs/schematics/src/migrations/migrations.json
        key:     00-migration-v221121_13-update-feature-toggles
        version: <PUBLISHING_VERSION>
        factory: ../shared/utils/update-feature-toggles#migrate
  → commits and pushes release branch

The migrations.json entry is not committed to the feature branch — it is written at release time. Tests call migrate() directly and do not depend on the entry being present.


results of a test run were successful.
https://github.com/SAP/spartacus/pull/21678/changes#diff-df6132f32d2815c36326f633148f7b1ba428c10716422fede6e73a9f16c78dd8

@StanislavSukhanov StanislavSukhanov requested a review from a team as a code owner June 30, 2026 12:18
@github-actions github-actions Bot marked this pull request as draft June 30, 2026 12:18
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review June 30, 2026 12:18
@github-actions github-actions Bot marked this pull request as draft June 30, 2026 13:59
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review June 30, 2026 14:01
@github-actions

Copy link
Copy Markdown
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions Bot marked this pull request as draft June 30, 2026 14:06
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review June 30, 2026 14:08
@github-actions

Copy link
Copy Markdown
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions Bot marked this pull request as draft June 30, 2026 14:30
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review June 30, 2026 14:31
@github-actions

Copy link
Copy Markdown
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions Bot marked this pull request as draft July 1, 2026 11:43
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review July 1, 2026 11:44
@cypress

cypress Bot commented Jul 1, 2026

Copy link
Copy Markdown

spartacus    Run #53825

Run Properties:  status check passed Passed #53825  •  git commit c3b7aada93 ℹ️: Merge 6870bf9ef2108ac33ae89ca3402c068d7df361e8 into 8b19171a168624ca4f646dbbfc21...
Project spartacus
Branch Review feat/CXSPA-13564-auto-feature-toggle-migration
Run status status check passed Passed #53825
Run duration 04m 33s
Commit git commit c3b7aada93 ℹ️: Merge 6870bf9ef2108ac33ae89ca3402c068d7df361e8 into 8b19171a168624ca4f646dbbfc21...
Committer Stanislav Sukhanov
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 103
View all changes introduced in this branch ↗︎

@github-actions github-actions Bot marked this pull request as draft July 1, 2026 12:37
@StanislavSukhanov StanislavSukhanov marked this pull request as ready for review July 1, 2026 12:43
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.

1 participant