fix: only set root config version and commit if migrations ran#2513
fix: only set root config version and commit if migrations ran#2513
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the create-plugin migration runner to avoid writing/committing the root .config/.cprc.json version when there are no migrations to execute, reducing no-op diffs and CI noise during create-plugin update.
Changes:
- Guard
.config/.cprc.jsonversion updates behindmigrations.length > 0. - Skip the version-update git commit when there are no migrations to run.
| // Only set the version in the config file if there were migrations to run. | ||
| if (migrations.length > 0) { | ||
| setRootConfig({ version: CURRENT_APP_VERSION }); | ||
|
|
||
| if (options.commitEachMigration) { | ||
| await gitCommitNoVerify(`chore: update .config/.cprc.json to version ${CURRENT_APP_VERSION}.`); | ||
| if (options.commitEachMigration) { | ||
| await gitCommitNoVerify(`chore: update .config/.cprc.json to version ${CURRENT_APP_VERSION}.`); | ||
| } | ||
| } |
There was a problem hiding this comment.
This new conditional introduces an untested behavior change: when migrations.length === 0, the root config version is no longer updated and the version-update commit is skipped. There are existing unit tests for runMigrations in this package; please add coverage for the empty-migrations case (including with commitEachMigration: true) to lock in the intended behavior.
| const migrationListBody = | ||
| migrationList.length > 0 ? output.bulletList(migrationList) : ['No migrations to run. Exiting.']; | ||
|
|
There was a problem hiding this comment.
The log message says "No migrations to run. Exiting." but runMigrations doesn’t actually early-return at that point (it just finishes naturally). Consider either returning immediately when migrations.length === 0 or changing the message to avoid implying an explicit exit, so future logic added after the loop won’t be misleading.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
What this PR does / why we need it:
Currently if create-plugin update doesn't run any migrations it still updates the version in the cprc.json file. This creates unnecessary noise both locally and if update runs via CI. This PR addresses this by only updating the cprc.json file if any migrations ran.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
📦 Published PR as canary version:
Canary Versions✨ Test out this PR locally via:
npm install @grafana/create-plugin@7.0.4-canary.2513.22728705812.0 # or yarn add @grafana/create-plugin@7.0.4-canary.2513.22728705812.0