yast-rake 0.2.41 → 0.2.45

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea95f9f06d6f3ab9b3a4e5078bf6ac60a87379540571f3c5b99bdea42dfb83c
4
- data.tar.gz: 2e15ce0eb612f90be1ae9f65906283ddfaf0d3f6159fe816954a4ceb5a22c4cc
3
+ metadata.gz: 44bab584e30b75b55a4b7cbfe7744e98c3b29c0fb0fbc259bb3663aac70a1b5d
4
+ data.tar.gz: fb8b758faff86d93e53658f9b9dcb9a247071fd821882e1992a7d31bf2d3c12b
5
5
  SHA512:
6
- metadata.gz: 9cb29be7fb662e4c53e693efe4c907183210b9b1fb6f7abbb941a791001b64e0c4c7a1aab312d83846ae4aac73755d64957136a36de9e4861ec4cd5fb43184b5
7
- data.tar.gz: ac4dbcc62bcb8a0497205a24f5aac12d6d30137f1832769576e3ac8df5654db9fb3aaa179ab3348b6f6be6ebd427e9264d65a1fb30c99606a1e12eff54efa87b
6
+ metadata.gz: a855254c47f0071b0b29754dff4ec0415f426f72f48532aab8a7bce4e2fa30aabf5aa006ccb5795ce5682a5c343c81c3dc7cc0281b26412e1243996bc229a40e
7
+ data.tar.gz: d4ff9bb5d5307137f1dccb83fb110216a7f2c75bcd36ea0d6e62949f5aa6f1190e3491ab8972a871580e015016b0629e3eea08c26cc596dc50040b2fe6f46629
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.41
1
+ 0.2.45
@@ -28,8 +28,7 @@ class ContainerRunner
28
28
  # @param client [String,nil] the client name, nil or empty string = find
29
29
  # the client automatically
30
30
  def run(client)
31
- image = find_image
32
- container = GithubActions::Container.new(image)
31
+ container = find_container
33
32
  container.pull
34
33
  container.start
35
34
  container.copy_current_dir
@@ -44,16 +43,16 @@ private
44
43
 
45
44
  # find the Docker image to use in the container
46
45
  # @return [String] the image name
47
- def find_image
46
+ def find_container
48
47
  # explicitly requested image
49
48
  image = ENV["DOCKER_IMAGE"]
50
- return image if image && !image.empty?
49
+ return GithubActions::Container.new(image) if image && !image.empty?
51
50
 
52
51
  # scan the Docker images used in the GitHub Actions
53
- images = workflow_images
54
- return images.first if images.size == 1
52
+ containers = workflow_containers
53
+ return containers.first if containers.size == 1
55
54
 
56
- if images.empty?
55
+ if containers.empty?
57
56
  error("No Docker image was found in the GitHub Actions")
58
57
  puts "Use DOCKER_IMAGE=<name> option for specifying the image name"
59
58
  abort
@@ -61,20 +60,36 @@ private
61
60
 
62
61
  # multiple images found
63
62
  error("Found multiple Docker images in the GitHub Actions:")
64
- error(images.inspect)
63
+ error(containers.map { |c| [c.image, c.options] })
65
64
  puts "Use DOCKER_IMAGE=<name> option for specifying the image name"
65
+ puts "and DOCKER_OPTIONS=<options> option for specifying the extra Docker"
66
+ puts "command line parameters."
66
67
  abort
67
68
  end
68
69
 
69
70
  # extract the Docker images from the GitHub Actions,
70
71
  # the duplicates are removed
71
- # @return [Array<String>] image names
72
- def workflow_images
73
- GithubActions::Workflow.read.each_with_object([]) do |workflow, images|
72
+ # @return [Array<GithubActions::Container>] image names
73
+ def workflow_containers
74
+ ret = GithubActions::Workflow.read.each_with_object([]) do |workflow, containers|
74
75
  workflow.jobs.each do |job|
75
- container = job.container
76
- images << container if container && !images.include?(container)
76
+ container_data = job.container
77
+
78
+ if container_data.is_a?(String)
79
+ containers << GithubActions::Container.new(container_data)
80
+ elsif container_data.is_a?(Hash)
81
+ # to_s converts missing options (nil) to empty options ("")
82
+ # to treat these as equal in comparison
83
+ containers << GithubActions::Container.new(
84
+ container_data["image"],
85
+ container_data["options"].to_s
86
+ )
87
+ else
88
+ abort "Unsupported container definition: #{container_data.inspect}"
89
+ end
77
90
  end
