yast-rake 0.2.34 → 0.2.40

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf7eceae62dd270be7aa3d585c849f167de79e3fc0d2c19227115a9a31369c2c
4
- data.tar.gz: 8d1a2b6238bb073661dcc3094fff41b29fb48d1f44725b897e7dc432bb8eb425
3
+ metadata.gz: 2642c0e7364635725ef46461b0d6c816fd1ebca543b87a813292cb8b6092a392
4
+ data.tar.gz: de07ea039866173b29bf17d3e505ab9d3635ff4a7b50e65c4c9ee4f8da4fdec4
5
5
  SHA512:
6
- metadata.gz: dcde1b6fcd4e201951b0394478e01f0025ec6b0cca159da600bfe2076ef04c5b4df4da4574b0a49724966269d5473f32428e8267a87b88fa83d374a44755df00
7
- data.tar.gz: e7711375a60035a0e7505f52c1481943d8208102a9b7c1164610beeef91c4c64db5137c55ed12904666f8fe747a3df94cc996566ef3f0aa305351bb016366799
6
+ metadata.gz: cd3a1697577fb14c191261d5b953e123c8cf2052ddb58388d5836f6a0477b233903aab0f58663d723a9eb692d9e3319475e4f1db9878264288b39a9e1758eee5
7
+ data.tar.gz: b6153a3bfe3601cef2f3cfad9dfe899e80cbe11eb65563029a84c14a01fe9f8831fc0f8e1f270dd90975badd3abde483db0891f71ca619c5086ee653c9ef5ee1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.34
1
+ 0.2.40
data/data/index.html ADDED
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <!-- This is a simple main page for the "rake server" task. -->
3
+ <html>
4
+ <head>
5
+ <title>Source Code Tarball Server</title>
6
+ </head>
7
+ <body>
8
+
9
+ <h1>Source Code Tarball Server</h1>
10
+ <p>This server provides dynamically generated source code tarballs.</p>
11
+
12
+ <h2>Supported URL Paths</h2>
13
+ <p>
14
+ <ul>
15
+ <li>
16
+ <b><a href = "/archive/current.tar.gz">/archive/current.tar.gz</a></b>
17
+ - dynamically generated tarball with the current source files
18
+ </li>
19
+ <li>
20
+ <b><a href = "/servers/index.json">/servers/index.json</a></b>
21
+ - index of other running servers on the machine
22
+ </li>
23
+ </ul>
24
+ </p>
25
+
26
+ </body>
27
+ </html>
data/data/targets.yml CHANGED
@@ -63,8 +63,8 @@
63
63
  :sle12sp5:
64
64
  obs_api: "https://api.suse.de/"
65
65
  obs_project: "Devel:YaST:SLE-12-SP5"
66
- obs_sr_project: "SUSE:SLE-12-SP5:GA"
67
- obs_target: "SLE_12_SP5"
66
+ obs_sr_project: "SUSE:SLE-12-SP5:Update"
67
+ obs_target: "SUSE_SLE-12-SP5_Update"
68
68
  :sle15:
69
69
  obs_api: "https://api.suse.de/"
70
70
  obs_project: "Devel:YaST:SLE-15"
@@ -75,11 +75,21 @@
75
75
  obs_project: "Devel:YaST:SLE-15-SP1"
76
76
  obs_sr_project: "SUSE:SLE-15-SP1:Update"
77
77
  obs_target: "SUSE_SLE-15-SP1_Update"
78
+ :sle15sp2:
79
+ obs_api: "https://api.suse.de/"
80
+ obs_project: "Devel:YaST:SLE-15-SP2"
81
+ obs_sr_project: "SUSE:SLE-15-SP2:Update"
82
+ obs_target: "SUSE_SLE-15-SP2_Update"
83
+ :sle15sp3:
84
+ obs_api: "https://api.suse.de/"
85
+ obs_project: "Devel:YaST:SLE-15-SP3"
86
+ obs_sr_project: "SUSE:SLE-15-SP3:Update"
87
+ obs_target: "SUSE_SLE-15-SP3_Update"
78
88
  :sle_latest:
