selective-ruby-core 0.1.1-x86_64-darwin → 0.1.3-x86_64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bin/build_env.sh +18 -12
- data/lib/bin/transport +0 -0
- data/lib/selective/ruby/core/controller.rb +43 -21
- data/lib/selective/ruby/core/version.rb +1 -1
- data/lib/selective-ruby-core.rb +3 -2
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 768c13ee1e2c74fe8909abdb4cf2193402e16bea564c42cb040d3d97ca096738
         | 
| 4 | 
            +
              data.tar.gz: d6f01be1d6bababc38807173b73ca4f77f329deca59f3c65d4be3b1458c24c56
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 394cd0376b4ca2298917828d179fd82f373a49c0a147a1bc4ba06e630aacffc90518d13afd7ee0c886229d2502393e1980e35c40bc2772f35069ba065f61f686
         | 
| 7 | 
            +
              data.tar.gz: 14bb3272aa4d945afff46647c3a8f63b464b83ced81f6ede396c58e944a3299cf0c265923132721a5d44700e4b03cd0997bd577c694a5e42e8b31552ba771f2b
         | 
    
        data/lib/bin/build_env.sh
    CHANGED
    
    | @@ -3,20 +3,24 @@ | |
| 3 3 | 
             
            # Detect the platform (only GitHub Actions in this case)
         | 
| 4 4 | 
             
            if [ -n "$GITHUB_ACTIONS" ]; then
         | 
| 5 5 | 
             
              # Get environment variables
         | 
| 6 | 
            -
              platform= | 
| 7 | 
            -
              branch | 
| 8 | 
            -
              pr_title | 
| 9 | 
            -
              target_branch | 
| 10 | 
            -
              actor | 
| 11 | 
            -
              sha | 
| 6 | 
            +
              platform=github_actions
         | 
| 7 | 
            +
              branch=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}
         | 
| 8 | 
            +
              pr_title=$SELECTIVE_PR_TITLE
         | 
| 9 | 
            +
              target_branch=${GITHUB_BASE_REF}
         | 
| 10 | 
            +
              actor=$GITHUB_ACTOR
         | 
| 11 | 
            +
              sha=$GITHUB_SHA
         | 
| 12 | 
            +
              run_id=$GITHUB_RUN_ID
         | 
| 13 | 
            +
              run_attempt=$GITHUB_RUN_ATTEMPT
         | 
| 12 14 | 
             
              commit_message=$(git log --format=%s -n 1 $sha)
         | 
| 13 15 | 
             
            else
         | 
| 14 | 
            -
              platform | 
| 15 | 
            -
              branch | 
| 16 | 
            -
              pr_title | 
| 17 | 
            -
              target_branch | 
| 18 | 
            -
              actor | 
| 19 | 
            -
              sha | 
| 16 | 
            +
              platform=$SELECTIVE_PLATFORM
         | 
| 17 | 
            +
              branch=$SELECTIVE_BRANCH
         | 
| 18 | 
            +
              pr_title=$SELECTIVE_PR_TITLE
         | 
| 19 | 
            +
              target_branch=$SELECTIVE_TARGET_BRANCH
         | 
| 20 | 
            +
              actor=$SELECTIVE_ACTOR
         | 
| 21 | 
            +
              sha=$SELECTIVE_SHA
         | 
| 22 | 
            +
              run_id=$SELECTIVE_RUN_ID
         | 
| 23 | 
            +
              run_attempt=$SELECTIVE_RUN_ATTEMPT
         | 
| 20 24 | 
             
              commit_message=$(git log --format=%s -n 1 $sha)
         | 
| 21 25 | 
             
            fi
         | 
| 22 26 |  | 
| @@ -29,6 +33,8 @@ cat <<EOF | |
| 29 33 | 
             
                "target_branch": "$target_branch",
         | 
| 30 34 | 
             
                "actor": "$actor",
         | 
| 31 35 | 
             
                "sha": "$sha",
         | 
| 36 | 
            +
                "run_id": "$run_id",
         | 
| 37 | 
            +
                "run_attempt": "$run_attempt",
         | 
| 32 38 | 
             
                "commit_message": "$commit_message"
         | 
| 33 39 | 
             
              }
         | 
| 34 40 | 
             
            EOF
         | 
    
        data/lib/bin/transport
    CHANGED
    
    | Binary file | 
| @@ -1,6 +1,8 @@ | |
| 1 1 | 
             
            require "logger"
         | 
| 2 2 | 
             
            require "uri"
         | 
| 3 3 | 
             
            require "json"
         | 
| 4 | 
            +
            require "fileutils"
         | 
| 5 | 
            +
            require "open3"
         | 
| 4 6 |  | 
| 5 7 | 
             
            module Selective
         | 
| 6 8 | 
             
              module Ruby
         | 
| @@ -8,12 +10,12 @@ module Selective | |
| 8 10 | 
             
                  class Controller
         | 
| 9 11 | 
             
                    @@selective_suppress_reporting = false
         | 
