parallel_tests-ci 0.1.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 +7 -0
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/lib/parallel_tests/ci/github.rb +118 -0
- data/lib/parallel_tests/ci/run.rb +170 -0
- data/lib/parallel_tests/ci/runtime_log.rb +55 -0
- data/lib/parallel_tests/ci/version.rb +8 -0
- data/lib/parallel_tests/ci.rb +5 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 864c6fb5008d5737a937835d216eecd499c329ca7fb392c2348b692e89329f46
|
|
4
|
+
data.tar.gz: 454b3b97fde4b123fc36f433e4f5879283af643e17b86adfb44ef0e47eac6111
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 38086198f85476845325ad56e9e842cd50ce1228941d83745eac4f7358c6c31518d5fa6fd2f1d3c8f1188d32f5a6610ce882bcfe093356eaf7f5dcdee8a9f0c3
|
|
7
|
+
data.tar.gz: 034e3729db3f02d3d292df77c229b8e924e513afa88944275db27add15dc4b5604713cd485eb89031fd0d319dd8f11d20277bf32c716a5c5ecc017d60fbba7e3
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026/11/19)
|
|
4
|
+
|
|
5
|
+
- [#2](https://github.com/dblock/parallel_tests-ci/pull/2): Add runtime-balanced RSpec shards and automatic trusted timing history - [@dblock](https://github.com/dblock).
|
|
6
|
+
- [#4](https://github.com/dblock/parallel_tests-ci/pull/4): Add an editable cube logo and PNG - [@dblock](https://github.com/dblock).
|
|
7
|
+
- [#5](https://github.com/dblock/parallel_tests-ci/pull/5): Label workers with position and actual total - [@dblock](https://github.com/dblock).
|
|
8
|
+
- [#6](https://github.com/dblock/parallel_tests-ci/pull/6): Add namespaced worker-name templates - [@dblock](https://github.com/dblock).
|
|
9
|
+
- [#7](https://github.com/dblock/parallel_tests-ci/pull/7): Pass workflow inputs to Ruby as JSON - [@dblock](https://github.com/dblock).
|
|
10
|
+
- [#8](https://github.com/dblock/parallel_tests-ci/pull/8): Configure runners, execution, caching, checkout, and artifact retention - [@dblock](https://github.com/dblock).
|
|
11
|
+
- [#10](https://github.com/dblock/parallel_tests-ci/pull/10): Document versioned 0.1.0 usage and shorten all guides - [@dblock](https://github.com/dblock).
|
|
12
|
+
- [#11](https://github.com/dblock/parallel_tests-ci/pull/11): Simplify test setup and output assertions, isolate validation cases, and scope consumer environment variables - [@dblock](https://github.com/dblock).
|
|
13
|
+
- [#12](https://github.com/dblock/parallel_tests-ci/pull/12): Remove the automatic Danger review message and skip new comments for empty reports - [@dblock](https://github.com/dblock).
|
|
14
|
+
- [#13](https://github.com/dblock/parallel_tests-ci/pull/13): Refine the cube logo with consistent 3D perspective and Test badge greens - [@dblock](https://github.com/dblock).
|
|
15
|
+
- [#14](https://github.com/dblock/parallel_tests-ci/pull/14): Link Posebook demo runs with cold and warm timing results and a test execution chart - [@dblock](https://github.com/dblock).
|
|
16
|
+
- [#16](https://github.com/dblock/parallel_tests-ci/pull/16): Document approved release protections and first-publication setup, and validate the installed package before release - [@dblock](https://github.com/dblock).
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Doubrovkine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<img src="assets/logo.svg" alt="A solid green cube beside eight outlined cubes in perspective" width="160">
|
|
2
|
+
|
|
3
|
+
# Parallel Tests CI
|
|
4
|
+
|
|
5
|
+
[](https://github.com/dblock/parallel_tests-ci/actions/workflows/test.yml) [](https://github.com/dblock/parallel_tests-ci/actions/workflows/lint.yml) [](https://github.com/dblock/parallel_tests-ci/actions/workflows/package.yml) [](https://coveralls.io/github/dblock/parallel_tests-ci?branch=master)
|
|
6
|
+
|
|
7
|
+
Runtime-balanced RSpec shards for GitHub Actions, powered by [parallel_tests](https://github.com/grosser/parallel_tests). Timing history is collected and reused automatically.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Requires Ruby 3.3+ and RSpec. Add to your Gemfile and run `bundle install`:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'parallel_tests-ci', '0.1.0', require: false
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add `.github/workflows/test.yml`:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
name: Test
|
|
23
|
+
on: [push, pull_request]
|
|
24
|
+
|
|
25
|
+
permissions:
|
|
26
|
+
contents: read
|
|
27
|
+
actions: read
|
|
28
|
+
|
|
29
|
+
jobs:
|
|
30
|
+
test:
|
|
31
|
+
name: Test
|
|
32
|
+
uses: dblock/parallel_tests-ci/.github/workflows/rspec.yml@v0.1.0
|
|
33
|
+
with:
|
|
34
|
+
shards: 8
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Ruby comes from your version file; workers use Ubuntu by default. The first run groups by file size. Successful default-branch pushes supply timings for later runs; PRs read them without updating history. Jobs appear as `Test / 1 of 8`, capped at matching file count. Keep gem and workflow versions matched.
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
### Runners and Execution
|
|
42
|
+
|
|
43
|
+
| Input | Default | Purpose |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `runs-on` | `ubuntu-latest` | Runner label or JSON label array for all jobs; Linux and macOS supported. |
|
|
46
|
+
| `timeout-minutes` | `360` | Minutes per job, including setup; positive integer, subject to runner limits. |
|
|
47
|
+
| `max-parallel` | `256` | Concurrent workers (1-256), subject to runner availability. |
|
|
48
|
+
| `fail-fast` | `false` | Cancel other workers when a worker fails. |
|
|
49
|
+
| `fetch-depth` | `1` | Checkout history depth in all jobs; `0` fetches all history and tags. |
|
|
50
|
+
| `ruby-version` | Empty | Override the caller's Ruby version file. |
|
|
51
|
+
| `bundler-cache` | `true` | Cache gems in all jobs; `false` still installs gems. |
|
|
52
|
+
|
|
53
|
+
### Suite and Setup
|
|
54
|
+
|
|
55
|
+
| Input | Default | Purpose |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| `shards` | `4` | Workers (1-256), capped at matching file count. |
|
|
58
|
+
| `worker-name` | `{shard.number} of {shard.count}` | Worker label template; empty uses the default. |
|
|
59
|
+
| `pattern` | `spec/**/*_spec.rb` | Repository-relative spec glob. |
|
|
60
|
+
| `rspec-options` | `[]` | JSON array of RSpec arguments. |
|
|
61
|
+
| `environment` | `{}` | JSON object of non-secret environment variables. |
|
|
62
|
+
| `before-bundle` | Empty | Shell setup before gems in every job. |
|
|
63
|
+
| `setup` | Empty | Shell setup before specs in each worker. |
|
|
64
|
+
|
|
65
|
+
### Artifacts
|
|
66
|
+
|
|
67
|
+
| Input | Default | Purpose |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| `artifacts` | Empty | Extra files to retain, including hidden files and failure diagnostics. |
|
|
70
|
+
| `artifact-prefix` | `parallel-tests-ci` | Unique per call; letters, numbers, underscores, and hyphens only. |
|
|
71
|
+
| `artifact-retention-days` | `30` | Days to retain plans, measurements, and test artifacts; `0` uses repository default. |
|
|
72
|
+
| `baseline-retention-days` | `90` | Days to retain trusted history; `0` uses repository default. |
|
|
73
|
+
|
|
74
|
+
See [Workflow Inputs](DESIGN.md#workflow-inputs) for templates, secret environments, and setup rules, and [Plans and Retries](DESIGN.md#plans-and-retries) for rerun behavior.
|
|
75
|
+
|
|
76
|
+
## Demo
|
|
77
|
+
|
|
78
|
+
[Posebook](https://github.com/dblock/posebook), a custom Rails CMS, runs 1,142 examples across eight workers. Times below are reported by RSpec and exclude setup and spec loading.
|
|
79
|
+
|
|
80
|
+
<img src="assets/demo.svg" alt="Slowest worker RSpec time: serial 395s, custom sharding 61.62s, parallel_tests alone 70.71s, parallel_tests-ci cold runs 79.11s and 79.03s, warm runs 57.59s and 62.90s" width="480">
|
|
81
|
+
|
|
82
|
+
- [Single-worker run](https://github.com/dblock/posebook/actions/runs/44218105420): No parallel tests; 395s.
|
|
83
|
+
- [#178](https://github.com/dblock/posebook/pull/178): Introduce custom sharding, no `parallel_tests`; slowest worker 61.62s.
|
|
84
|
+
- [#181](https://github.com/dblock/posebook/pull/181): `parallel_tests` alone, without `parallel_tests-ci`; slowest worker 70.71s.
|
|
85
|
+
- [#185](https://github.com/dblock/posebook/pull/185): Initial cold run; slowest worker 79.11s.
|
|
86
|
+
- [#186](https://github.com/dblock/posebook/pull/186): Repeat cold run, identical assignments; slowest worker 79.03s.
|
|
87
|
+
- [#187](https://github.com/dblock/posebook/pull/187): Warm history redistributed 85/95 files; slowest successful worker 57.59s.
|
|
88
|
+
- [#188](https://github.com/dblock/posebook/pull/188): Same warm assignments; slowest worker 62.90s.
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
See [Contributing](CONTRIBUTING.md), [Coding Guidance](AGENTS.md), [Design](DESIGN.md), [Changelog](CHANGELOG.md), and [Releasing](RELEASING.md).
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
Distributed under the [MIT License](LICENSE.txt).
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'parallel_tests/ci'
|
|
6
|
+
|
|
7
|
+
module ParallelTests
|
|
8
|
+
module CI
|
|
9
|
+
# Internal entry points used by the reusable workflow, not a consumer CLI.
|
|
10
|
+
module GitHub
|
|
11
|
+
DIRECTORY = 'tmp/parallel_tests_ci'
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def event
|
|
17
|
+
JSON.parse(File.read(ENV.fetch('GITHUB_EVENT_PATH')))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def prefix(value)
|
|
21
|
+
unless value.match?(/\A[a-zA-Z0-9][a-zA-Z0-9_-]*\z/)
|
|
22
|
+
raise ArgumentError, 'Artifact prefix must contain only letters, numbers, underscores, and hyphens'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
value
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def api(path, paginate: false)
|
|
29
|
+
arguments = ['gh', 'api', path]
|
|
30
|
+
arguments.push('--paginate', '--slurp') if paginate
|
|
31
|
+
output, error, status = Open3.capture3(*arguments)
|
|
32
|
+
raise Error, error unless status.success?
|
|
33
|
+
|
|
34
|
+
JSON.parse(output)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def find_history(inputs:)
|
|
38
|
+
repository = ENV.fetch('GITHUB_REPOSITORY')
|
|
39
|
+
artifact_prefix = prefix(inputs.fetch('artifact-prefix'))
|
|
40
|
+
successful_runs(repository).each do |run|
|
|
41
|
+
artifact = history_artifact(repository, run.fetch('id'), artifact_prefix: artifact_prefix)
|
|
42
|
+
next unless artifact
|
|
43
|
+
|
|
44
|
+
outputs(history_run: run.fetch('id'), history_artifact: artifact.fetch('id'))
|
|
45
|
+
break
|
|
46
|
+
end
|
|
47
|
+
rescue Error, JSON::ParserError, SystemCallError => e
|
|
48
|
+
warn "Timing history unavailable; using file sizes: #{e.message}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def successful_runs(repository)
|
|
52
|
+
current = api("repos/#{repository}/actions/runs/#{ENV.fetch('GITHUB_RUN_ID')}")
|
|
53
|
+
branch = URI.encode_www_form_component(event.fetch('repository').fetch('default_branch'))
|
|
54
|
+
path = "repos/#{repository}/actions/workflows/#{current.fetch('workflow_id')}/runs"
|
|
55
|
+
api("#{path}?branch=#{branch}&event=push&status=success&per_page=20")
|
|
56
|
+
.fetch('workflow_runs').select { |run| trusted_run?(run, repository) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def history_artifact(repository, id, artifact_prefix:)
|
|
60
|
+
pages = api("repos/#{repository}/actions/runs/#{id}/artifacts?per_page=100", paginate: true)
|
|
61
|
+
pages.flat_map { |page| page.fetch('artifacts') }.find do |entry|
|
|
62
|
+
entry.fetch('name') == "#{artifact_prefix}-runtimes" && !entry.fetch('expired')
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def trusted_run?(run, repository)
|
|
67
|
+
run.fetch('event') == 'push' && run.fetch('conclusion') == 'success' &&
|
|
68
|
+
run.fetch('head_branch') == event.fetch('repository').fetch('default_branch') &&
|
|
69
|
+
run.dig('head_repository', 'full_name') == repository
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def prepare(inputs:)
|
|
73
|
+
run = Run.prepare(directory: "#{DIRECTORY}/plan", history: "#{DIRECTORY}/history/runtime.log",
|
|
74
|
+
pattern: inputs.fetch('pattern'), shards: inputs.fetch('shards'),
|
|
75
|
+
rspec_options: JSON.parse(inputs.fetch('rspec-options')))
|
|
76
|
+
outputs(matrix: JSON.generate(worker_matrix(run, inputs: inputs)),
|
|
77
|
+
artifact: "#{prefix(inputs.fetch('artifact-prefix'))}-plan-#{ENV.fetch('GITHUB_RUN_ATTEMPT')}")
|
|
78
|
+
puts "Prepared #{run.plan.fetch('shards')} shards using #{run.plan.fetch('group_by')} grouping."
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def worker_matrix(run, inputs:)
|
|
82
|
+
template = inputs.fetch('worker-name', '')
|
|
83
|
+
template = '{shard.number} of {shard.count}' if template.empty?
|
|
84
|
+
values = { 'shard.count' => run.plan.fetch('shards').to_s, 'plan.group_by' => run.plan.fetch('group_by') }
|
|
85
|
+
run.matrix.map do |entry|
|
|
86
|
+
entry.merge(name: render_template(template, values.merge('shard.number' => entry.fetch(:shard).to_s)))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def render_template(template, values)
|
|
91
|
+
template.gsub(/\{([^{}]*)\}|[{}]/) do |token|
|
|
92
|
+
key = Regexp.last_match(1)
|
|
93
|
+
values.fetch(key) do
|
|
94
|
+
raise ArgumentError, "Unknown or malformed template placeholder: #{token}"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def run(inputs:, shard:)
|
|
100
|
+
attempt = ENV.fetch('GITHUB_RUN_ATTEMPT')
|
|
101
|
+
code = Run.new("#{DIRECTORY}/plan").run(shard: shard, attempt: attempt, directory: "#{DIRECTORY}/result")
|
|
102
|
+
outputs(artifact: "#{prefix(inputs.fetch('artifact-prefix'))}-shard-#{shard}-#{attempt}") if code.zero?
|
|
103
|
+
exit(code)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def collect
|
|
107
|
+
Run.new("#{DIRECTORY}/plan").collect(directory: "#{DIRECTORY}/results",
|
|
108
|
+
output: "#{DIRECTORY}/baseline/runtime.log")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def outputs(values)
|
|
112
|
+
File.open(ENV.fetch('GITHUB_OUTPUT'), 'a') do |file|
|
|
113
|
+
values.each { |key, value| file.puts "#{key}=#{value}" }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'parallel_tests'
|
|
7
|
+
require 'rbconfig'
|
|
8
|
+
require 'shellwords'
|
|
9
|
+
|
|
10
|
+
module ParallelTests
|
|
11
|
+
module CI
|
|
12
|
+
# A shared immutable plan; parallel_tests remains the only partitioner.
|
|
13
|
+
class Run
|
|
14
|
+
attr_reader :directory, :plan
|
|
15
|
+
|
|
16
|
+
def self.prepare(directory:, pattern: 'spec/**/*_spec.rb', shards: 4, history: nil, rspec_options: [])
|
|
17
|
+
plan = configuration(pattern, shards, rspec_options)
|
|
18
|
+
known = history_for(history, plan.fetch('sizes').keys)
|
|
19
|
+
plan['group_by'] = grouping(known.size, plan.fetch('sizes').size)
|
|
20
|
+
FileUtils.mkdir_p(directory)
|
|
21
|
+
File.write(File.join(directory, 'plan.json'), JSON.generate(plan))
|
|
22
|
+
RuntimeLog.write(File.join(directory, 'runtime.log'), known)
|
|
23
|
+
new(directory)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.configuration(pattern, shards, options)
|
|
27
|
+
count = positive_integer(shards)
|
|
28
|
+
raise ArgumentError, 'GitHub Actions allows at most 256 shards' if count > 256
|
|
29
|
+
unless options.is_a?(Array) && options.all?(String)
|
|
30
|
+
raise ArgumentError, 'RSpec options must be an array of strings'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
sizes = discover(pattern)
|
|
34
|
+
raise ArgumentError, "No spec files match #{pattern.inspect}" if sizes.empty?
|
|
35
|
+
|
|
36
|
+
{ 'pattern' => pattern, 'sizes' => sizes, 'shards' => [count, sizes.size].min, 'rspec_options' => options }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.grouping(known, total)
|
|
40
|
+
known.positive? && known * 2 >= total ? 'runtime' : 'filesize'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.positive_integer(value)
|
|
44
|
+
number = Integer(value.to_s, 10)
|
|
45
|
+
raise ArgumentError, 'Expected a positive integer' unless number.positive?
|
|
46
|
+
|
|
47
|
+
number
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.discover(pattern)
|
|
51
|
+
RuntimeLog.validate_path(pattern)
|
|
52
|
+
Dir.glob(pattern).select { |file| File.file?(file) }.to_h do |file|
|
|
53
|
+
[RuntimeLog.validate_path(file), File.size(file)]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.history_for(path, files)
|
|
58
|
+
return {} unless path && File.file?(path)
|
|
59
|
+
|
|
60
|
+
RuntimeLog.read(path).slice(*files)
|
|
61
|
+
rescue ArgumentError, SystemCallError => e
|
|
62
|
+
warn "Ignoring unusable timing history: #{e.message}"
|
|
63
|
+
{}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def initialize(directory)
|
|
67
|
+
@directory = File.expand_path(directory)
|
|
68
|
+
@plan = JSON.parse(File.read(File.join(@directory, 'plan.json')))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def matrix
|
|
72
|
+
(1..plan.fetch('shards')).map { |shard| { shard: shard } }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def fingerprint
|
|
76
|
+
Digest::SHA256.hexdigest("#{File.read(File.join(directory, 'plan.json'))}\0#{File.read(history_path)}")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def run(shard:, attempt:, directory:, env: {})
|
|
80
|
+
index = validate_shard(shard)
|
|
81
|
+
generation = self.class.positive_integer(attempt)
|
|
82
|
+
directory = File.expand_path(directory)
|
|
83
|
+
prepare_output(directory)
|
|
84
|
+
code = execute(command(index, File.join(directory, 'runtime.log')), env)
|
|
85
|
+
if code.zero?
|
|
86
|
+
File.write(File.join(directory, 'result.json'),
|
|
87
|
+
JSON.generate('plan' => fingerprint, 'shard' => index, 'attempt' => generation))
|
|
88
|
+
end
|
|
89
|
+
code
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def collect(directory:, output:)
|
|
93
|
+
paths = latest_results(directory)
|
|
94
|
+
combined = RuntimeLog.merge(paths, files: plan.fetch('sizes').keys)
|
|
95
|
+
raise ArgumentError, 'No test timings were recorded' if combined.empty?
|
|
96
|
+
|
|
97
|
+
FileUtils.mkdir_p(File.dirname(output))
|
|
98
|
+
RuntimeLog.write(output, combined)
|
|
99
|
+
combined
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
def validate_shard(shard)
|
|
105
|
+
index = self.class.positive_integer(shard)
|
|
106
|
+
raise ArgumentError, 'Shard is outside the prepared matrix' if index > plan.fetch('shards')
|
|
107
|
+
unless self.class.discover(plan.fetch('pattern')) == plan.fetch('sizes')
|
|
108
|
+
raise ArgumentError, 'Selected spec files or sizes changed after preparation'
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
index
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def prepare_output(directory)
|
|
115
|
+
FileUtils.mkdir_p(directory)
|
|
116
|
+
FileUtils.rm_f(File.join(directory, 'result.json'))
|
|
117
|
+
File.write(File.join(directory, 'runtime.log'), '')
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def execute(command, env)
|
|
121
|
+
pid = Process.spawn(env, *command)
|
|
122
|
+
_pid, status = Process.wait2(pid)
|
|
123
|
+
status.exitstatus || (128 + status.termsig)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def history_path
|
|
127
|
+
File.join(directory, 'runtime.log')
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def command(index, output)
|
|
131
|
+
options = [*plan.fetch('rspec_options'), '--format', 'progress',
|
|
132
|
+
'--format', 'ParallelTests::RSpec::RuntimeLogger', '--out', output]
|
|
133
|
+
[RbConfig.ruby, Gem.bin_path('parallel_tests', 'parallel_rspec'),
|
|
134
|
+
'-n', plan.fetch('shards').to_s, '--only-group', index.to_s,
|
|
135
|
+
'--group-by', plan.fetch('group_by'), '--runtime-log', history_path,
|
|
136
|
+
'--test-options', Shellwords.join(options), '--',
|
|
137
|
+
*plan.fetch('sizes').keys.map { |file| "./#{file}" }]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def latest_results(directory)
|
|
141
|
+
results = result_records(directory)
|
|
142
|
+
expected = (1..plan.fetch('shards')).to_a
|
|
143
|
+
unless results.map { |result| result.fetch('shard') }.uniq.sort == expected
|
|
144
|
+
raise ArgumentError, 'Incomplete or unexpected shard reports'
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
expected.map { |shard| latest_result(results.select { |result| result.fetch('shard') == shard }) }
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def result_records(directory)
|
|
151
|
+
Dir.glob(File.join(directory, '**/result.json')).filter_map do |path|
|
|
152
|
+
result = JSON.parse(File.read(path))
|
|
153
|
+
next unless result.fetch('plan') == fingerprint
|
|
154
|
+
|
|
155
|
+
result.merge('path' => File.join(File.dirname(path), 'runtime.log'))
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def latest_result(results)
|
|
160
|
+
results.each { |result| result['attempt'] = self.class.positive_integer(result.fetch('attempt')) }
|
|
161
|
+
latest = results.max_by { |result| result.fetch('attempt') }
|
|
162
|
+
if results.count { |result| result.fetch('attempt') == latest.fetch('attempt') } != 1
|
|
163
|
+
raise ArgumentError, 'Duplicate reports for the same shard and attempt'
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
latest.fetch('path')
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
5
|
+
module ParallelTests
|
|
6
|
+
module CI
|
|
7
|
+
# Reads the upstream file:seconds format without accepting ambiguous measurements.
|
|
8
|
+
module RuntimeLog
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def validate_path(path)
|
|
12
|
+
unless path.is_a?(String) && path.valid_encoding? && path.match?(/\A[^\\\r\n\0]+\z/) &&
|
|
13
|
+
!Pathname.new(path).absolute? && !path.split('/').include?('..')
|
|
14
|
+
raise ArgumentError, "Expected a relative repository path: #{path.inspect}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Pathname.new(path).cleanpath.to_s
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def read(path)
|
|
21
|
+
File.foreach(path).each_with_object({}) do |line, entries|
|
|
22
|
+
file, separator, seconds = line.chomp.rpartition(':')
|
|
23
|
+
raise ArgumentError, "Invalid runtime entry: #{line.inspect}" if separator.empty?
|
|
24
|
+
|
|
25
|
+
file = validate_path(file)
|
|
26
|
+
raise ArgumentError, "Duplicate runtime for #{file}" if entries.key?(file)
|
|
27
|
+
|
|
28
|
+
entries[file] = parse_duration(seconds, file)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def parse_duration(value, file)
|
|
33
|
+
duration = Float(value)
|
|
34
|
+
raise ArgumentError, "Invalid duration for #{file}" unless duration.finite? && !duration.negative?
|
|
35
|
+
|
|
36
|
+
duration
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def write(path, entries)
|
|
40
|
+
File.write(path, entries.sort.map { |file, seconds| "#{file}:#{seconds}\n" }.join)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def merge(paths, files:)
|
|
44
|
+
paths.each_with_object({}) do |path, combined|
|
|
45
|
+
read(path).each do |file, seconds|
|
|
46
|
+
raise ArgumentError, "Unexpected measured file: #{file}" unless files.include?(file)
|
|
47
|
+
raise ArgumentError, "Duplicate runtime for #{file}" if combined.key?(file)
|
|
48
|
+
|
|
49
|
+
combined[file] = seconds
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: parallel_tests-ci
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Daniel Doubrovkine
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-11-19 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: parallel_tests
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '5.9'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '5.9'
|
|
26
|
+
description: Prepare and reuse CI timing history while parallel_tests owns test collection
|
|
27
|
+
and sharding.
|
|
28
|
+
email:
|
|
29
|
+
- dblock@users.noreply.github.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- CHANGELOG.md
|
|
35
|
+
- LICENSE.txt
|
|
36
|
+
- README.md
|
|
37
|
+
- lib/parallel_tests/ci.rb
|
|
38
|
+
- lib/parallel_tests/ci/github.rb
|
|
39
|
+
- lib/parallel_tests/ci/run.rb
|
|
40
|
+
- lib/parallel_tests/ci/runtime_log.rb
|
|
41
|
+
- lib/parallel_tests/ci/version.rb
|
|
42
|
+
homepage: https://github.com/dblock/parallel_tests-ci
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata:
|
|
46
|
+
bug_tracker_uri: https://github.com/dblock/parallel_tests-ci/issues
|
|
47
|
+
changelog_uri: https://github.com/dblock/parallel_tests-ci/blob/master/CHANGELOG.md
|
|
48
|
+
source_code_uri: https://github.com/dblock/parallel_tests-ci
|
|
49
|
+
rubygems_mfa_required: 'true'
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '3.3'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubygems_version: 4.0.20
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: Shared GitHub Actions integration for parallel_tests timing history.
|
|
67
|
+
test_files: []
|