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"
SSH_USERNAME =
"deploy"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

rubocop:disable Metrics/MethodLength,Metrics/ParameterLists



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/groundskeeper/commands.rb', line 60

def initialize(
  console:, version_file:,
  bitbucket: nil,
  git: nil,
  jira: nil,
  project: nil,
  repository: nil,
  rubygems: nil,
  sentry: nil,
  slack: nil,
  ssh: nil,
  website: nil
)
  @console = console
  @bitbucket = bitbucket
  @git = git
  @jira = jira
  @project = project
  @repository = repository
  @rubygems = rubygems
  @sentry = sentry
  @slack = slack
  @ssh = ssh
  @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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/groundskeeper/commands.rb', line 25

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

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

.stageObject

rubocop:enable Metrics/AbcSize,Metrics/MethodLength



55
56
57
# File 'lib/groundskeeper/commands.rb', line 55

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



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/groundskeeper/commands.rb', line 150

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 missing_slack_credentials unless slack.credentials?
  return groundskeeper_outdated unless check_groundskeeper_version
  return unable_to_ssh unless ssh.can_connect?

  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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/groundskeeper/commands.rb', line 91

def info(options = {})
  return unrecognized_version unless version_file.exists?
  return groundskeeper_outdated 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:



137
138
139
140
141
142
143
144
145
# File 'lib/groundskeeper/commands.rb', line 137

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

  Executable.verbose = options[:verbose]
  pull_project_details

  mina "predeploy", options
end

#release(options = {}) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/groundskeeper/commands.rb', line 111

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

  return missing_jira_credentials unless jira.credentials?
  return missing_bitbucket_credentials unless bitbucket.credentials?
  return groundskeeper_outdated 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
  say_next_version(is_initial_release)
  checkout_new_branch
  update_version_file
  commit_changes_and_tag(is_initial_release)
  create_jira_version
  push
  add_version_to_jira_issues unless is_initial_release
  create_pr
end