78
91
  end
92
+
93
+ ret.uniq { |c| [c.image, c.options] }
79
94
  end
80
95
  end
@@ -26,7 +26,7 @@ module GithubActions
26
26
  class Container
27
27
  include Colorizer
28
28
 
29
- attr_reader :image, :container
29
+ attr_reader :image, :options, :container
30
30
 
31
31
  # the default timeout in seconds, maximum time for the running container,
32
32
  # after the time runs out the container is automatically stopped and removed
@@ -43,8 +43,10 @@ module GithubActions
43
43
 
44
44
  # constructor
45
45
  # @param image [String] name of the Docker image to use
46
- def initialize(image)
46
+ # @param options [String, nil] extra docker options
47
+ def initialize(image, options = nil)
47
48
  @image = image
49
+ @options = options
48
50
  end
49
51
 
50
52
  # pull the Docker image, ensure that the latest version is used
@@ -73,7 +75,7 @@ module GithubActions
73
75
  end
74
76
 
75
77
  cmd = "docker create #{env_options(ENV_VARIABLES)} --rm --entrypoint " \
76
- "#{run} #{image.shellescape} #{args}"
78
+ "#{run} #{options} #{ENV["DOCKER_OPTIONS"]} #{image.shellescape} #{args}"
77
79
 
78
80
  # contains the container ID
79
81
  @container = `#{cmd}`.chomp
@@ -22,7 +22,7 @@ module GithubActions
22
22
  # Github Actions job
23
23
  # @see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
24
24
  class Job
25
- attr_reader :name, :steps, :runs_on, :container, :workflow
25
+ attr_reader :name, :steps, :runs_on, :container, :workflow, :matrix
26
26
 
27
27
  # @param name [String] name of the job
28
28
  # @param data [Hash] data from the workflow YAML file
@@ -32,6 +32,7 @@ module GithubActions
32
32
  @runs_on = data["runs-on"]
33
33
  @container = data["container"]
34
34
  @workflow = workflow
35
+ @matrix = data.fetch("strategy", {})["matrix"]
35
36
 
36
37
  @steps = data["steps"].map do |step|
37
38
  Step.new(self, step)
@@ -58,12 +58,45 @@ module GithubActions
58
58
 
59
59
  # pull the Docker image and start the container
60
60
  def start_container
61
- # prefer the custom image if requested
62
- @container = Container.new(image || job.container)
61
+ @container = find_container
63
62
  container.pull
64
63
  container.start
65
64
  end
66
65
 
66
+ # Get the container configuration
67
+ # @return [Container] container which should run the job
68
+ def find_container
69
+ # prefer the custom image if requested
70
+ image_name = if image
71
+ image
72
+ elsif job.container.is_a?(String)
73
+ job.container
74
+ elsif job.container.is_a?(Hash)
75
+ options = job.container["options"]
76
+ job.container["image"]
77
+ else
78
+ abort "Unsupported container definition: #{job.container.inspect}"
79
+ end
80
+
81
+ Container.new(expand_name(image_name), options.to_s)
82
+ end
83
+
84
+ # replace the ${{ matrix.<value> }} placeholders in the image name
85
+ #
86
+ # @param image_name [String] name of the Docker image
87
+ # @return [String] name with replaced values
88
+ def expand_name(image_name)
89
+ image_name.gsub(/\$\{\{\s*matrix\.[^}]*\}\}/) do |subst|
90
+ name = /\$\{\{\s*matrix\.([^}]*)\}\}/.match(subst)[1].strip
91
+ value = job.matrix ? job.matrix[name] : subst
92
+
93
+ # if the value is an Array use the first value by default
94
+ replacement = value.is_a?(Array) ? value.first : value.to_s
95
+ puts "Using ${{matrix.#{name}}} value: #{replacement.inspect}"
96
+ replacement
97
+ end
98
+ end
99
+
67
100
  # run a job step
68
101
  # @param step [GithubActions::Step] the step to run
69
102
  # @return [Boolean] `true` if the step succeeded, `false` otherwise
@@ -15,12 +15,24 @@
15
15
  #
16
16
  #++
