From c174c8cf182bf639a5cf5d2409423efe0a0ff24a Mon Sep 17 00:00:00 2001 From: William Lee Date: Thu, 3 Oct 2024 14:30:43 +0100 Subject: [PATCH] Add epi_deploy:set_branch task for manually set the Capistrano :branch variable on deployment --- lib/capistrano/epi_deploy.rb | 2 +- lib/capistrano/tasks/branches.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lib/capistrano/tasks/branches.rb diff --git a/lib/capistrano/epi_deploy.rb b/lib/capistrano/epi_deploy.rb index 8ad9ba3..3be9d81 100644 --- a/lib/capistrano/epi_deploy.rb +++ b/lib/capistrano/epi_deploy.rb @@ -1 +1 @@ -load File.join(File.dirname(__FILE__), 'tasks', 'multi_customers.rb') \ No newline at end of file +Dir.glob(File.join(File.dirname(__FILE__), 'tasks', '*.rb')).each { |f| require f } \ No newline at end of file diff --git a/lib/capistrano/tasks/branches.rb b/lib/capistrano/tasks/branches.rb new file mode 100644 index 0000000..d1664cb --- /dev/null +++ b/lib/capistrano/tasks/branches.rb @@ -0,0 +1,21 @@ +if File.exist?('config/initializers/version.rb') + require_relative 'config/initializers/version' +end + +namespace :epi_deploy do + task :set_branch do + branch = if ENV['BRANCH'] + ENV['BRANCH'] + elsif Object.const_defined?('LATEST_RELEASE_TAG') + LATEST_RELEASE_TAG + end + + if branch.nil? + raise 'Cannot determine commit to deploy as BRANCH environment variable is not set and LATEST_RELEASE_TAG constant in version.rb could not be found' + end + + set :branch, branch + end +end + +before 'deploy:starting', 'epi_deploy:set_branch'