79
89
  obs_api: "https://api.suse.de/"
80
90
  obs_project: "Devel:YaST:Head"
81
- obs_sr_project: "SUSE:SLE-15-SP2:GA"
82
- obs_target: "SUSE_SLE-15-SP2_GA"
91
+ obs_sr_project: "SUSE:SLE-15-SP3:GA"
92
+ obs_target: "SUSE_SLE-15-SP3_GA"
83
93
  :factory:
84
94
  obs_project: "YaST:Head"
85
95
  obs_sr_project: "openSUSE:Factory"
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2021 SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require_relative "github_actions/tasks"
22
+
23
+ # tasks related to GitHub Actions (https://docs.github.com/en/actions)
24
+ namespace :actions do
25
+ desc "List the GitHub Action jobs"
26
+ task :list do
27
+ GithubActions::Tasks::List.new.run
28
+ end
29
+
30
+ desc "Display GitHub Action job details"
31
+ task :details do
32
+ GithubActions::Tasks::Details.new.run
33
+ end
34
+
35
+ desc "Run locally the specified GitHub Action job (all jobs if \"job\" is empty)"
36
+ task :run, [:job] do |_task, args|
37
+ name = args[:job]
38
+ if name.nil? || name.empty?
39
+ GithubActions::Tasks::RunAll.new.run
40
+ else
41
+ GithubActions::Tasks::Run.new(name).run
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2021 SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require_relative "github_actions/github_actions"
22
+
23
+ # Run a client in Docker container
24
+ class ContainerRunner
25
+ include GithubActions::Colorizer
26
+
27
+ # start a container, copy the sources there and run "rake run"
28
+ # @param client [String,nil] the client name, nil or empty string = find
29
+ # the client automatically
30
+ def run(client)
31
+ image = find_image
32
+ container = GithubActions::Container.new(image)
33
+ container.pull
34
+ container.start
35
+ container.copy_current_dir
36
+
37
+ cmd = client ? "rake run[#{client}]" : "rake run"
38
+ container.run(cmd)
39
+
40
+ container.stop
41
+ end
42
+
43
+ private
44
+
45
+ # find the Docker image to use in the container
46
+ # @return [String] the image name
47
+ def find_image
48
+ # explicitly requested image
49
+ image = ENV["DOCKER_IMAGE"]
50
+ return image if image && !image.empty?
51
+
52
+ # scan the Docker images used in the GitHub Actions
53
+ images = workflow_images
54
+ return images.first if images.size == 1
55
+
56
+ if images.empty?
57
+ error("No Docker image was found in the GitHub Actions")
58
+ puts "Use DOCKER_IMAGE=<name> option for specifying the image name"
59
+ abort
60
+ end
61
+
62
+ # multiple images found
63
+ error("Found multiple Docker images in the GitHub Actions:")
64
+ error(images.inspect)
65
+ puts "Use DOCKER_IMAGE=<name> option for specifying the image name"
66
+ abort
67
+ end
68
+
69
+ # extract the Docker images from the GitHub Actions,
70
+ # the duplicates are removed
71
+ # @return [Array<String>] image names
72
+ def workflow_images
73
+ GithubActions::Workflow.read.each_with_object([]) do |workflow, images|
74
+ workflow.jobs.each do |job|
75
+ container = job.container
76
+ images << container if container && !images.include?(container)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2021 SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require_relative "github_actions/colorizer"
22
+ require_relative "github_actions/container"
23
+ require_relative "github_actions/job"
24
+ require_relative "github_actions/job_runner"
25
+ require_relative "github_actions/step"
26
+ require_relative "github_actions/workflow"
27
+
28
+ # classes for running the Github Actions locally
29
+ module GithubActions
30
+ # regexps for some special actions which need to be handled differently
31
+ CHECKOUT_ACTION = /\Aactions\/checkout(|@.*)\z/.freeze
32
+ COVERALLS_ACTION = /\Acoverallsapp\/github-action(|@.*)\z/.freeze
33
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2021 SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ module GithubActions
22
+ # helper methods for colorizing output, if the "rainbow" colorizing gem
23
+ # is not installed then it prints the original messages without any colorizing
24
+ module Colorizer
25
+ # print an error
26
+ # @param msg [Object] the text to print
27
+ def error(msg)
28
+ print_colored(msg, :red)
29
+ end
30
+
31
+ # print a success message
32
+ # @param msg [Object] the text to print
33
+ def success(msg)
34
+ print_colored(msg, :green)
35
+ end
36
+
37
+ # print a warning
38
+ # @param msg [Object] the text to print
39
+ def warning(msg)
40
+ print_colored(msg, :magenta)
41
+ end
42
+
43
+ # print a message
44
+ # @param msg [Object] the text to print
45
+ def info(msg)
46
+ print_colored(msg, :cyan)
47
+ end
48
+
49
+ # print the progress status
50
+ # @param msg [Object] the text to print
51
+ def stage(msg)
52
+ print_colored(msg, :yellow)
53
+ end
54
+
55
+ private
56
+
57
+ # helper for printing the text
58
+ # @param msg [Object] the text to print
59
+ # @param color [Symbol] the text color
60
+ def print_colored(msg, color)
61
+ puts rainbow? ? Rainbow(msg).color(color) : msg
62
+ end
63
+
64
+ # load the Rainbow colorizing library if present
65
+ # see https://github.com/sickill/rainbow
66
+ # @return Boolean `true` if Rainbow was successfully loaded, `false` otherwise
67
+ def rainbow?
68
+ return @rainbow_present unless @rainbow_present.nil?
69
+
70
+ begin
71
+ require "rainbow"
72
+ @rainbow_present = true
73
+ rescue LoadError
74
+ @rainbow_present = false
75
+ end
76
+
77
+ @rainbow_present
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ #--
4
+ # Yast rake
5
+ #
6
+ # Copyright (C) 2021 SUSE LLC
7
+ # This library is free software; you can redistribute it and/or modify
8
+ # it only under the terms of version 2.1 of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation.
10
+ #
11
+ # This library is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
+ # details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+ require "English"
22
+ require "shellwords"
23
+
24
+ module GithubActions
25
+ # Manage a Docker container
26
+ class Container
27
+ include Colorizer
28
+
29
+ attr_reader :image, :container
30
+
31
+ # the default timeout in seconds, maximum time for the running container,
32
+ # after the time runs out the container is automatically stopped and removed
33
+ # unless `KEEP_CONTAINER` option is set
34
+ TIMEOUT = 3600
35
+
36
+ # the default environment variables in the container
37
+ ENV_VARIABLES = {
38
+ # this is a CI environment
39
+ "CI" => "true",
40
+ # skip the modified check in the "rake osc:build" task
41
+ "CHECK_MODIFIED" => "0"
42
+ }.freeze
43
+
44
+ # constructor
45
+ # @param image [String] name of the Docker image to use
46
+ def initialize(image)
47
+ @image = image
48
+ end
49
+
50
+ # pull the Docker image, ensure that the latest version is used
51
+ def pull
52
+ stage("Pulling the #{image} image...")
53
+ # if the latest image is already present it does nothing
54
+ system("docker pull #{image.shellescape}")
55
+ end
56
+
57
+ # start the container, runs "docker create" and "docker start"
58
+ def start
59
+ stage("Starting the container...")
60
+
61
+ # define the initial command for the container to start
62
+ if keep_container?
63
+ # running "tail -f /dev/null" does nothing and gets stuck forever,
64
+ # this ensures the container keeps running and we can execute
65
+ # the other commands there via "docker exec"
66
+ run = "tail"
67
+ args = "-f /dev/null"
68
+ else
69
+ # the "sleep" command ensures the container shuts down automatically after
70
+ # the timeout (to abort frozen jobs or avoid hanging containers after a crash)
71
+ run = "sleep"
72
+ args = TIMEOUT
73
+ end
74
+
75
+ cmd = "docker create #{env_options(ENV_VARIABLES)} --rm --entrypoint " \
76
+ "#{run} #{image.shellescape} #{args}"
77
+
78
+ # contains the container ID
79
+ @container = `#{cmd}`.chomp
80
+ system("docker start #{container.shellescape} > /dev/null")
81
+ end
82
+
83
+ # stop and remove the container from the system, runs "docker rm"
84
+ def stop
85
+ if keep_container?
86
+ print_container_usage
87
+ else
88
+ stage("Stopping the container...")
89
+ system("docker rm --force #{container.shellescape} > /dev/null")
90
+ end
91
+ end
92
+
93
+ # run a command in the container, runs "docker exec"
94
+ # the command is executed in a shell, so shell metacharacters like "&&"
95
+ # can be used to join several commands
96
+ # @param cmd [String] the command to run, it is passed to a shell to it might
97
+ # contain multiple commands or shell meta characters
98
+ # @param env [Hash] optional environment variables (with mapping "name" => "value")
99
+ # @return [Boolean] `true` if the command succeeded (exit status 0),
100
+ # `false` otherwise
101
+ def run(cmd, env = {})
102
+ stage("Running command: #{cmd}")
103
+ system("docker exec -it #{env_options(env)} #{container.shellescape} " \
104
+ "sh -c #{cmd.shellescape}")
105
+ $CHILD_STATUS.success?
106
+ end
107
+
108
+ # get the current working directory in the container
109
+ # @return [String] the path
110
+ def cwd
111
+ `docker exec #{container.shellescape} pwd`.chomp
112
+ end
113
+
114
+ # copy the files from host into the container
115
+ # @param from [String] the source path, if it is a directory all content
116
+ # is copied (including subdirectories)
117
+ # @param to [String] the target location in the container
118
+ def copy_files(from, to)
119
+ stage("Copying #{from} to #{to} in the container...")
120
+
121
+ if File.directory?(from)
122
+ # Dir.children is similar to Dir.entries but it omits the "." and ".." values
123
+ Dir.children(from).each do |f|
124
+ system("docker cp #{f.shellescape} #{container.shellescape}:#{to.shellescape}")
125
+ end
126
+ else
127
+ system("docker cp #{from.shellescape} #{container.shellescape}:#{to.shellescape}")
128
+ end
129
+ end
130
+
131
+ # copy the current directory to the current directory in the container
132
+ def copy_current_dir
133
+ copy_files(Dir.pwd, cwd)
134
+ end
135
+
136
+ private
137
+
138
+ # should we keep the container at the end or remove it?
139
+ def keep_container?
140
+ ENV["KEEP_CONTAINER"] == "1" || ENV["KEEP_CONTAINER"] == "true"
141
+ end
142
+
143
+ # when we keep the container running print some hints how to use it
144
+ def print_container_usage
145
+ warning("The Docker container is still running!")
146
+ puts "Use this command to connect to it:"
147
+ # docker accepts shortened IDs, make the commands shorter
148
+ info(" docker exec -it #{container[0..16]} bash")
149
+ puts "To stop and remove the container run:"
150
+ info(" docker rm -f #{container[0..16]}")
151
+ end
152
+
153
+ # build the docker environment command line options
154
+ # @param mapping [Hash] environment variables
155
+ # @return [String] the built Docker options
156
+ def env_options(mapping)
157
+ mapping.map do |name, value|
158
+ "-e #{name.shellescape}=#{value.shellescape}"
159
+ end.join(" ")
160
+ end
161
+ end
162
+ end