Skip to content

Commit ea14aee

Browse files
committed
Github actions scaffold
1 parent 646d17a commit ea14aee

File tree

3 files changed

+231
-0
lines changed

3 files changed

+231
-0
lines changed

.github/workflows/test.yml

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Please do NOT manually edit this file.
2+
# This file is generated by 'bundle exec rake github:actions:test_template'
3+
---
4+
name: Test
5+
'on':
6+
- push
7+
jobs:
8+
compute_tasks:
9+
runs-on: ubuntu-22.04
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
engine:
14+
- name: ruby
15+
version: '3.3'
16+
alias: ruby-33
17+
- name: ruby
18+
version: '3.2'
19+
alias: ruby-32
20+
- name: ruby
21+
version: '3.1'
22+
alias: ruby-31
23+
- name: ruby
24+
version: '3.0'
25+
alias: ruby-30
26+
container:
27+
image: ghcr.io/datadog/images-rb/engines/${{ matrix.engine.name }}:${{ matrix.engine.version }}
28+
outputs:
29+
ruby-33-matrix: "${{ steps.set-matrix.outputs.ruby-33 }}"
30+
ruby-32-matrix: "${{ steps.set-matrix.outputs.ruby-32 }}"
31+
ruby-31-matrix: "${{ steps.set-matrix.outputs.ruby-31 }}"
32+
ruby-30-matrix: "${{ steps.set-matrix.outputs.ruby-30 }}"
33+
steps:
34+
- uses: actions/checkout@v4
35+
- run: apt update && apt install jq -y
36+
- run: bundle install
37+
- id: set-matrix
38+
run: |
39+
matrix_json=$(bundle exec rake github:generate_matrix)
40+
# Debug output
41+
echo "Generated JSON:"
42+
echo "$matrix_json"
43+
# Set the output
44+
echo "${{ matrix.engine.alias }}=$(echo "$matrix_json" | jq -c .)" >> $GITHUB_OUTPUT
45+
test-ruby-33:
46+
name: Test on ruby 3.3
47+
needs:
48+
- compute_tasks
49+
runs-on: ubuntu-22.04
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
include: "${{ fromJson(needs.compute_tasks.outputs.ruby-33-matrix) }}"
54+
container:
55+
image: ghcr.io/datadog/images-rb/engines/ruby:3.3
56+
steps:
57+
- uses: actions/checkout@v4
58+
- run: bundle install
59+
- run: bundle exec rake test:${{ matrix.task }}
60+
test-ruby-32:
61+
name: Test on ruby 3.2
62+
needs:
63+
- compute_tasks
64+
runs-on: ubuntu-22.04
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
include: "${{ fromJson(needs.compute_tasks.outputs.ruby-32-matrix) }}"
69+
container:
70+
image: ghcr.io/datadog/images-rb/engines/ruby:3.2
71+
steps:
72+
- uses: actions/checkout@v4
73+
- run: bundle install
74+
- run: bundle exec rake test:${{ matrix.task }}
75+
test-ruby-31:
76+
name: Test on ruby 3.1
77+
needs:
78+
- compute_tasks
79+
runs-on: ubuntu-22.04
80+
strategy:
81+
fail-fast: false
82+
matrix:
83+
include: "${{ fromJson(needs.compute_tasks.outputs.ruby-31-matrix) }}"
84+
container:
85+
image: ghcr.io/datadog/images-rb/engines/ruby:3.1
86+
steps:
87+
- uses: actions/checkout@v4
88+
- run: bundle install
89+
- run: bundle exec rake test:${{ matrix.task }}
90+
test-ruby-30:
91+
name: Test on ruby 3.0
92+
needs:
93+
- compute_tasks
94+
runs-on: ubuntu-22.04
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
include: "${{ fromJson(needs.compute_tasks.outputs.ruby-30-matrix) }}"
99+
container:
100+
image: ghcr.io/datadog/images-rb/engines/ruby:3.0
101+
steps:
102+
- uses: actions/checkout@v4
103+
- run: bundle install
104+
- run: bundle exec rake test:${{ matrix.task }}

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"files.associations": {
33
"*.gemfile": "ruby",
4+
"Matrixfile": "ruby",
45
"Dockerfile*": "dockerfile"
56
}
67
}

