Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include:
- local: .gitlab/ci/chatops.gitlab-ci.yml

stages:
- chatops
- components

default:
Expand Down
14 changes: 14 additions & 0 deletions .gitlab/ci/chatops.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.chatops:
image: ruby:3.2.2
stage: chatops
timeout: 10 min
script:
- bundle install
- bin/chatops $CI_JOB_NAME $CHAT_INPUT
variables:
THOR_SHELL: 'Basic'
rules:
- if: $CI_PIPELINE_SOURCE == "chat"

components:
extends: .chatops
44 changes: 44 additions & 0 deletions bin/chatops
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'stringio'
require_relative '../lib/pyxis'

original_stdout = $stdout
stringio = StringIO.new
$stdout = stringio

start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
config = { debug: true } # we want the error to be raised

begin
result = Pyxis::Cli.start(ARGV, config)
successful = true
rescue Thor::Error, Pyxis::Error => e
result = "#{e.class}\n#{e.message}"
successful = false
end

end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)

SemanticLogger.flush

$stdout = original_stdout

SECTION = 'chat_reply'

puts "section_start:#{Time.now.to_i}:#{SECTION}\r\033[0K"

puts "$ pyxis #{ARGV.join(' ')}"
puts '```'
puts

puts result || stringio.string

puts
puts '```'
puts "#{successful ? 'Finished' : 'Failed'} in #{(end_time - start_time).round(2)} seconds"

puts "section_end:#{Time.now.to_i}:#{SECTION}\r\033[0K"

exit(successful)
5 changes: 4 additions & 1 deletion bin/pyxis
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

require_relative '../lib/pyxis'

Pyxis::Cli.start(ARGV)
result = Pyxis::Cli.start(ARGV)
SemanticLogger.flush

puts result
2 changes: 2 additions & 0 deletions lib/pyxis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
Bundler.require

module Pyxis
Error = Class.new(StandardError)
end

loader = Zeitwerk::Loader.for_gem
loader.setup
loader.eager_load_namespace(Pyxis::Logger)
loader.eager_load_namespace(Pyxis::DryRunEnforcer)
loader.eager_load_namespace(Pyxis::Project::Base)
16 changes: 10 additions & 6 deletions lib/pyxis/commands/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@
module Pyxis
module Commands
class Components < Thor
include PermissionHelper

desc 'info [BUILD_ID]', 'Get the component versions for a reticulum build'
def info(build_id)
component_versions = ManagedVersioning::ComponentInfo.new(build_id).execute

SemanticLogger.flush

puts 'Versions of each component'
result = 'Versions of each component'
component_versions.each do |component, version|
puts "#{component}: #{version}"
result += "\n#{component}: #{version}"
end
result
end

desc 'update [COMPONENT]', 'Update a component in reticulum'
def update(component)
assert_executed_by_schedule!

updater(component).execute
end

desc 'list', 'List all available components'
def list
puts 'Available components:'
result = 'Available components:'
Pyxis::Project.components.each do |project|
puts "- #{project.downcase}"
result += "\n- #{project.downcase}"
end
result
end

desc 'get_version COMPONENT', 'Get the current version of a component in reticulum'
Expand Down
2 changes: 1 addition & 1 deletion lib/pyxis/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def call(env)

SemanticLogger.application = 'pyxis'
SemanticLogger.default_level = ENV.fetch('LOG_LEVEL', 'debug').to_sym
SemanticLogger.add_appender(io: $stdout, level: SemanticLogger.default_level,
SemanticLogger.add_appender(io: $stderr, level: SemanticLogger.default_level,
formatter: Pyxis::Logger::NoProcessColorFormatter.new)

SemanticLogger.push_tags('dry-run') if Pyxis::GlobalStatus.dry_run?
Expand Down
17 changes: 17 additions & 0 deletions lib/pyxis/permission_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Pyxis
PermissionError = Class.new(Pyxis::Error)
module PermissionHelper
def checks_active?
ENV['BYPASS_PERMISSION_CHECKS'].nil?
end

def assert_executed_by_schedule!
return unless checks_active?
return if ENV['CI_PIPELINE_SOURCE'] == 'schedule'

raise PermissionError, 'This operation can only be run by a pipeline schedule'
end
end
end