ruby_raider 4.0.1 → 4.2.0
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/.github/workflows/e2e_tests.yml +3 -0
- data/README.md +58 -1
- data/RELEASE.md +25 -0
- data/lib/commands/schedule_commands.rb +84 -0
- data/lib/generators/templates/common/git_ignore.tt +1 -0
- data/lib/ruby_raider/runtime/retry_reset.rb +32 -0
- data/lib/ruby_raider/runtime/rspec.rb +1 -0
- data/lib/ruby_raider/runtime/show_browser.rb +53 -0
- data/lib/ruby_raider/runtime.rb +2 -0
- data/lib/ruby_raider.rb +31 -0
- data/lib/utilities/schedules/adapter.rb +22 -0
- data/lib/utilities/schedules/base.rb +27 -0
- data/lib/utilities/schedules/kind.rb +74 -0
- data/lib/utilities/schedules/legacy.rb +196 -0
- data/lib/utilities/schedules/legacy_stub.rb +62 -0
- data/lib/utilities/schedules/next_run.rb +61 -0
- data/lib/utilities/schedules/notifier.rb +76 -0
- data/lib/utilities/schedules/os/command_runner.rb +73 -0
- data/lib/utilities/schedules/os/cron.rb +147 -0
- data/lib/utilities/schedules/os/launchd.rb +182 -0
- data/lib/utilities/schedules/os/linux.rb +81 -0
- data/lib/utilities/schedules/os/systemd.rb +194 -0
- data/lib/utilities/schedules/os/task_scheduler.rb +195 -0
- data/lib/utilities/schedules/os_enumerator.rb +30 -0
- data/lib/utilities/schedules/project.rb +70 -0
- data/lib/utilities/schedules/rule.rb +162 -0
- data/lib/utilities/schedules/run_lock.rb +160 -0
- data/lib/utilities/schedules/run_log.rb +122 -0
- data/lib/utilities/schedules/run_report.rb +139 -0
- data/lib/utilities/schedules/run_wrapper.rb +216 -0
- data/lib/utilities/schedules/schedule.rb +89 -0
- data/lib/utilities/schedules/schedule_store.rb +53 -0
- data/lib/utilities/schedules/scheduler.rb +178 -0
- data/lib/utilities/schedules/scheduler_steps.rb +69 -0
- data/lib/utilities/schedules/selection.rb +133 -0
- data/lib/utilities/schedules/spawn.rb +68 -0
- data/lib/utilities/schedules/store.rb +139 -0
- data/lib/version +1 -1
- data/ruby_raider.gemspec +1 -0
- data/sig/commands/schedule_commands.rbs +12 -0
- data/sig/ruby_raider/runtime/retry_reset.rbs +7 -0
- data/sig/ruby_raider/runtime/show_browser.rbs +27 -0
- data/sig/ruby_raider.rbs +6 -0
- data/sig/utilities/schedules/adapter.rbs +5 -0
- data/sig/utilities/schedules/base.rbs +15 -0
- data/sig/utilities/schedules/kind.rbs +32 -0
- data/sig/utilities/schedules/legacy.rbs +45 -0
- data/sig/utilities/schedules/legacy_stub.rbs +15 -0
- data/sig/utilities/schedules/next_run.rbs +15 -0
- data/sig/utilities/schedules/notifier.rbs +29 -0
- data/sig/utilities/schedules/os/command_runner.rbs +27 -0
- data/sig/utilities/schedules/os/cron.rbs +34 -0
- data/sig/utilities/schedules/os/launchd.rbs +46 -0
- data/sig/utilities/schedules/os/linux.rbs +33 -0
- data/sig/utilities/schedules/os/systemd.rbs +44 -0
- data/sig/utilities/schedules/os/task_scheduler.rbs +56 -0
- data/sig/utilities/schedules/os_enumerator.rbs +12 -0
- data/sig/utilities/schedules/project.rbs +22 -0
- data/sig/utilities/schedules/rule.rbs +72 -0
- data/sig/utilities/schedules/run_lock.rbs +29 -0
- data/sig/utilities/schedules/run_log.rbs +33 -0
- data/sig/utilities/schedules/run_report.rbs +34 -0
- data/sig/utilities/schedules/run_wrapper.rbs +45 -0
- data/sig/utilities/schedules/schedule.rbs +27 -0
- data/sig/utilities/schedules/schedule_store.rbs +21 -0
- data/sig/utilities/schedules/scheduler.rbs +49 -0
- data/sig/utilities/schedules/scheduler_steps.rbs +22 -0
- data/sig/utilities/schedules/selection.rbs +36 -0
- data/sig/utilities/schedules/spawn.rbs +10 -0
- data/sig/utilities/schedules/store.rbs +39 -0
- data/spec/commands/schedule_commands_spec.rb +284 -0
- data/spec/integration/content/common_content_spec.rb +8 -2
- data/spec/integration/content/gemfile_content_spec.rb +2 -2
- data/spec/runtime/retry_reset_spec.rb +112 -0
- data/spec/runtime/show_browser_project_spec.rb +70 -0
- data/spec/runtime/show_browser_spec.rb +101 -0
- data/spec/utilities/schedules/kind_spec.rb +81 -0
- data/spec/utilities/schedules/legacy_spec.rb +433 -0
- data/spec/utilities/schedules/legacy_stub_spec.rb +144 -0
- data/spec/utilities/schedules/next_run_spec.rb +119 -0
- data/spec/utilities/schedules/notifier_spec.rb +120 -0
- data/spec/utilities/schedules/os/command_runner_spec.rb +55 -0
- data/spec/utilities/schedules/os/cron_spec.rb +292 -0
- data/spec/utilities/schedules/os/launchd_spec.rb +306 -0
- data/spec/utilities/schedules/os/linux_spec.rb +163 -0
- data/spec/utilities/schedules/os/list_ids_spec.rb +202 -0
- data/spec/utilities/schedules/os/systemd_spec.rb +333 -0
- data/spec/utilities/schedules/os/task_scheduler_spec.rb +511 -0
- data/spec/utilities/schedules/os_entry_spec.rb +54 -0
- data/spec/utilities/schedules/os_enumerator_spec.rb +57 -0
- data/spec/utilities/schedules/project_spec.rb +125 -0
- data/spec/utilities/schedules/run_lock_spec.rb +143 -0
- data/spec/utilities/schedules/run_log_spec.rb +83 -0
- data/spec/utilities/schedules/run_report_spec.rb +150 -0
- data/spec/utilities/schedules/run_wrapper_integration_spec.rb +166 -0
- data/spec/utilities/schedules/run_wrapper_spec.rb +430 -0
- data/spec/utilities/schedules/schedule_spec.rb +120 -0
- data/spec/utilities/schedules/schedule_store_spec.rb +151 -0
- data/spec/utilities/schedules/scheduler_launchd_spec.rb +77 -0
- data/spec/utilities/schedules/scheduler_spec.rb +445 -0
- data/spec/utilities/schedules/selection_spec.rb +176 -0
- data/spec/utilities/schedules/spawn_spec.rb +104 -0
- metadata +106 -2
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rbconfig'
|
|
4
|
+
require_relative 'base'
|
|
5
|
+
require_relative 'os/task_scheduler'
|
|
6
|
+
|
|
7
|
+
module RubyRaider
|
|
8
|
+
module Schedules
|
|
9
|
+
# Which tests a schedule runs: all of them, one tag, or listed spec files. Immutable.
|
|
10
|
+
# Checking is in two steps: the shape and every path's syntax (new, from_h: a schedules.yml entry still
|
|
11
|
+
# loads when a file was deleted), and whether each file is there (parse for add, check! for run). A file
|
|
12
|
+
# that is there but resolves outside the project is refused by both.
|
|
13
|
+
# :reek:MissingSafeMethod { exclude: [ check! ] } -- a check that raises; missing_file is its safe twin
|
|
14
|
+
# :reek:TooManyConstants { max_constants: 7 } -- the kinds, the tag and file rules, the cap, Windows
|
|
15
|
+
class Selection
|
|
16
|
+
KINDS = %w[all tag files].freeze
|
|
17
|
+
KEYS = %w[kind tag files].freeze
|
|
18
|
+
TAG = /\A[A-Za-z0-9_:-]+\z/
|
|
19
|
+
MAX_FILES = 200
|
|
20
|
+
WINDOWS = /mswin|mingw|cygwin/
|
|
21
|
+
FILE_RULE = 'use a path inside the project ending in _spec.rb, with no .. and no leading - or /'
|
|
22
|
+
WINDOWS_RULE = 'Task Scheduler and ruby.exe would expand %...%, *, ?, [ or { in it on Windows: rename the file or use a tag'
|
|
23
|
+
|
|
24
|
+
attr_reader :kind, :tag, :files
|
|
25
|
+
|
|
26
|
+
def self.all = new(kind: 'all')
|
|
27
|
+
|
|
28
|
+
# What `raider schedule add` was given: no files and no tag is all tests; every file must be there
|
|
29
|
+
def self.parse(files:, tag:, root:, host_os: RbConfig::CONFIG['host_os'])
|
|
30
|
+
raise Error, 'Invalid spec files: use a list of paths' unless files.is_a?(Array)
|
|
31
|
+
raise Error, 'Use --tag or spec files, not both' if !tag.nil? && !files.empty?
|
|
32
|
+
|
|
33
|
+
selection = if !tag.nil? then new(kind: 'tag', tag: tag)
|
|
34
|
+
elsif files.empty? then all
|
|
35
|
+
else new(kind: 'files', files: files, host_os: host_os)
|
|
36
|
+
end
|
|
37
|
+
selection.check!(root)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# The selection of a schedules.yml entry; a missing file still loads (missing_file names it)
|
|
41
|
+
def self.from_h(hash, root:, host_os: RbConfig::CONFIG['host_os'])
|
|
42
|
+
raise Error, 'Invalid selection: use kind all, tag or files' unless hash.is_a?(Hash) && (hash.keys - KEYS).empty?
|
|
43
|
+
|
|
44
|
+
selection = new(kind: hash['kind'], tag: hash['tag'], files: hash['files'], host_os: host_os)
|
|
45
|
+
selection.missing_file(root)
|
|
46
|
+
selection
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def initialize(kind:, tag: nil, files: nil, host_os: RbConfig::CONFIG['host_os'])
|
|
50
|
+
raise Error, "Invalid selection kind #{kind.inspect}: use all, tag or files" unless KINDS.include?(kind)
|
|
51
|
+
|
|
52
|
+
@kind = kind.dup.freeze
|
|
53
|
+
@tag = kind == 'tag' ? checked_tag(tag) : nothing('tag', tag)
|
|
54
|
+
@files = kind == 'files' ? checked_files(files, host_os.match?(WINDOWS)) : nothing('files', files) || [].freeze
|
|
55
|
+
freeze
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The first listed file that is not in the project (nil when all are there); raises when one resolves
|
|
59
|
+
# outside the project. root is the project's real path.
|
|
60
|
+
def missing_file(root) = files.reject { |file| present?(root, file) }.first
|
|
61
|
+
|
|
62
|
+
# Itself when every file is there, otherwise raises
|
|
63
|
+
def check!(root)
|
|
64
|
+
missing = missing_file(root)
|
|
65
|
+
raise Error, "#{missing} not found" if missing
|
|
66
|
+
|
|
67
|
+
self
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_h
|
|
71
|
+
case kind
|
|
72
|
+
when 'tag' then { 'kind' => kind, 'tag' => tag }
|
|
73
|
+
when 'files' then { 'kind' => kind, 'files' => files.dup }
|
|
74
|
+
else { 'kind' => kind }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def nothing(label, value)
|
|
81
|
+
raise Error, "Invalid selection: #{label} is only for kind #{label == 'tag' ? 'tag' : 'files'}" unless value.nil?
|
|
82
|
+
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def checked_tag(tag)
|
|
87
|
+
return tag.dup.freeze if tag.is_a?(String) && tag.valid_encoding? && TAG.match?(tag)
|
|
88
|
+
|
|
89
|
+
raise Error, "Invalid tag #{Schedules.printable(tag.inspect)}: use letters, digits, _, : and -"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Duplicates removed, order kept, then counted
|
|
93
|
+
def checked_files(files, windows)
|
|
94
|
+
raise Error, 'Invalid spec files: use a list of one or more paths' unless files.is_a?(Array) && !files.empty?
|
|
95
|
+
|
|
96
|
+
unique = files.map { |file| checked_file(file, windows) }.uniq
|
|
97
|
+
raise Error, "Too many spec files (#{unique.size}): select at most #{MAX_FILES}, or use a tag" if unique.size > MAX_FILES
|
|
98
|
+
|
|
99
|
+
unique.freeze
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def checked_file(file, windows)
|
|
103
|
+
raise Error, "Invalid spec file #{Schedules.printable(file.inspect)}: #{FILE_RULE}" unless spec_path?(file, windows)
|
|
104
|
+
raise Error, "Invalid spec file #{file.inspect}: #{WINDOWS_RULE}" if windows && file.match?(Regexp.union(Os::TaskScheduler::EXPANDS, Os::TaskScheduler::GLOB))
|
|
105
|
+
|
|
106
|
+
file.dup.freeze
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def spec_path?(file, windows)
|
|
110
|
+
file.is_a?(String) && file.valid_encoding? && !file.match?(/[[:cntrl:]]/) && file.end_with?('_spec.rb') && relative?(file, windows)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def relative?(file, windows)
|
|
114
|
+
return false if file.start_with?('-', '/') || File.absolute_path?(file)
|
|
115
|
+
return false if windows && file.match?(/\A(?:\\|[A-Za-z]:)/)
|
|
116
|
+
|
|
117
|
+
!file.split(windows ? %r{[/\\]} : '/').include?('..')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# true when the file is in the project, false when it is not there; raises when it resolves outside
|
|
121
|
+
def present?(root, file)
|
|
122
|
+
real = File.realpath(File.join(root, file))
|
|
123
|
+
raise Error, "#{file} points outside the project" unless real.start_with?("#{root}#{File::SEPARATOR}")
|
|
124
|
+
|
|
125
|
+
File.file?(real)
|
|
126
|
+
rescue Errno::ENOENT, Errno::ENOTDIR
|
|
127
|
+
false
|
|
128
|
+
rescue SystemCallError => e
|
|
129
|
+
raise Error, "#{file} can't be read: #{e.message}"
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'English'
|
|
4
|
+
|
|
5
|
+
module RubyRaider
|
|
6
|
+
module Schedules
|
|
7
|
+
# Runs one rspec process with an argv array and no shell, under the project's own bundle rather
|
|
8
|
+
# than the one raider runs in, and stops it the way a person would: with exactly one INT.
|
|
9
|
+
#
|
|
10
|
+
# rspec stops gracefully on its first INT (it finishes the example, prints the summary and runs at_exit
|
|
11
|
+
# hooks, where raider_reporter writes run.json) and force-quits on a second one. The child stays in the
|
|
12
|
+
# terminal's process group (it can read the terminal, and a closed terminal ends it), so a Ctrl-C typed
|
|
13
|
+
# there already reached it. Hence:
|
|
14
|
+
# - TERM is always passed on as one INT;
|
|
15
|
+
# - INT is passed on only with forward_int (true when the INT can't have come from the terminal, e.g.
|
|
16
|
+
# stdin is not a TTY); otherwise the child is taken to have had it;
|
|
17
|
+
# - a signal before the child exists is passed on once it does;
|
|
18
|
+
# - never more than one INT per run. On Windows the console already sent Ctrl-C to the child.
|
|
19
|
+
module Spawn
|
|
20
|
+
# [exit status (nil when it could not start or died of a signal), true when INT or TERM stopped it]
|
|
21
|
+
def self.call(env, argv, chdir, forward_int: true)
|
|
22
|
+
state = { pid: nil, stopped: false, interrupted: false }
|
|
23
|
+
code = run(env, argv, chdir, state, forward_int)
|
|
24
|
+
[code, state[:stopped] == true]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The exit status, with the traps set from before the spawn (so a stop in between is not lost) to the end
|
|
28
|
+
def self.run(env, argv, chdir, state, forward_int)
|
|
29
|
+
previous = %w[INT TERM].to_h { |signal| [signal, trap(signal) { stop(state, signal, forward_int) }] }
|
|
30
|
+
wait = lambda do
|
|
31
|
+
pid = state[:pid] = Process.spawn(env, *argv, chdir: chdir)
|
|
32
|
+
interrupt(state) if state[:stopped]
|
|
33
|
+
Process.wait(pid)
|
|
34
|
+
# Reaped: its pid may be reused, so a later signal must not reach it
|
|
35
|
+
state[:pid] = nil
|
|
36
|
+
$CHILD_STATUS.exitstatus
|
|
37
|
+
end
|
|
38
|
+
defined?(Bundler) ? Bundler.with_unbundled_env(&wait) : wait.call
|
|
39
|
+
rescue SystemCallError => e
|
|
40
|
+
warn("Could not start #{argv.first}: #{e.message}")
|
|
41
|
+
nil
|
|
42
|
+
ensure
|
|
43
|
+
previous&.each { |signal, handler| trap(signal, handler || 'DEFAULT') }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Called from the trap: marks the run stopped and passes the signal on as INT when the child needs it
|
|
47
|
+
def self.stop(state, signal, forward_int)
|
|
48
|
+
state[:stopped] = true
|
|
49
|
+
return unless state[:pid] # passed on right after the spawn
|
|
50
|
+
|
|
51
|
+
# A terminal Ctrl-C reached the child too: count it as the child's one INT
|
|
52
|
+
return state[:interrupted] = true if signal == 'INT' && !forward_int
|
|
53
|
+
|
|
54
|
+
interrupt(state)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# INT, at most once per run
|
|
58
|
+
def self.interrupt(state)
|
|
59
|
+
return if state[:interrupted] || Gem.win_platform?
|
|
60
|
+
|
|
61
|
+
state[:interrupted] = true
|
|
62
|
+
Process.kill('INT', state[:pid])
|
|
63
|
+
rescue SystemCallError
|
|
64
|
+
nil
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'securerandom'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
|
|
8
|
+
module RubyRaider
|
|
9
|
+
module Schedules
|
|
10
|
+
# <kind dir>/schedules.yml: a project's schedules of one kind, sorted by name. The OS entries are made
|
|
11
|
+
# from it; it is written whole through a temp file and a rename, so a reader never sees half a file.
|
|
12
|
+
# A subclass passes the schedule class (a Rule with from_h, to_h and os_id_for); its Kind names the folder.
|
|
13
|
+
# :reek:MissingSafeMethod { exclude: [ writable! ] } -- a check that raises, with no safe twin to offer
|
|
14
|
+
class Store
|
|
15
|
+
FILE = 'schedules.yml'
|
|
16
|
+
NOFOLLOW = defined?(File::NOFOLLOW) ? File::NOFOLLOW : 0
|
|
17
|
+
NONBLOCK = defined?(File::NONBLOCK) ? File::NONBLOCK : 0
|
|
18
|
+
|
|
19
|
+
# What delete returns for an entry it removed but could not read: enough to remove its OS entry
|
|
20
|
+
class Removed
|
|
21
|
+
attr_reader :name, :os_id
|
|
22
|
+
|
|
23
|
+
def initialize(name, os_id)
|
|
24
|
+
@name = name
|
|
25
|
+
@os_id = os_id
|
|
26
|
+
freeze
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def initialize(project, schedule_class)
|
|
31
|
+
@project = project
|
|
32
|
+
@schedule_class = schedule_class
|
|
33
|
+
@dir = schedule_class.kind.dir
|
|
34
|
+
@file = project.path("#{@dir}/#{FILE}")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Every valid entry, sorted by name; a broken entry or file is skipped
|
|
38
|
+
def all
|
|
39
|
+
entries = read_entries
|
|
40
|
+
return [] unless entries
|
|
41
|
+
|
|
42
|
+
entries.filter_map { |entry| from_entry(entry) }.sort_by(&:name)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def find(name) = all.find { |schedule| schedule.name == name }
|
|
46
|
+
|
|
47
|
+
# Adds the schedule, or replaces the one with its name
|
|
48
|
+
def save(schedule)
|
|
49
|
+
write(writable_entries.reject { |entry| named?(entry, schedule.name) } + [schedule.to_h])
|
|
50
|
+
schedule
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Raises the Error save and delete would, before anything else is changed
|
|
54
|
+
def writable!
|
|
55
|
+
writable_entries
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Removes every entry with the name, readable or not. Returns the removed schedule, a Removed
|
|
60
|
+
# (name and os_id) when the entry could not be read, or nil when there was none.
|
|
61
|
+
def delete(name)
|
|
62
|
+
entries = writable_entries
|
|
63
|
+
named, kept = entries.partition { |entry| named?(entry, name) }
|
|
64
|
+
return nil if named.empty?
|
|
65
|
+
|
|
66
|
+
write(kept)
|
|
67
|
+
named.filter_map { |entry| from_entry(entry) }.first || Removed.new(name, @schedule_class.os_id_for(@project.root, name))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
attr_reader :project
|
|
73
|
+
|
|
74
|
+
def from_entry(entry)
|
|
75
|
+
@schedule_class.from_h(entry, @project.root)
|
|
76
|
+
rescue Error
|
|
77
|
+
nil
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def named?(entry, name) = entry.is_a?(Hash) && entry['name'] == name
|
|
81
|
+
|
|
82
|
+
# The raw entries, nil when the file is not a schedules file or can't be read (missing reads as empty)
|
|
83
|
+
def read_entries
|
|
84
|
+
text = read_text
|
|
85
|
+
return [] if text.nil?
|
|
86
|
+
return nil unless text
|
|
87
|
+
|
|
88
|
+
data = YAML.safe_load(text)
|
|
89
|
+
return [] if data.nil?
|
|
90
|
+
|
|
91
|
+
entries = data.is_a?(Hash) ? data['schedules'] : nil
|
|
92
|
+
entries.is_a?(Array) ? entries : nil
|
|
93
|
+
rescue Psych::Exception
|
|
94
|
+
nil
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The entries to rewrite, keeping ones this version can't read; refuses to overwrite a broken file
|
|
98
|
+
def writable_entries
|
|
99
|
+
read_entries || raise(Error, "#{@dir}/#{FILE} is not a schedules file: fix or remove it, then try again")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Read through one handle that is not a link; nil when there is no file, false when it is a link,
|
|
103
|
+
# not a regular file or can't be read (so a write never replaces what it could not see)
|
|
104
|
+
def read_text
|
|
105
|
+
File.open(@file, File::RDONLY | NONBLOCK | NOFOLLOW) do |file|
|
|
106
|
+
file.stat.file? ? file.read.to_s.force_encoding(Encoding::UTF_8) : false
|
|
107
|
+
end
|
|
108
|
+
rescue Errno::ENOENT
|
|
109
|
+
nil
|
|
110
|
+
rescue SystemCallError
|
|
111
|
+
false
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def write(entries)
|
|
115
|
+
dir = private_dir
|
|
116
|
+
sorted = entries.sort_by { |entry| entry.is_a?(Hash) ? entry['name'].to_s : '' }
|
|
117
|
+
temp = File.join(dir, ".#{FILE}.#{SecureRandom.hex(6)}.tmp")
|
|
118
|
+
File.open(temp, File::WRONLY | File::CREAT | File::EXCL | NOFOLLOW, 0o600) do |file|
|
|
119
|
+
file.write(YAML.dump({ 'schedules' => sorted }))
|
|
120
|
+
file.flush
|
|
121
|
+
file.fsync
|
|
122
|
+
end
|
|
123
|
+
File.rename(temp, @file)
|
|
124
|
+
ensure
|
|
125
|
+
FileUtils.rm_f(temp) if temp && File.exist?(temp)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# A 0700 folder inside the project that is not a link
|
|
129
|
+
def private_dir
|
|
130
|
+
dir = @project.path(@dir)
|
|
131
|
+
FileUtils.mkdir_p(dir)
|
|
132
|
+
raise Error, "#{@dir} must be a folder, not a link" unless File.lstat(dir).directory?
|
|
133
|
+
|
|
134
|
+
File.chmod(0o700, dir)
|
|
135
|
+
dir
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0
|
|
1
|
+
4.2.0
|
data/ruby_raider.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.add_development_dependency 'rake', '~> 13.0.6'
|
|
19
19
|
s.add_development_dependency 'reek', '~> 6.5'
|
|
20
20
|
s.add_development_dependency 'rspec', '~> 3.11.0'
|
|
21
|
+
s.add_development_dependency 'rspec-retry', '~> 0.6'
|
|
21
22
|
s.add_development_dependency 'rubocop', '~> 1.27'
|
|
22
23
|
s.add_development_dependency 'rubocop-performance', '~> 1.15.0'
|
|
23
24
|
s.add_development_dependency 'rubocop-rspec', '~> 2.9.0'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Type definitions for ScheduleCommands
|
|
2
|
+
class ScheduleCommands < Thor
|
|
3
|
+
def add: (String name, *String files) -> void
|
|
4
|
+
def list: () -> void
|
|
5
|
+
def remove: (String name) -> void
|
|
6
|
+
def run_schedule: (String name) -> bot
|
|
7
|
+
def new_project: () -> RubyRaider::Schedules::Project
|
|
8
|
+
def cleaned_project: () -> RubyRaider::Schedules::Project
|
|
9
|
+
def cleanup: (RubyRaider::Schedules::Project project) -> String?
|
|
10
|
+
def scheduler: () -> RubyRaider::Schedules::Scheduler
|
|
11
|
+
def stop: (RubyRaider::Schedules::Error error) -> bot
|
|
12
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Raider
|
|
2
|
+
module ShowBrowser
|
|
3
|
+
ENV_KEY: String
|
|
4
|
+
OPTIONS: Array[String]
|
|
5
|
+
SWITCHES: Array[String]
|
|
6
|
+
PREFIX: String
|
|
7
|
+
ARGS_KEYS: Array[Symbol | String]
|
|
8
|
+
|
|
9
|
+
def self.headless?: (untyped arg) -> bool
|
|
10
|
+
def self.without_headless: (untyped args) -> untyped
|
|
11
|
+
def self.install: (?_Env env) -> Array[Module]
|
|
12
|
+
|
|
13
|
+
def headless?: (untyped arg) -> bool
|
|
14
|
+
def without_headless: (untyped args) -> untyped
|
|
15
|
+
def install: (?_Env env) -> Array[Module]
|
|
16
|
+
|
|
17
|
+
interface _Env
|
|
18
|
+
def []: (String) -> String?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module Filter
|
|
22
|
+
def initialize: (**untyped opts) -> void
|
|
23
|
+
def add_argument: (untyped arg) -> untyped
|
|
24
|
+
def args=: (untyped value) -> untyped
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/sig/ruby_raider.rbs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Type definitions for main RubyRaider entry point
|
|
2
2
|
module RubyRaider
|
|
3
3
|
class Raider < Thor
|
|
4
|
+
GUARDED: Array[String]
|
|
5
|
+
LEGACY: Array[String]
|
|
6
|
+
|
|
7
|
+
def self.start: (?Array[String] given_args, ?Hash[Symbol, untyped] config) -> void
|
|
8
|
+
def self.legacy_stub: (Array[String] given_args) -> Integer
|
|
9
|
+
|
|
4
10
|
def current_version: () -> String
|
|
5
11
|
|
|
6
12
|
def new: (String project_name) -> void
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
NAME: Regexp
|
|
4
|
+
DAYS: Array[String]
|
|
5
|
+
|
|
6
|
+
def self.valid_name?: (untyped name) -> bool
|
|
7
|
+
def self.printable: (untyped text) -> String
|
|
8
|
+
|
|
9
|
+
class Error < StandardError
|
|
10
|
+
attr_reader exit_code: Integer
|
|
11
|
+
|
|
12
|
+
def initialize: (String message, ?exit_code: Integer) -> void
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
class Kind
|
|
4
|
+
FLOW_LEGACY: Kind
|
|
5
|
+
TESTS: Kind
|
|
6
|
+
|
|
7
|
+
attr_reader command: String
|
|
8
|
+
attr_reader os_id_prefix: String
|
|
9
|
+
attr_reader os_id_pattern: Regexp
|
|
10
|
+
attr_reader dir: String
|
|
11
|
+
attr_reader noun: String
|
|
12
|
+
attr_reader plural: String
|
|
13
|
+
attr_reader remove_command: String
|
|
14
|
+
attr_reader stranded_hint: String?
|
|
15
|
+
attr_reader reserved: Array[String]
|
|
16
|
+
|
|
17
|
+
def initialize: (command: String, dir: String, noun: String, plural: String, remove_command: String, ?stranded_hint: String?, ?reserved: Array[String]) -> void
|
|
18
|
+
def valid_name?: (untyped name) -> bool
|
|
19
|
+
def name_in: (untyped os_id) -> String?
|
|
20
|
+
def listed?: (untyped os_id, String prefix) -> bool
|
|
21
|
+
def cron_tag: () -> String
|
|
22
|
+
def our_command?: (String text, String? name) -> bool
|
|
23
|
+
def task_description: (String name, String rule) -> String
|
|
24
|
+
def task_file_prefix: () -> String
|
|
25
|
+
def service_description: (String name) -> String
|
|
26
|
+
def timer_description: (String name) -> String
|
|
27
|
+
def not_ours: () -> String
|
|
28
|
+
def stranded: (String name) -> String
|
|
29
|
+
def unsupported: (String host_os) -> String
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
class Legacy
|
|
4
|
+
KIND: Kind
|
|
5
|
+
FILE: String
|
|
6
|
+
MAX_BYTES: Integer
|
|
7
|
+
NOFOLLOW: Integer
|
|
8
|
+
NONBLOCK: Integer
|
|
9
|
+
|
|
10
|
+
class OldRule < Rule
|
|
11
|
+
def self.kind: () -> Kind
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@project: Project
|
|
15
|
+
@root: String
|
|
16
|
+
@adapter: untyped
|
|
17
|
+
@err: untyped
|
|
18
|
+
@yml_clean: bool
|
|
19
|
+
|
|
20
|
+
def self.folder?: (Project project) -> bool
|
|
21
|
+
|
|
22
|
+
def initialize: (Project project, ?adapter: untyped, ?err: untyped) -> void
|
|
23
|
+
def cleanup: (?last: String?) -> String?
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def adapter: () -> untyped
|
|
28
|
+
def remove_all: (untyped current, Array[String] names) -> [Array[String], Array[[String, String]]]
|
|
29
|
+
def remove_own: (untyped current, String name) -> void
|
|
30
|
+
def notice: (Array[String] removed, Array[[String, String]] failed) -> String?
|
|
31
|
+
def removed_text: (Array[String] names) -> String
|
|
32
|
+
def failed_text: (Array[[String, String]] failed) -> String
|
|
33
|
+
def counted: (Integer count) -> String
|
|
34
|
+
def say: (String text) -> String?
|
|
35
|
+
def dir: () -> String
|
|
36
|
+
def yml: () -> String
|
|
37
|
+
def real_dirs?: () -> bool
|
|
38
|
+
def yml_names: () -> Array[String]
|
|
39
|
+
def entry_name: (untyped entry) -> String?
|
|
40
|
+
def read_entries: () -> Array[untyped]?
|
|
41
|
+
def read_text: () -> String?
|
|
42
|
+
def delete_yml: () -> void
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
module LegacyStub
|
|
4
|
+
EXIT: Integer
|
|
5
|
+
REMOVED: String
|
|
6
|
+
OPTION: String
|
|
7
|
+
|
|
8
|
+
def self.run: (Array[untyped] argv, ?err: untyped) -> Integer
|
|
9
|
+
def self.clean: (String root, String? name, untyped err) -> void
|
|
10
|
+
def self.project_root: (Array[untyped] argv) -> String?
|
|
11
|
+
def self.project_value: (Array[untyped] argv) -> untyped
|
|
12
|
+
def self.own_name: (Array[untyped] argv) -> String?
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
module NextRun
|
|
4
|
+
WDAYS: Array[String]
|
|
5
|
+
SEARCH_DAYS: Integer
|
|
6
|
+
SEARCH_MINUTES: Integer
|
|
7
|
+
|
|
8
|
+
def self?.after: (_OsEntry schedule, Time now) -> Time
|
|
9
|
+
def self?.next_minute: (Integer minute, Time now) -> Time
|
|
10
|
+
def self?.next_day: (_OsEntry schedule, Time now) -> Time
|
|
11
|
+
def self?.local: (Date date, Integer hour, Integer minute) -> Time
|
|
12
|
+
def self?.wall: (Time time) -> Array[Integer]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
class Notifier
|
|
4
|
+
MAX: Integer
|
|
5
|
+
TIMEOUT: Integer
|
|
6
|
+
OSASCRIPT: Array[String]
|
|
7
|
+
NOTIFY_SEND: Array[String]
|
|
8
|
+
MARKUP: Hash[String, String]
|
|
9
|
+
TOAST_SCRIPT: String
|
|
10
|
+
POWERSHELL_ARGS: Array[String]
|
|
11
|
+
|
|
12
|
+
@runner: Os::CommandRunner
|
|
13
|
+
@host_os: String
|
|
14
|
+
@err: IO | StringIO
|
|
15
|
+
@warned: bool
|
|
16
|
+
@powershell: String
|
|
17
|
+
|
|
18
|
+
def self.powershell: () -> String
|
|
19
|
+
|
|
20
|
+
def initialize: (?runner: Os::CommandRunner, ?host_os: String, ?err: IO | StringIO, ?powershell: String) -> void
|
|
21
|
+
def notify: (String title, String message) -> bool
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def clean: (untyped text) -> String
|
|
26
|
+
def failed: (String reason) -> false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
module Os
|
|
4
|
+
class CommandRunner
|
|
5
|
+
MISSING: Integer
|
|
6
|
+
TIMED_OUT: Integer
|
|
7
|
+
|
|
8
|
+
class Result
|
|
9
|
+
attr_reader stdout: String
|
|
10
|
+
attr_reader stderr: String
|
|
11
|
+
attr_reader exitstatus: Integer
|
|
12
|
+
|
|
13
|
+
def initialize: (stdout: String, stderr: String, exitstatus: Integer) -> void
|
|
14
|
+
def success?: () -> bool
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call: (*String argv, ?stdin_data: String?, ?env: Hash[String, String], ?timeout: Numeric?) -> Result
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def reader: (IO io) -> Thread
|
|
22
|
+
def feed: (IO stdin, String? data) -> void
|
|
23
|
+
def timed_out: (String command, Numeric? timeout, untyped wait) -> Result
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module RubyRaider
|
|
2
|
+
module Schedules
|
|
3
|
+
module Os
|
|
4
|
+
class Cron
|
|
5
|
+
CRONTAB: String
|
|
6
|
+
MAX_LINE: Integer
|
|
7
|
+
|
|
8
|
+
@kind: Kind
|
|
9
|
+
@runner: CommandRunner
|
|
10
|
+
|
|
11
|
+
def initialize: (kind: Kind, ?runner: CommandRunner) -> void
|
|
12
|
+
def label: () -> String
|
|
13
|
+
def missed_runs_note: () -> String
|
|
14
|
+
def line: (_OsEntry schedule) -> String
|
|
15
|
+
def install: (_OsEntry schedule) -> true
|
|
16
|
+
def remove: (String os_id) -> bool
|
|
17
|
+
def present?: (String os_id) -> bool
|
|
18
|
+
def list_ids: (String prefix) -> Array[String]
|
|
19
|
+
def usable?: () -> bool
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def fields: (_OsEntry schedule) -> String
|
|
24
|
+
def weekday: (String day) -> Integer
|
|
25
|
+
def escape: (String word) -> String
|
|
26
|
+
def without: (String table, String os_id) -> [String, bool]
|
|
27
|
+
def our_command?: (String text, String? name) -> bool
|
|
28
|
+
def read: () -> String
|
|
29
|
+
def save: (String table) -> void
|
|
30
|
+
def checked_os_id: (untyped os_id) -> String
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|