| 10 12 |  | 
| 11 | 
            -
                    def initialize(runner, debug  | 
| 13 | 
            +
                    def initialize(runner, debug: false, log: false)
         | 
| 12 14 | 
             
                      @debug = debug
         | 
| 13 15 | 
             
                      @runner = runner
         | 
| 14 16 | 
             
                      @retries = 0
         | 
| 15 17 | 
             
                      @runner_id = ENV.fetch("SELECTIVE_RUNNER_ID", generate_runner_id)
         | 
| 16 | 
            -
                      @logger =  | 
| 18 | 
            +
                      @logger = init_logger(log)
         | 
| 17 19 | 
             
                    end
         | 
| 18 20 |  | 
| 19 21 | 
             
                    def start(reconnect: false)
         | 
| @@ -52,6 +54,15 @@ module Selective | |
| 52 54 |  | 
| 53 55 | 
             
                    BUILD_ENV_SCRIPT_PATH = "../../../bin/build_env.sh".freeze
         | 
| 54 56 |  | 
| 57 | 
            +
                    def init_logger(enabled)
         | 
| 58 | 
            +
                      if enabled
         | 
| 59 | 
            +
                        FileUtils.mkdir_p("log")
         | 
| 60 | 
            +
                        Logger.new("log/#{runner_id}.log")
         | 
| 61 | 
            +
                      else
         | 
| 62 | 
            +
                        Logger.new("/dev/null")
         | 
| 63 | 
            +
                      end
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
             | 
| 55 66 | 
             
                    def run_main_loop
         | 
| 56 67 | 
             
                      loop do
         | 
| 57 68 | 
             
                        message = pipe.read
         | 
| @@ -90,13 +101,15 @@ module Selective | |
| 90 101 | 
             
                    def transport_url
         | 
| 91 102 | 
             
                      @transport_url ||= begin
         | 
| 92 103 | 
             
                        api_key = ENV.fetch("SELECTIVE_API_KEY")
         | 
| 93 | 
            -
                        run_id = ENV.fetch("SELECTIVE_RUN_ID")
         | 
| 94 | 
            -
                        run_attempt = ENV.fetch("SELECTIVE_RUN_ATTEMPT", SecureRandom.uuid)
         | 
| 95 104 | 
             
                        host = ENV.fetch("SELECTIVE_HOST", "wss://app.selective.ci")
         | 
| 96 105 |  | 
| 97 106 | 
             
                        # Validate that host is a valid websocket url(starts with ws:// or wss://)
         | 
| 98 107 | 
             
                        raise "Invalid host: #{host}" unless host.match?(/^wss?:\/\//)
         | 
| 99 108 |  | 
| 109 | 
            +
                        run_id = build_env.delete("run_id")
         | 
| 110 | 
            +
                        run_attempt = build_env.delete("run_attempt")
         | 
| 111 | 
            +
                        run_attempt = SecureRandom.uuid if run_attempt.nil? || run_attempt.empty?
         | 
| 112 | 
            +
             | 
| 100 113 | 
             
                        params = {
         | 
| 101 114 | 
             
                          "run_id" => run_id,
         | 
| 102 115 | 
             
                          "run_attempt" => run_attempt,
         | 
| @@ -111,8 +124,10 @@ module Selective | |
| 111 124 | 
             
                    end
         | 
| 112 125 |  | 
| 113 126 | 
             
                    def build_env
         | 
| 114 | 
            -
                       | 
| 115 | 
            -
             | 
| 127 | 
            +
                      @build_env ||= begin
         | 
| 128 | 
            +
                        result = `#{Pathname.new(__dir__) + BUILD_ENV_SCRIPT_PATH}`
         | 
| 129 | 
            +
                        JSON.parse(result)
         | 
| 130 | 
            +
                      end
         | 
| 116 131 | 
             
                    end
         | 
| 117 132 |  | 
| 118 133 | 
             
                    def spawn_transport_process(url)
         | 
| @@ -123,7 +138,6 @@ module Selective | |
| 123 138 | 
             
                      # The get_transport script is not released with the gem, so this
         | 
| 124 139 | 
             
                      # code is intended for development/CI purposes.
         | 
| 125 140 | 
             
                      if !File.exist?(transport_path) && File.exist?(get_transport_path)
         | 
| 126 | 
            -
                        require "open3"
         | 
| 127 141 | 
             
                        output, status = Open3.capture2e(get_transport_path)
         | 
| 128 142 | 
             
                        if !status.success?
         | 
| 129 143 | 
             
                          puts <<~TEXT
         | 
| @@ -175,8 +189,8 @@ module Selective | |
| 175 189 |  | 
| 176 190 | 
             
                    def handle_command(response)
         | 
| 177 191 | 
             
                      case response[:command]
         | 
| 178 | 
            -
                      when " | 
| 179 | 
            -
                         | 
| 192 | 
            +
                      when "print_notice"
         | 
| 193 | 
            +
                        print_notice(response[:message])
         | 
| 180 194 | 
             
                      when "test_manifest"
         | 
| 181 195 | 
             
                        handle_test_manifest
         | 
| 182 196 | 
             
                      when "run_test_cases"
         | 
| @@ -189,10 +203,11 @@ module Selective | |
| 189 203 | 
             
                        handle_print_message(response[:message])
         | 
| 190 204 | 
             
                      when "close"
         | 
| 191 205 | 
             
                        handle_close(response[:exit_status])
         | 
| 192 | 
            -
             | 
| 193 | 
            -
                        #  | 
| 194 | 
            -
                        # cannot exit but we need to break the loop
         | 
| 206 | 
            +
                        # This return is here for the sake of test where
         | 
| 207 | 
            +
                        # we cannot exit but we need to break the loop
         | 
| 195 208 | 
             
                        return false
         | 
| 209 | 
            +
                      else
         | 
| 210 | 
            +
                        raise "Unknown command received: #{response[:command]}" if debug?
         | 
| 196 211 | 
             
                      end
         | 
| 197 212 |  | 
| 198 213 | 
             
                      true
         | 
| @@ -207,10 +222,9 @@ module Selective | |
| 207 222 | 
             
                    def handle_test_manifest
         | 
| 208 223 | 
             
                      self.class.restore_reporting!
         | 
| 209 224 | 
             
                      @logger.info("Sending Response: test_manifest")
         | 
| 210 | 
            -
                       | 
| 211 | 
            -
             | 
| 212 | 
            -
             | 
| 213 | 
            -
                      }})
         | 
