Class: Command::GenerateGithubActions

Inherits:
Base
  • Object
show all
Defined in:
lib/command/generate_github_actions.rb

Constant Summary collapse

NAME =
"generate-github-actions"
OPTIONS =
[staging_branch_option].freeze
DESCRIPTION =
"Creates GitHub Actions templates for review apps, staging deploys, and production promotion"
LONG_DESCRIPTION =
<<~DESC
  Creates GitHub Actions templates for a Heroku Flow style Control Plane pipeline:
  - on-demand review apps for pull requests
  - automatic staging deploys from your main branch
  - manual promotion from staging to production
  - nightly cleanup and PR help workflows

  Pass `--staging-branch BRANCH` when staging should auto-deploy from a branch
  other than `main` or `master`; the generator will bake that branch into the
  GitHub Actions push trigger and use it as the default STAGING_APP_BRANCH.
DESC
EXAMPLES =
<<~EX
  ```sh
  # Creates .github/actions and .github/workflows files for the Control Plane flow
  cpflow generate-github-actions

  # Creates the flow with staging deploys triggered from develop
  cpflow generate-github-actions --staging-branch develop
  ```
EX
WITH_INFO_HEADER =
false
VALIDATIONS =
[].freeze
REQUIRES_STARTUP_CHECKS =
false
TEMPLATE_ROOT =

Resolve template root from __dir__ rather than Cpflow.root_path because this file is loaded before ‘module Cpflow` finishes defining its class methods.

Pathname.new(File.expand_path("../github_flow_templates", __dir__))

Constants inherited from Base

Base::ACCEPTS_EXTRA_OPTIONS, Base::ALL_VALIDATIONS, Base::DEFAULT_ARGS, Base::HIDE, Base::REQUIRES_ARGS, Base::SUBCOMMAND_NAME, Base::USAGE, Base::VALIDATIONS_WITHOUT_ADDITIONAL_OPTIONS, Base::VALIDATIONS_WITH_ADDITIONAL_OPTIONS

Instance Attribute Summary

Attributes inherited from Base

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

add_app_identity_option, all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, common_options, #cp, cpu_option, detached_option, dir_option, docker_context_option, domain_option, #ensure_docker_running!, entrypoint_option, image_option, #initialize, interactive_option, location_option, log_method_option, logs_limit_option, logs_since_option, memory_option, org_option, #progress, replica_option, #run_command_in_latest_image, #run_cpflow_command, run_release_phase_option, skip_confirm_option, skip_post_creation_hook_option, skip_pre_deletion_hook_option, skip_secret_access_binding_option, skip_secrets_setup_option, staging_branch_option, #step, #step_finish, terminal_size_option, trace_option, upstream_token_option, use_local_token_option, validations_option, verbose_option, version_option, wait_option, #with_retry, workload_option

Methods included from Helpers

normalize_command_name, normalize_option_name, random_four_digits, strip_str_and_validate

Constructor Details

This class inherits a constructor from Command::Base

Class Method Details

.ensure_template_root!Object



112
113
114
# File 'lib/command/generate_github_actions.rb', line 112

def self.ensure_template_root!
  raise "cpflow template directory not found: #{TEMPLATE_ROOT}" unless TEMPLATE_ROOT.directory?
end

.generated_filesObject



102
103
104
105
106
107
108
109
110
# File 'lib/command/generate_github_actions.rb', line 102

def self.generated_files
  ensure_template_root!

  Dir.glob(TEMPLATE_ROOT.join("**", "*").to_s, File::FNM_DOTMATCH)
     .select { |path| File.file?(path) }
     .map { |path| Pathname.new(path).relative_path_from(TEMPLATE_ROOT).to_s }
     .sort
     .freeze
end

Instance Method Details

#callObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/command/generate_github_actions.rb', line 116

def call
  self.class.ensure_template_root!
  branch = staging_branch

  if (existing = existing_files).any?
    files = existing.map { |path| "- #{path}" }.join("\n")
    Shell.warn("The following files already exist:\n#{files}\n\n" \
               "Remove or rename them before running `cpflow #{NAME}` again.")
    return
  end

  GithubActionsGenerator.start([branch].compact)
end