Skip to content

Commit 7b84fbf

Browse files
nicoleribrsmontero
authored andcommitted
M #-: Fix cleanup of old builds on publish.rb (#3275)
(cherry picked from commit 8870ec5)
1 parent 76a24f3 commit 7b84fbf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

publish/publish.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,21 @@ def error(rc)
9090
" echo \"#{branch_symlink_path} is not a symlink\" >&2'")
9191
error(rc)
9292

93+
# cleanup old versions
94+
95+
rc = run("ssh #{ssh_op} #{host} 'find #{host_path} -maxdepth 1 -type d -name \"#{branch_dir}.*\" -printf \"%f\\n\" | sort'")
96+
error(rc)
97+
9398
builds = rc[0].split
9499

95-
exit(0) if builds.length <= 3
100+
puts "Total builds found: #{builds.length}"
101+
puts "Builds: #{builds.join("\n")}"
96102

97-
builds = builds[0..-3] # Keep two latest ones
103+
exit(0) if builds.length <= 2
98104

99-
builds.each do |build|
100-
run("ssh #{ssh_op} #{host} rm -rf #{host_path}/#{build}")
105+
# List all builds except the two most recent
106+
old_builds = builds[0...-2]
107+
old_builds.each do |build|
108+
puts "Removing old build folder: #{build}"
109+
run("ssh #{ssh_op} #{host} rm -rf #{host_path}/#{build}")
101110
end

0 commit comments

Comments
 (0)