| 225 | 
            +
                      data = {test_cases: runner.manifest["examples"]}
         | 
| 226 | 
            +
                      data[:modified_test_files] = modified_test_files unless modified_test_files.nil?
         | 
| 227 | 
            +
                      write({type: "test_manifest", data: data})
         | 
| 214 228 | 
             
                    end
         | 
| 215 229 |  | 
| 216 230 | 
             
                    def handle_run_test_cases(test_cases)
         | 
| @@ -227,9 +241,17 @@ module Selective | |
| 227 241 | 
             
                    end
         | 
| 228 242 |  | 
| 229 243 | 
             
                    def modified_test_files
         | 
| 230 | 
            -
                       | 
| 231 | 
            -
             | 
| 232 | 
            -
                         | 
| 244 | 
            +
                      @modified_test_files ||= begin
         | 
| 245 | 
            +
                        target_branch = build_env["target_branch"]
         | 
| 246 | 
            +
                        return [] if target_branch.nil? || target_branch.empty?
         | 
| 247 | 
            +
             | 
| 248 | 
            +
                        output, status = Open3.capture2e("git diff #{target_branch} --name-only")
         | 
| 249 | 
            +
             | 
| 250 | 
            +
                        if status.success?
         | 
| 251 | 
            +
                          output.split("\n").filter do |f|
         | 
| 252 | 
            +
                            f.match?(/^#{runner.base_test_path}/)
         | 
| 253 | 
            +
                          end
         | 
| 254 | 
            +
                        end
         | 
| 233 255 | 
             
                      end
         | 
| 234 256 | 
             
                    end
         | 
| 235 257 |  | 
| @@ -285,10 +307,10 @@ module Selective | |
| 285 307 | 
             
                      TEXT
         | 
| 286 308 | 
             
                    end
         | 
| 287 309 |  | 
| 288 | 
            -
                    def  | 
| 310 | 
            +
                    def print_notice(message)
         | 
| 289 311 | 
             
                      puts_indented <<~TEXT
         | 
| 290 312 | 
             
                        #{banner}
         | 
| 291 | 
            -
                         | 
| 313 | 
            +
                        #{message}
         | 
| 292 314 | 
             
                      TEXT
         | 
| 293 315 | 
             
                    end
         | 
| 294 316 |  | 
    
        data/lib/selective-ruby-core.rb
    CHANGED
    
    | @@ -24,6 +24,7 @@ module Selective | |
| 24 24 | 
             
                  class Init
         | 
| 25 25 | 
             
                    def initialize(args)
         | 
| 26 26 | 
             
                      @debug = !args.delete("--debug").nil?
         | 
| 27 | 
            +
                      @log = !args.delete("--log").nil?
         | 
| 27 28 | 
             
                      @runner_name, @args, @command = parse_args(args)
         | 
| 28 29 | 
             
                      require_runner
         | 
| 29 30 | 
             
                    end
         | 
| @@ -34,10 +35,10 @@ module Selective | |
| 34 35 |  | 
| 35 36 | 
             
                    private
         | 
| 36 37 |  | 
| 37 | 
            -
                    attr_reader :debug, :runner_name, :args, :command
         | 
| 38 | 
            +
                    attr_reader :debug, :log, :runner_name, :args, :command
         | 
| 38 39 |  | 
| 39 40 | 
             
                    def run
         | 
| 40 | 
            -
                      Selective::Ruby::Core::Controller.new(runner, debug).send(command)
         | 
| 41 | 
            +
                      Selective::Ruby::Core::Controller.new(runner, debug: debug, log: log).send(command)
         | 
| 41 42 | 
             
                    end
         | 
| 42 43 |  | 
| 43 44 | 
             
                    def parse_args(args)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: selective-ruby-core
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.3
         | 
| 5 5 | 
             
            platform: x86_64-darwin
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Benjamin Wood
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2023-11- | 
| 12 | 
            +
            date: 2023-11-21 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: zeitwerk
         |