17
17
 
18
+ # the default old version used
19
+ OLD_RUBOCOP_VERSION = "0.41.2"
20
+
21
+ def rubocop_version
22
+ return @rubocop_version if @rubocop_version
23
+
24
+ @rubocop_version = if File.read(".rubocop.yml").match(/rubocop-(\d+\.\d+\.\d+)/)
25
+ Regexp.last_match[1]
26
+ else
27
+ OLD_RUBOCOP_VERSION
28
+ end
29
+ end
30
+
18
31
  def rubocop_bin
19
32
  return @rubocop_bin if @rubocop_bin
20
33
  return @rubocop_bin = ENV["RUBOCOP_BIN"] if ENV["RUBOCOP_BIN"]
21
34
 
22
- version = File.read(".rubocop.yml").include?("rubocop-0.71.0") ? "0.71.0" : "0.41.2"
23
- binary = `/usr/sbin/update-alternatives --list rubocop | grep '#{version}'`.strip
35
+ binary = `/usr/sbin/update-alternatives --list rubocop | grep '#{rubocop_version}'`.strip
24
36
  if !system("which #{binary}")
25
37
  raise "cannot find proper version of rubocop binary in " \
26
38
  "'/usr/sbin/update-alternatives --list rubocop'." \
@@ -32,18 +44,26 @@ end
32
44
  # run Rubocop in parallel
33
45
  # @param params [String] optional Rubocop parameters
34
46
  def run_rubocop(params = "")
35
- # how it works:
36
- # 1) get the list of inspected files by Rubocop
37
- # 2) shuffle it randomly (better would be evenly distribute them according to
38
- # the analysis complexity but that is hard to evaluate and even simply
39
- # distributing by file size turned out to be ineffective and slower than
40
- # a simple random shuffling)
41
- # 3) pass that as input for xargs
42
- # a) use -P with number of processors to run the commands in parallel
43
- # b) use -n to set the maximum number of files per process, this number
44
- # is computed to equally distribute the files across the workers
45
- sh "#{rubocop_bin} -L | sort -R | xargs -P`nproc` -n$(expr `#{rubocop_bin} -L | wc -l` / " \
46
- "`nproc` + 1) #{rubocop_bin} #{params}"
47
+ # newer Rubocop versions support the "-P" ("--parallel") option,
48
+ # but that is not compatible with the "-a" ("--auto-correct") option
49
+ if rubocop_version != OLD_RUBOCOP_VERSION && !params.to_s.match(/-a|--auto-correct/)
50
+ sh "#{rubocop_bin} -P #{params}"
51
+ else
52
+ # for older Rubocop or auto-correct mode manually start multiple instances in parallel
53
+ #
54
+ # how it works:
55
+ # 1) get the list of inspected files by Rubocop
56
+ # 2) shuffle it randomly (better would be evenly distribute them according to
57
+ # the analysis complexity but that is hard to evaluate and even simply
58
+ # distributing by file size turned out to be ineffective and slower than
59
+ # a simple random shuffling)
60
+ # 3) pass that as input for xargs
61
+ # a) use -P with number of processors to run the commands in parallel
62
+ # b) use -n to set the maximum number of files per process, this number
63
+ # is computed to equally distribute the files across the workers
64
+ sh "#{rubocop_bin} -L | sort -R | xargs -P`nproc` -n$(expr `#{rubocop_bin} -L | wc -l` / " \
65
+ "`nproc` + 1) #{rubocop_bin} #{params}"
66
+ end
47
67
  end
48
68
 
49
69
  namespace :check do
@@ -18,12 +18,16 @@
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #++
20
20
 
21
- require_relative "../yast/tarball_server"
22
-
23
21
  # Rake task for running a source code web server,
24
22
  # designed for the `yupdate` script.
25
23
  desc "Start an HTTP server providing dynamically generated source code tarball"
26
24
  task :server, [:port] do |_task, args|
25
+ begin
26
+ require_relative "../yast/tarball_server"
27
+ rescue LoadError
28
+ abort "Webrick server is not installed, please install the webrick Ruby gem"
29
+ end
30
+
27
31
  server = Yast::TarballServer.new(args[:port])
28
32
 
29
33
  puts "Starting tarball webserver:"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yast-rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.41
4
+ version: 0.2.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Reidinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: packaging_rake_tasks