diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae703d..e558cdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [Unreleased] ### Fixed * Drop support for Ruby 3.1 and 3.2, Rails 7.0 +* Capistrano: deployment should continue even if cleanup cannot delete files ## 7.3.6 / 2026-01-13 ### Added diff --git a/lib/ndr_dev_support/capistrano/restart.rb b/lib/ndr_dev_support/capistrano/restart.rb index 5ee2c08..223c2c0 100644 --- a/lib/ndr_dev_support/capistrano/restart.rb +++ b/lib/ndr_dev_support/capistrano/restart.rb @@ -5,5 +5,15 @@ # The tmp/ directory should be shared, so this affects all prior deployments run "touch #{shared_path}/tmp/restart.txt" end + + desc <<~DESC + Clean up old releases. Overrides the default deploy:cleanup but without blocking \ + subsequent tasks if cleanup fails (e.g. because of locked files or permissions issues). + DESC + task :cleanup, except: { no_release: true } do + count = fetch(:keep_releases, 5).to_i + try_sudo "ls -1dt #{releases_path}/* | tail -n +#{count + 1} | #{try_sudo} xargs -r rm -rf " \ + "|| echo 'cap deploy:cleanup failed - continuing, but check permissions.' >&2" + end end end