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"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

rubocop:disable Metrics/MethodLength,Metrics/ParameterLists



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

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

Class Method Details

.build(console) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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
48
49
# File 'lib/groundskeeper/commands.rb', line 22

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

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

.stageObject

rubocop:enable Metrics/AbcSize,Metrics/MethodLength



52
53
54
# File 'lib/groundskeeper/commands.rb', line 52

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

Instance Method Details

#deploy(options) ⇒ Object

rubocop:disable Metrics/AbcSize



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

def deploy(options)
  return unrecognized_version unless version_file.exists?
  return missing_jira_credentials unless jira.credentials?
  return unless check_groundskeeper_version
  pull_project_details

  ENV["whenever"] = "1" if project.uses_whenever?

  mina "deploy", options
  console.say("waiting for deployed application to restart...", :yellow)
  update_deployed_issues
  add_version_to_sentry
end

#infoObject

rubocop:disable Metrics/MethodLength,Metrics/AbcSize



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/groundskeeper/commands.rb', line 87

def info
  return unrecognized_version unless version_file.exists?
  return unless check_groundskeeper_version
  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

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength



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

def predeploy(options)
  return unrecognized_version unless version_file.exists?
  return unless check_groundskeeper_version
  pull_project_details

  mina "predeploy", options
end

#releaseObject

rubocop:disable Metrics/AbcSize



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

def release
  return unrecognized_version unless version_file.exists?
  return missing_jira_credentials unless jira.credentials?
  return unless check_groundskeeper_version
  pull_project_details

  summarize_recent_commits
  ask_next_version
  ask_new_branch
  update_version_file
  update_changelog
  commit_changes_and_tag
  ask_create_jira_version
  ask_push_with_tags
  ask_add_version_to_jira_issues
  open_pull_request_page
end