|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Pyxis |
| 4 | + module Checks |
| 5 | + class TucanaVersionMatch |
| 6 | + include Check |
| 7 | + |
| 8 | + attr_reader :component_info |
| 9 | + |
| 10 | + def initialize(component_info) |
| 11 | + @component_info = component_info |
| 12 | + end |
| 13 | + |
| 14 | + def perform_check! |
| 15 | + [sagittarius_version, aquila_version, draco_version, taurus_version].uniq.size == 1 |
| 16 | + end |
| 17 | + |
| 18 | + def status_message |
| 19 | + return "#{icon} Components use the same tucana version" if pass? |
| 20 | + |
| 21 | + message = [] |
| 22 | + message << "#{icon} Components use different tucana versions" |
| 23 | + message << '' |
| 24 | + message << "sagittarius: #{sagittarius_version}" |
| 25 | + message << "aquila: #{aquila_version}" |
| 26 | + message << "draco: #{draco_version}" |
| 27 | + message << "taurus: #{taurus_version}" |
| 28 | + |
| 29 | + message.join("\n") |
| 30 | + end |
| 31 | + |
| 32 | + private |
| 33 | + |
| 34 | + def sagittarius_version |
| 35 | + return @sagittarius_version if defined?(@sagittarius_version) |
| 36 | + |
| 37 | + gemfile_content = Base64.decode64 GithubClient.octokit.contents( |
| 38 | + Project::Sagittarius.github_path, |
| 39 | + path: 'Gemfile.lock', |
| 40 | + ref: executed_component_info[:sagittarius] |
| 41 | + ).content |
| 42 | + |
| 43 | + @sagittarius_version = Bundler::LockfileParser.new(gemfile_content) |
| 44 | + .specs |
| 45 | + .find { |spec| spec.name == 'tucana' } |
| 46 | + .version |
| 47 | + .to_s |
| 48 | + end |
| 49 | + |
| 50 | + def aquila_version |
| 51 | + @aquila_version ||= from_cargo_lockfile( |
| 52 | + Base64.decode64( |
| 53 | + GithubClient.octokit.contents( |
| 54 | + Project::Aquila.github_path, |
| 55 | + path: 'Cargo.lock', |
| 56 | + ref: executed_component_info[:aquila] |
| 57 | + ).content |
| 58 | + ) |
| 59 | + ) |
| 60 | + end |
| 61 | + |
| 62 | + def draco_version |
| 63 | + @draco_version ||= from_cargo_lockfile( |
| 64 | + Base64.decode64( |
| 65 | + GithubClient.octokit.contents( |
| 66 | + Project::Draco.github_path, |
| 67 | + path: 'Cargo.lock', |
| 68 | + ref: executed_component_info[:draco] |
| 69 | + ).content |
| 70 | + ) |
| 71 | + ) |
| 72 | + end |
| 73 | + |
| 74 | + def taurus_version |
| 75 | + @taurus_version ||= from_cargo_lockfile( |
| 76 | + Base64.decode64( |
| 77 | + GithubClient.octokit.contents( |
| 78 | + Project::Taurus.github_path, |
| 79 | + path: 'Cargo.lock', |
| 80 | + ref: executed_component_info[:taurus] |
| 81 | + ).content |
| 82 | + ) |
| 83 | + ) |
| 84 | + end |
| 85 | + |
| 86 | + def from_cargo_lockfile(lockfile) |
| 87 | + toml = TomlRB.parse(lockfile, symbolize_keys: true) |
| 88 | + toml[:package].find { |package| package[:name] == 'tucana' }[:version] |
| 89 | + end |
| 90 | + |
| 91 | + def executed_component_info |
| 92 | + @executed_component_info ||= component_info.execute |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | +end |
0 commit comments