mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Raise if a stage has an invalid name like "deploy"
This commit is contained in:
parent
058621c885
commit
1adf2508bd
5 changed files with 35 additions and 1 deletions
9
features/stage_failure.feature
Normal file
9
features/stage_failure.feature
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Feature: Stage failure
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a test app with the default configuration
|
||||||
|
And a stage file named deploy.rb
|
||||||
|
|
||||||
|
Scenario: Running a task
|
||||||
|
When I run cap "doctor"
|
||||||
|
Then the task fails
|
|
@ -52,3 +52,7 @@ Given(/^a custom task to run in the event of a failure$/) do
|
||||||
safely_remove_file(TestApp.shared_path.join("failed"))
|
safely_remove_file(TestApp.shared_path.join("failed"))
|
||||||
TestApp.copy_task_to_test_app("spec/support/tasks/failed.rake")
|
TestApp.copy_task_to_test_app("spec/support/tasks/failed.rake")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given(/^a stage file named (.+)$/) do |filename|
|
||||||
|
TestApp.write_local_stage_file(filename)
|
||||||
|
end
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
module Capistrano
|
module Capistrano
|
||||||
module DSL
|
module DSL
|
||||||
module Stages
|
module Stages
|
||||||
|
RESERVED_NAMES = %w(deploy doctor install).freeze
|
||||||
|
private_constant :RESERVED_NAMES
|
||||||
|
|
||||||
def stages
|
def stages
|
||||||
Dir[stage_definitions].map { |f| File.basename(f, ".rb") }
|
names = Dir[stage_definitions].map { |f| File.basename(f, ".rb") }
|
||||||
|
assert_valid_stage_names(names)
|
||||||
|
names
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage_definitions
|
def stage_definitions
|
||||||
|
@ -12,6 +17,15 @@ module Capistrano
|
||||||
def stage_set?
|
def stage_set?
|
||||||
!!fetch(:stage, false)
|
!!fetch(:stage, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def assert_valid_stage_names(names)
|
||||||
|
invalid = names.find { |n| RESERVED_NAMES.include?(n) }
|
||||||
|
return if invalid.nil?
|
||||||
|
|
||||||
|
raise t("error.invalid_stage_name", name: invalid, path: stage_config_path.join("#{invalid}.rb"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,7 @@ en = {
|
||||||
bye: "bye"
|
bye: "bye"
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
|
invalid_stage_name: '"%{name}" is a reserved word and cannot be used as a stage. Rename "%{path}" to something else.',
|
||||||
user: {
|
user: {
|
||||||
does_not_exist: "User %{user} does not exists",
|
does_not_exist: "User %{user} does not exists",
|
||||||
cannot_switch: "Cannot switch to user %{user}"
|
cannot_switch: "Cannot switch to user %{user}"
|
||||||
|
|
|
@ -61,6 +61,12 @@ module TestApp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_local_stage_file(filename, config=nil)
|
||||||
|
File.open(test_app_path.join("config/deploy/#{filename}"), "w") do |file|
|
||||||
|
file.write(config) if config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def append_to_deploy_file(config)
|
def append_to_deploy_file(config)
|
||||||
File.open(test_stage_path, "a") do |file|
|
File.open(test_stage_path, "a") do |file|
|
||||||
file.write config + "\n"
|
file.write config + "\n"
|
||||||
|
|
Loading…
Reference in a new issue