diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93622da..1452820 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,28 +32,27 @@ jobs: run: bundle exec rspec spec integration_test: - runs-on: pub-hk-ubuntu-22.04-xlarge - env: - STACK: "heroku-22" - TEST_VERSION: "3.1.4" - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 - with: - ruby-version: '3.1' - - name: Install dependencies - run: bundle install - - name: Output CHANGELOG - run: bundle exec rake "changelog[$TEST_VERSION]" - - name: Build Docker image - run: bundle exec rake "generate_image[$STACK]" - - name: Generate Ruby Dockerfile - run: bundle exec rake "new[$TEST_VERSION,$STACK]" - - name: Build and package Ruby runtime - run: bash "rubies/$STACK/ruby-$TEST_VERSION.sh" - - name: Verify ruby executable and output rubygems version - run: bundle exec rake "rubygems_version[$TEST_VERSION,$STACK]" - - + runs-on: pub-hk-ubuntu-22.04-xlarge + strategy: + matrix: + stack: ["heroku-20", "heroku-22"] + version: ["3.1.4"] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 + with: + ruby-version: '3.1' + - name: Install dependencies + run: bundle install + - name: Output CHANGELOG + run: bundle exec rake "changelog[${{matrix.version}}]" + - name: Build Docker image + run: bundle exec rake "generate_image[${{matrix.stack}}]" + - name: Generate Ruby Dockerfile + run: bundle exec rake "new[${{matrix.version}},${{matrix.stack}}]" + - name: Build and package Ruby runtime + run: bash "rubies/${{matrix.stack}}/ruby-${{matrix.version}}.sh" + - name: Verify ruby executable and output rubygems version + run: bundle exec rake "rubygems_version[${{matrix.version}},${{matrix.stack}}]" diff --git a/Rakefile b/Rakefile index 1fbb523..8718663 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) require "ruby_version" require "changelog" +require "docker_command" require "fileutils" @@ -35,11 +36,10 @@ end desc "Output the Rubygems version for a given binary" task :rubygems_version, [:version, :stack] do |t, args| - stack = args[:stack] - ruby_version = args[:version] - - # Extract the binary in a docker image and run `bin/gem -v` to output it's Rubygems version - command = "docker run -v $(pwd)/builds/#{stack}:/tmp/output hone/ruby-builder:#{stack} bash -c \"mkdir /tmp/unzipped && tar xzf /tmp/output/ruby-#{ruby_version}.tgz -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v\"" + command = DockerCommand.gem_version_from_tar( + stack: args[:stack], + ruby_version: RubyVersion.new(args[:version]) + ) puts "Running: #{command}" pipe(command) end diff --git a/dockerfiles/Dockerfile.heroku-20 b/dockerfiles/Dockerfile.heroku-20 index fc15af7..eb6d251 100644 --- a/dockerfiles/Dockerfile.heroku-20 +++ b/dockerfiles/Dockerfile.heroku-20 @@ -10,4 +10,5 @@ ENV PATH="/root/.cargo/bin:${PATH}" # output dir is mounted ADD build.rb /tmp/build.rb +COPY lib/ /tmp/lib/ CMD ["ruby", "/tmp/build.rb", "/tmp/workspace", "/tmp/output", "/tmp/cache"] diff --git a/lib/docker_command.rb b/lib/docker_command.rb new file mode 100644 index 0000000..95159ae --- /dev/null +++ b/lib/docker_command.rb @@ -0,0 +1,5 @@ +module DockerCommand + def self.gem_version_from_tar(ruby_version:, stack:) + "docker run -v $(pwd)/builds/#{stack}:/tmp/output hone/ruby-builder:#{stack} bash -c \"mkdir /tmp/unzipped && tar xzf /tmp/output/#{ruby_version.tar_file_name_output} -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v\"" + end +end diff --git a/spec/unit/changelog_spec.rb b/spec/unit/changelog_spec.rb index de8bc5a..588b4a4 100644 --- a/spec/unit/changelog_spec.rb +++ b/spec/unit/changelog_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" require "changelog" -describe RubyVersion do +describe "Changelog output" do it "prints changelog info for regular releases" do io = StringIO.new Changelog.new( diff --git a/spec/unit/docker_command_spec.rb b/spec/unit/docker_command_spec.rb new file mode 100644 index 0000000..aac2818 --- /dev/null +++ b/spec/unit/docker_command_spec.rb @@ -0,0 +1,16 @@ +require "spec_helper" +require "docker_command" + +describe DockerCommand do + it "Generates docker command for outputting rubygems versions" do + actual = DockerCommand.gem_version_from_tar(ruby_version: RubyVersion.new("3.1.4"), stack: "heroku-22") + expected = %{docker run -v $(pwd)/builds/heroku-22:/tmp/output hone/ruby-builder:heroku-22 bash -c "mkdir /tmp/unzipped && tar xzf /tmp/output/ruby-3.1.4.tgz -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v"} + expect(actual).to eq(expected) + end + + it "works with preview releases" do + actual = DockerCommand.gem_version_from_tar(ruby_version: RubyVersion.new("3.3.0-preview2"), stack: "heroku-22") + expected = %{docker run -v $(pwd)/builds/heroku-22:/tmp/output hone/ruby-builder:heroku-22 bash -c "mkdir /tmp/unzipped && tar xzf /tmp/output/ruby-3.3.0.tgz -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v"} + expect(actual).to eq(expected) + end +end