1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Merge pull request #1811 from markri/master

Fixes Bug #1810 removal of old releases
This commit is contained in:
Matt Brictson 2016-12-07 06:52:36 -08:00 committed by GitHub
commit 199b7854ac
3 changed files with 7 additions and 2 deletions

View file

@ -8,6 +8,8 @@ https://github.com/capistrano/capistrano/compare/v3.7.0.beta1...HEAD
* Your contribution here! * Your contribution here!
* Fix the removal of old releases `deploy:cleanup`. Logic is changed because of unreliable modification times on folders. Removal of directories is now decided by sorting on folder names (name is generated from current datetime format YmdHis). Cleanup is skipped, and a warning is given when a folder name is in a different format.
## `3.7.0.beta1` (2016-11-02) ## `3.7.0.beta1` (2016-11-02)
https://github.com/capistrano/capistrano/compare/v3.6.1...v3.7.0.beta1 https://github.com/capistrano/capistrano/compare/v3.6.1...v3.7.0.beta1

View file

@ -12,6 +12,7 @@ en = {
written_file: "create %{file}", written_file: "create %{file}",
question: "Please enter %{key} (%{default_value}): ", question: "Please enter %{key} (%{default_value}): ",
keeping_releases: "Keeping %{keep_releases} of %{releases} deployed releases on %{host}", keeping_releases: "Keeping %{keep_releases} of %{releases} deployed releases on %{host}",
skip_cleanup: "Skipping cleanup of old releases on %{host}; unexpected foldername found (should be timestamp)",
no_old_releases: "No old releases (keeping newest %{keep_releases}) on %{host}", no_old_releases: "No old releases (keeping newest %{keep_releases}) on %{host}",
linked_file_does_not_exist: "linked file %{file} does not exist on %{host}", linked_file_does_not_exist: "linked file %{file} does not exist on %{host}",
cannot_rollback: "There are no older releases to rollback to", cannot_rollback: "There are no older releases to rollback to",

View file

@ -148,8 +148,10 @@ namespace :deploy do
desc "Clean up old releases" desc "Clean up old releases"
task :cleanup do task :cleanup do
on release_roles :all do |host| on release_roles :all do |host|
releases = capture(:ls, "-xtr", releases_path).split releases = capture(:ls, "-x", releases_path).split
if releases.count >= fetch(:keep_releases) if !(releases.all? { |e| /^\d{14}$/ =~ e })
warn t(:skip_cleanup, host: host.to_s)
elsif releases.count >= fetch(:keep_releases)
info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: releases.count) info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: releases.count)
directories = (releases - releases.last(fetch(:keep_releases))) directories = (releases - releases.last(fetch(:keep_releases)))
if directories.any? if directories.any?