Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Nov 18, 2024
1 parent 256c969 commit f206f06
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 55 deletions.
103 changes: 49 additions & 54 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,80 @@
---
name: Test

on:
push:

'on':
- push
jobs:
generate-matrices:
comput_matrices:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
engine:
- { name: "ruby", version: "3.3", alias: "ruby-33" }
- { name: "ruby", version: "3.2", alias: "ruby-32" }
- { name: "ruby", version: "3.1", alias: "ruby-31" }
- name: ruby
version: '3.3'
alias: ruby-33
- name: ruby
version: '3.2'
alias: ruby-32
- name: ruby
version: '3.1'
alias: ruby-31
container:
image: ghcr.io/datadog/images-rb/engines/${{ matrix.engine.name }}:${{ matrix.engine.version }}
outputs:
ruby-33-matrix: ${{ steps.set-matrix.outputs.ruby-33 }}
ruby-32-matrix: ${{ steps.set-matrix.outputs.ruby-32 }}
ruby-31-matrix: ${{ steps.set-matrix.outputs.ruby-31 }}
ruby-33-matrix: "${{ steps.set-matrix.outputs.ruby-33 }}"
ruby-32-matrix: "${{ steps.set-matrix.outputs.ruby-32 }}"
ruby-31-matrix: "${{ steps.set-matrix.outputs.ruby-31 }}"
steps:
- uses: actions/checkout@v4
- run: apt update && apt install jq -y
- name: Bundle install
run: bundle install
- id: set-matrix
run: |
matrix_json=$(bundle exec rake github:generate_matrix)
# Debug output
echo "Generated JSON:"
echo "$matrix_json"
# Set the output
echo "${{ matrix.engine.alias }}=$(echo "$matrix_json" | jq -c .)" >> $GITHUB_OUTPUT
test-ruby-33:
name: Test Ruby 3.3
needs: generate-matrices
- uses: actions/checkout@v4
- run: apt update && apt install jq -y
- run: bundle install
- id: set-matrix
run: |
matrix_json=$(bundle exec rake github:generate_matrix)
# Debug output
echo "Generated JSON:"
echo "$matrix_json"
# Set the output
echo "${{ matrix.engine.alias }}=$(echo "$matrix_json" | jq -c .)" >> $GITHUB_OUTPUT
test-ruby-31:
name: Test on ruby 3.1
needs: comput_matrices
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrices.outputs.ruby-33-matrix) }}
include: "${{ needs.comput_matrices.outputs.ruby-31-matrix }}"
container:
image: ghcr.io/datadog/images-rb/engines/ruby:3.3
image: ghcr.io/datadog/images-rb/engines/ruby:3.1
steps:
- uses: actions/checkout@v4
- name: Bundle install
run: bundle install
- name: Run tests
run: bundle exec rake test:${{ matrix.task }}

- uses: actions/checkout@v4
- run: bundle install
- run: bundle exec rake test:${{ matrix.task }}
test-ruby-32:
name: Test Ruby 3.2
needs: generate-matrices
name: Test on ruby 3.2
needs: comput_matrices
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrices.outputs.ruby-32-matrix) }}
include: "${{ needs.comput_matrices.outputs.ruby-32-matrix }}"
container:
image: ghcr.io/datadog/images-rb/engines/ruby:3.2
steps:
- uses: actions/checkout@v4
- name: Bundle install
run: bundle install
- name: Run tests
run: bundle exec rake test:${{ matrix.task }}

test-ruby-31:
name: Test Ruby 3.1
needs: generate-matrices
- uses: actions/checkout@v4
- run: bundle install
- run: bundle exec rake test:${{ matrix.task }}
test-ruby-33:
name: Test on ruby 3.3
needs: comput_matrices
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrices.outputs.ruby-31-matrix) }}
include: "${{ needs.comput_matrices.outputs.ruby-33-matrix }}"
container:
image: ghcr.io/datadog/images-rb/engines/ruby:3.1
image: ghcr.io/datadog/images-rb/engines/ruby:3.3
steps:
- uses: actions/checkout@v4
- name: Bundle install
run: bundle install
- name: Run tests
run: bundle exec rake test:${{ matrix.task }}
- uses: actions/checkout@v4
- run: bundle install
- run: bundle exec rake test:${{ matrix.task }}
79 changes: 78 additions & 1 deletion tasks/github.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,88 @@
require 'json'
require "psych"
# rubocop:disable Metrics/BlockLength
namespace :github do
namespace :actions do
task :generate_test do
file_name = 'test.yml'


test_jobs = [
"ruby:3.1",
"ruby:3.2",
"ruby:3.3",
].map do |runtime|
engine, version = runtime.split(':')
runtime_alias = "#{engine}-#{version.gsub('.', '')}"

{
"test-#{runtime_alias}" => {
"name" => "Test on #{engine} #{version}",
"needs" => "comput_matrices",
"runs-on" => "ubuntu-22.04",
"strategy" => {
"fail-fast" => false,
"matrix" => {
"include" => "${{ needs.comput_matrices.outputs.#{runtime_alias}-matrix }}"
}
},
"container" => { "image" => "ghcr.io/datadog/images-rb/engines/#{engine}:#{version}" },
"steps" => [
{ "uses" => "actions/checkout@v4" },
{ "run" => "bundle install" },
{ "run" => "bundle exec rake test:${{ matrix.task }}" }
]
}
}
end

comput_matrices = {
"runs-on" => "ubuntu-22.04",
"strategy" => {
"fail-fast" => false,
"matrix" => {
"engine" => [
{ "name" => "ruby", "version" => "3.3", "alias" => "ruby-33" },
{ "name" => "ruby", "version" => "3.2", "alias" => "ruby-32" },
{ "name" => "ruby", "version" => "3.1", "alias" => "ruby-31" },
]
}
},
"container" =>{
"image" => "ghcr.io/datadog/images-rb/engines/${{ matrix.engine.name }}:${{ matrix.engine.version }}"
},
"outputs" => {
"ruby-33-matrix" => "${{ steps.set-matrix.outputs.ruby-33 }}",
"ruby-32-matrix" => "${{ steps.set-matrix.outputs.ruby-32 }}",
"ruby-31-matrix" => "${{ steps.set-matrix.outputs.ruby-31 }}",
},
"steps" => [
{ "uses" => "actions/checkout@v4" },
{ "run" => "apt update && apt install jq -y" },
{ "run" => "bundle install" },
{
"id" => "set-matrix",
"run" => <<~BASH
matrix_json=$(bundle exec rake github:generate_matrix)
# Debug output
echo "Generated JSON:"
echo "$matrix_json"
# Set the output
echo "${{ matrix.engine.alias }}=$(echo "$matrix_json" | jq -c .)" >> $GITHUB_OUTPUT
BASH
},
]
}

base = {
"name" => 'Test',
"on" => ['push'],
"jobs" => {
"comput_matrices" => comput_matrices,
**test_jobs.reduce(&:merge)
}
}
File.binwrite(".github/workflows/test.yml", Psych.dump(base, line_width: 120))

end
end

Expand Down

0 comments on commit f206f06

Please sign in to comment.