Class: Groundskeeper::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/groundskeeper/commands.rb

Overview

Formulas for managing releases and deployments. rubocop:disable Metrics/ClassLength

Constant Summary collapse

RAKEFILE =
File.join(
  File.dirname(__FILE__), "..", "..", "config", "deploy.rb"
)
STAGE =
"stage"
STAGING =
"staging"
PRODUCTION =
"production"
DEFAULT_STAGE =
STAGING
TAG =
"tag"
INITIAL_VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(changelog: nil, console:, git: nil, jira: nil, project: nil, repository: nil, rubygems: nil, sentry: nil, website: nil, version_file:) ⇒ Commands

rubocop:disable Metrics/MethodLength,Metrics/ParameterLists



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/groundskeeper/commands.rb', line 53

def initialize(
  changelog: nil,
  console:,
  git: nil,
  jira: nil,
  project: nil,
  repository: nil,
  rubygems: nil,
  sentry: nil,
  website: nil,
  version_file:
)
  @changelog = changelog
  @console = console
  @git = git
  @jira = jira
  @project = project
  @repository = repository
  @rubygems = rubygems
  @sentry = sentry
  @website = website
  @version_file = version_file
  @did_push_to_remote = false
  @current_step = 1
end

Class Method Details

.build(console) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/groundskeeper/commands.rb', line 23

def self.build(console)
  repository = Repository.new
  project = Project.build(repository.name)
  deploy_url = "https://#{project.full_dns(stage)}"
  website = Website.new(deploy_url)
  sentry = Sentry.build(
    project_name: project.sentry_project,
    version_prefix: repository.name
  )

  new(
    changelog: Changelog.build,
    console: console,
    git: Git.build,
    jira: Jira.build(project.jira_prefix),
    project: project,
    repository: repository,
    rubygems: Rubygems,
    sentry: sentry,
    version_file: RailsVersion.build,
    website: website
  )
end

.stageObject

rubocop:enable Metrics/AbcSize,Metrics/MethodLength



48
49
50
# File 'lib/groundskeeper/commands.rb', line 48

def self.stage
  ENV[STAGE] == PRODUCTION ? PRODUCTION : DEFAULT_STAGE
end

Instance Method Details

#deploy(options = {}) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/groundskeeper/commands.rb', line 140

def deploy(options = {})
  return unrecognized_version unless version_file.exists?
  return unrecognized_tag unless tag_present_in_git?(ENV[TAG])
  return missing_jira_credentials unless jira.credentials?
  return missing_sentry_credentials unless sentry.credentials?
  return unless check_groundskeeper_version

  Executable.verbose = options[:verbose]
  pull_project_details
  ENV["whenever"] = "1" if project.uses_whenever?

  mina "deploy", options
  announce_step "Wait for deployed application to restart"
  update_deployed_issues
  release_version if self.class.stage == PRODUCTION
  add_version_to_sentry
end

#info(options = {}) ⇒ Object

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/groundskeeper/commands.rb', line 81

def info(options = {})
  return unrecognized_version unless version_file.exists?
  return unless check_groundskeeper_version

  Executable.verbose = options[:verbose]
  pull_project_details

  announce_latest_tag
  console.say(
    "version in current branch: " +
    version_file.current_version,
    :yellow
  )
  console.say(
    "tag contained in: #{git.branches_containing_latest_tag}\n\n",
    :yellow
  )
end

#predeploy(options = {}) ⇒ Object

:nocov:



127
128
129
130
131
132
133
134
135
# File 'lib/groundskeeper/commands.rb', line 127

def predeploy(options = {})
  return unrecognized_version unless version_file.exists?
  return unless check_groundskeeper_version

  Executable.verbose = options[:verbose]
  pull_project_details

  mina "predeploy", options
end

#release(options = {}) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/groundskeeper/commands.rb', line 102

def release(options = {})
  is_initial_release = !version_file.exists?

  return missing_jira_credentials unless jira.credentials?
  return unless check_groundskeeper_version
  return unrecognized_version unless version_file.rails?

  version_file.create_initial_version! unless version_file.exists?
  Executable.verbose = options[:verbose]
  pull_project_details

  summarize_recent_commits unless is_initial_release
  ask_next_version(is_initial_release)
  checkout_new_branch
  update_version_file
  update_changelog
  commit_changes_and_tag(is_initial_release)
  ask_create_jira_version
  ask_push
  ask_add_version_to_jira_issues unless is_initial_release
end