Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: spree:upgrade DRY_RUN lists the steps a real run executes (#14697)

Damian Legawiecf43bed2cdbfb
diff --git a/.changeset/cli-upgrade-next-steps.md b/.changeset/cli-upgrade-next-steps.md
new file mode 100644
index 0000000000..47bde9dcc1
--- /dev/null
+++ b/.changeset/cli-upgrade-next-steps.md
@@ -0,0 +1,5 @@
+---
+"@spree/cli": patch
+---
+
+`spree upgrade` no longer reminds you to schedule `Spree::StockReservations::ExpireJob`, a Spree 5.5 step that every 5.6 installation has already done. The "Next steps" panel now points you at your scheduled jobs and behavior changes in the upgrade guide and links to a page that exists. `spree upgrade --plan` now lists the same data backfills a real run executes after the Spree gems are bumped, instead of nothing.
diff --git a/packages/cli/src/commands/upgrade.ts b/packages/cli/src/commands/upgrade.ts
index f09207abc7..8936ef8235 100644
--- a/packages/cli/src/commands/upgrade.ts
+++ b/packages/cli/src/commands/upgrade.ts
@@ -13,7 +13,10 @@ export function registerUpgradeCommand(program: Command): void {
program
.command('upgrade')
.description('Walk through a Spree version upgrade (bundle + migrate + spree:upgrade)')
- .option('--plan', 'print the plan via spree:upgrade DRY_RUN=1; skip bundle + migrate')
+ .option(
+ '--plan',
+ 'list the data backfills a run would execute — for the installed Spree version, or the --to version (DRY_RUN=1); skip bundle + migrate',
+ )
.option('--step <id>', 'run a single rake step by id (skips bundle + migrate)')
.option(
'--to <version>',
@@ -183,12 +186,12 @@ function printPostUpgradeReminder(projectDir: string): void {
`The manifest only ran ${pc.bold('rake-automatable')} steps.`,
'',
"Don't forget the manual parts from the upgrade doc:",
- ` ${pc.dim('- Schedule Spree::StockReservations::ExpireJob (cron)')}`,
+ ` ${pc.dim('- Compare your scheduled jobs (config/recurring.yml) with the upgrade guide')}`,
` ${pc.dim(`- ${sdkAdvisory(projectDir)}`)}`,
- ` ${pc.dim('- Review behavior changes (cart, availability, payment-method types)')}`,
+ ` ${pc.dim('- Review the behavior changes listed in the upgrade guide')}`,
` ${pc.dim('- Audit custom decorators against renamed APIs')}`,
'',
- `Full checklist: ${pc.cyan('https://spreecommerce.org/docs/developer/upgrades')}`,
+ `Full checklist: ${pc.cyan('https://spreecommerce.org/docs/developer/upgrades/quickstart')}`,
].join('\n'),
'Next steps',
)
diff --git a/spree/core/lib/tasks/upgrade.rake b/spree/core/lib/tasks/upgrade.rake
index 5305e4acf3..e29bb96841 100644
--- a/spree/core/lib/tasks/upgrade.rake
+++ b/spree/core/lib/tasks/upgrade.rake
@@ -13,7 +13,7 @@
#
# Usage:
# bundle exec rake spree:upgrade # walk all eligible manifests
-# bundle exec rake spree:upgrade DRY_RUN=1 # print plan, run nothing
+# bundle exec rake spree:upgrade DRY_RUN=1 # print the steps a run would execute, run nothing
# bundle exec rake spree:upgrade STEP=channels # run one step by id (any manifest)
# bundle exec rake spree:upgrade TO=5.4 # cap the walk at this version
#
@@ -72,10 +72,9 @@ module Spree
# rendering, invocation) stay separable and the plan can be inspected
# without execution.
class Runner
- attr_reader :target_version, :step_id, :dry_run, :target_explicit
+ attr_reader :target_version, :step_id, :dry_run
def initialize(target_version: nil, step_id: nil, dry_run: false)
- @target_explicit = !target_version.nil?
@target_version = target_version || Spree::Upgrade.installed_minor_version
@step_id = step_id
@dry_run = dry_run
@@ -98,36 +97,22 @@ module Spree
private
- # In plan-mode without explicit TO, show manifests ahead of the installed
- # version — the path the operator is about to walk. Otherwise filter to
- # manifests whose `to` is ≤ target.
+ # Plan mode selects exactly what a real run executes, so a dry run after
+ # bumping the gem lists every backfill the upgrade is about to perform.
def eligible_manifests
Spree::Upgrade.available_manifests
- .select { |manifest| manifest_eligible?(manifest) }
+ .select { |manifest| Spree::Upgrade.compare(manifest[:to], target_version) <= 0 }
.map { |entry| load_manifest_yaml(entry) }
end
- def manifest_eligible?(manifest)
- if dry_run && !target_explicit
- Spree::Upgrade.compare(manifest[:from], Spree::Upgrade.installed_minor_version) >= 0
- else
- Spree::Upgrade.compare(manifest[:to], target_version) <= 0
- end
- end
-
def load_manifest_yaml(entry)
YAML.safe_load_file(File.join(entry[:dir], 'manifest.yml'))
end
def run_full_walk(manifests)
total_steps = manifests.sum { |m| m['steps'].size }
- reported_target = if dry_run && !target_explicit
- manifests.map { |m| m['to'] }.compact.max_by { |v| Spree::Upgrade.version_parts(v) } || target_version
- else
- target_version
- end
puts
- puts " Walking #{manifests.size} manifest(s), #{total_steps} step(s) total. Target: Spree #{reported_target}."
+ puts " Walking #{manifests.size} manifest(s), #{total_steps} step(s) total. Target: Spree #{target_version}."
manifests.each do |manifest|
print_manifest_header(manifest)
diff --git a/spree/core/spec/lib/tasks/upgrade_spec.rb b/spree/core/spec/lib/tasks/upgrade_spec.rb
new file mode 100644
index 0000000000..1b23cfc9f7
--- /dev/null
+++ b/spree/core/spec/lib/tasks/upgrade_spec.rb
@@ -0,0 +1,76 @@
+require 'spec_helper'
+require 'rake'
+
+describe 'spree:upgrade' do
+ before(:all) do
+ Rake::Task.define_task(:environment)
+ load Spree::Core::Engine.root.join('lib', 'tasks', 'upgrade.rake')
+ end
+
+ let(:manifests) do
+ Spree::Upgrade.available_manifests.map do |entry|
+ YAML.safe_load_file(File.join(entry[:dir], 'manifest.yml'))
+ end
+ end
+
+ def step_ids_through(version)
+ manifests
+ .select { |manifest| Spree::Upgrade.compare(manifest['to'], version) <= 0 }
+ .flat_map { |manifest| manifest['steps'].map { |step| step['id'] } }
+ end
+
+ def run_upgrade(**options)
+ output = StringIO.new
+ $stdout = output
+ Spree::Upgrade::Runner.new(**options).call
+ output.string
+ ensure
+ $stdout = STDOUT
+ end
+
+ before { allow(Spree).to receive(:version).and_return('6.0.0') }
+
+ describe 'dry run without a target version' do
+ it 'lists every backfill up to the installed version, the same set a real run executes' do
+ output = run_upgrade(dry_run: true)
+
+ expect(output).to include('Spree 5.4 → 5.5', 'Spree 5.5 → 5.6', 'Spree 5.6 → 6.0')
+ expect(output).to include('Target: Spree 6.0.')
+ step_ids_through('6.0').each { |step_id| expect(output).to include("[#{step_id}]") }
+ end
+
+ it 'executes nothing' do
+ expect(Rake::Task).not_to receive(:[])
+
+ expect(run_upgrade(dry_run: true)).to include('dry run — nothing executed')
+ end
+ end
+
+ describe 'dry run with a target version' do
+ it 'caps the plan at that version' do
+ output = run_upgrade(dry_run: true, target_version: '5.5')
+
+ expect(output).to include('Spree 5.4 → 5.5', 'Target: Spree 5.5.')
+ expect(output).not_to include('Spree 5.5 → 5.6', 'Spree 5.6 → 6.0')
+ end
+ end
+
+ describe 'real run' do
+ it 'invokes every step the dry run listed' do
+ invoked_tasks = []
+ allow(Rake::Task).to receive(:task_defined?).and_return(true)
+ allow(Rake::Task).to receive(:[]) do |task_name|
+ instance_double(Rake::Task, reenable: nil).tap do |task|
+ allow(task).to receive(:invoke) { invoked_tasks << task_name }
+ end
+ end
+
+ run_upgrade
+
+ expected_tasks = manifests
+ .select { |manifest| Spree::Upgrade.compare(manifest['to'], '6.0') <= 0 }
+ .flat_map { |manifest| manifest['steps'].map { |step| step['task'] } }
+ expect(invoked_tasks).to eq(expected_tasks)
+ end
+ end
+end