Class: FaHarnessTools::CheckForwardDeploy
- Inherits:
-
Object
- Object
- FaHarnessTools::CheckForwardDeploy
- Defined in:
- lib/fa-harness-tools/check_forward_deploy.rb
Overview
Checks if the revision to deploy is ahead of the deployed revision, a forward deploy. The currently deployed revision is an ancestor of the revision to deploy.
In order to work out what is currently deployed it checks for tags with the configured tag_prefix, the newest of those is considered the current version. If there are none of those tags at all it will allow, to avoid creating an un-passable check!
Instance Method Summary collapse
-
#initialize(client:, context:, tag_prefix:) ⇒ CheckForwardDeploy
constructor
A new instance of CheckForwardDeploy.
- #verify? ⇒ Boolean
Constructor Details
#initialize(client:, context:, tag_prefix:) ⇒ CheckForwardDeploy
Returns a new instance of CheckForwardDeploy.
12 13 14 15 16 17 18 19 20 |
# File 'lib/fa-harness-tools/check_forward_deploy.rb', line 12 def initialize(client:, context:, tag_prefix:) @client = client @context = context @tag_prefix = tag_prefix @logger = CheckLogger.new( name: "Check forward deploy", description: "Only allow deployments that are newer than what's currently deployed", ) end |
Instance Method Details
#verify? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fa-harness-tools/check_forward_deploy.rb', line 22 def verify? @logger.start @logger.context_info(@client, @context) current_tag = @client.last_deploy_tag( prefix: @tag_prefix, environment: @context.environment) if current_tag.nil? # If no previous deploys we need to let it deploy otherwise it will # never get past this check! @logger.info "no #{@tag_prefix} tag was found, so this must be the first deployment" return @logger.pass("this is the first recorded deployment so is permitted") end @logger.info("the most recent deployment is #{current_tag[:name]}") current_deployed_rev = current_tag[:commit][:sha] rev = @context.new_commit_sha @logger.info("which means the currently deployed commit is #{current_deployed_rev}") if @client.is_ancestor_of?(current_deployed_rev, rev) @logger.pass "the commit being deployed is more recent than the currently deployed commit" else @logger.fail "the commit being deployed is before the currently deployed commit, so would revert changes" end end |