tasks/github.rake

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
require 'json'
2+
require "psych"
3+
# rubocop:disable Metrics/BlockLength
4+
namespace :github do
5+
namespace :actions do
6+
task :test_template do |t|
7+
runtimes = [
8+
"ruby:3.3",
9+
"ruby:3.2",
10+
"ruby:3.1",
11+
"ruby:3.0",
12+
].map do |runtime|
13+
engine, version = runtime.split(':')
14+
runtime_alias = "#{engine}-#{version.gsub('.', '')}"
15+
16+
OpenStruct.new(
17+
"engine" => engine,
18+
"version" => version,
19+
"alias" => runtime_alias,
20+
"image" => "ghcr.io/datadog/images-rb/engines/#{engine}:#{version}"
21+
)
22+
end
23+
24+
test_jobs = runtimes.map do |runtime|
25+
{
26+
"test-#{runtime.alias}" => {
27+
"name" => "Test on #{runtime.engine} #{runtime.version}",
28+
"needs" => ["compute_tasks"],
29+
"runs-on" => "ubuntu-22.04",
30+
"strategy" => {
31+
"fail-fast" => false,
32+
"matrix" => {
33+
"include" => "${{ fromJson(needs.compute_tasks.outputs.#{runtime.alias}-matrix) }}"
34+
}
35+
},
36+
"container" => { "image" => runtime.image },
37+
"steps" => [
38+
{ "uses" => "actions/checkout@v4" },
39+
{ "run" => "bundle install" },
40+
{ "run" => "bundle exec rake test:${{ matrix.task }}" }
41+
]
42+
}
43+
}
44+
end
45+
46+
compute_tasks = {
47+
"runs-on" => "ubuntu-22.04",
48+
"strategy" => {
49+
"fail-fast" => false,
50+
"matrix" => {
51+
"engine" => runtimes.map do |runtime|
52+
{ "name" => runtime.engine, "version" => runtime.version, "alias" => runtime.alias }
53+
end
54+
}
55+
},
56+
"container" =>{
57+
"image" => "ghcr.io/datadog/images-rb/engines/${{ matrix.engine.name }}:${{ matrix.engine.version }}"
58+
},
59+
"outputs" => runtimes.each_with_object({}) do |runtime, hash|
60+
hash["#{runtime.alias}-matrix"] = "${{ steps.set-matrix.outputs.#{runtime.alias} }}"
61+
end,
62+
"steps" => [
63+
{ "uses" => "actions/checkout@v4" },
64+
{ "run" => "apt update && apt install jq -y" },
65+
{ "run" => "bundle install" },
66+
{
67+
"id" => "set-matrix",
68+
"run" => <<~BASH
69+
matrix_json=$(bundle exec rake github:generate_matrix)
70+
# Debug output
71+
echo "Generated JSON:"
72+
echo "$matrix_json"
73+
# Set the output
74+
echo "${{ matrix.engine.alias }}=$(echo "$matrix_json" | jq -c .)" >> $GITHUB_OUTPUT
75+
BASH
76+
},
77+
]
78+
}
79+
80+
base = {
81+
"name" => 'Test',
82+
"on" => ['push'],
83+
"jobs" => {
84+
"compute_tasks" => compute_tasks,
85+
**test_jobs.reduce(&:merge)
86+
}
87+
}
88+
89+
string = +""
90+
string << <<~EOS
91+
# Please do NOT manually edit this file.
92+
# This file is generated by 'bundle exec rake #{t.name}'
93+
EOS
94+
string << Psych.dump(base, line_width: 120)
95+
96+
File.binwrite(".github/workflows/test.yml", string)
97+
end
98+
end
99+
100+
task :generate_matrix do
101+
matrix = eval(File.read('Matrixfile')).freeze # rubocop:disable Security/Eval
102+
103+
matrix = matrix.slice("stripe")
104+
105+
ruby_version = RUBY_VERSION[0..2]
106+
major, minor, = Gem::Version.new(RUBY_ENGINE_VERSION).segments
107+
ruby_runtime = "#{RUBY_ENGINE}-#{major}.#{minor}"
108+
array = []
109+
matrix.each do |key, spec_metadata|
110+
matched = spec_metadata.any? do |appraisal_group, rubies|
111+
if RUBY_PLATFORM == 'java'
112+
rubies.include?("✅ #{ruby_version}") && rubies.include?('✅ jruby')
113+
else
114+
rubies.include?("✅ #{ruby_version}")
115+
end
116+
end
117+
118+
if matched
119+
array << { task: key }
120+
end
121+
end
122+
123+
puts JSON.pretty_generate(array)
124+
end
125+
end
126+
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)