Skip to content

Commit

Permalink
Refactor + Test + Support preview releases (#31)
Browse files Browse the repository at this point in the history
* Refactor + Test + Support preview releases

I've resisted really touching the compilation script because it had no tests. This was tolerable when we ran scripts locally and adjustments could be made on the fly. Now that we're automating them, I wanted to have more confidence in the script. To do that I iteratively extracted, tested, and then refactored code.

In the process I got rid of most branching logic for features we don't support on GitHub actions today. If we need them in the future we have a git history.

The unit tests are fast, but not terribly comprehensive. We could continue down this path of testing and refactoring if we choose, but this was a good enough stoping point for my needs.

The only new behavior added is fixing these bugs that are all centered around preview/rc releases:

- #28
- #29
- #30

While I'm at it I also added a linter (standard).

* Update lib/changelog.rb

Co-authored-by: Josh W Lewis <[email protected]>

---------

Co-authored-by: Josh W Lewis <[email protected]>
  • Loading branch information
schneems and joshwlewis authored Sep 22, 2023
1 parent cf7eb1a commit 34e39c2
Show file tree
Hide file tree
Showing 21 changed files with 764 additions and 352 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
ruby-version: '3.1'
- name: Install dependencies
run: bundle install
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
- name: Generate Ruby Dockerfile
Expand All @@ -48,9 +50,6 @@ jobs:
run: aws s3 sync ./builds "s3://${S3_BUCKET}"
- name: Output Rubygems version
run: bundle exec rake "rubygems_version[${{inputs.ruby_version}},$STACK]"
- name: Output CHANGELOG
if: (!inputs.dry_run)
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"

build-and-upload-heroku-22:
if: (!startsWith(inputs.ruby_version, '3.0')) # https://bugs.ruby-lang.org/issues/18658
Expand All @@ -66,6 +65,8 @@ jobs:
ruby-version: '3.1'
- name: Install dependencies
run: bundle install
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
- name: Generate Ruby Dockerfile
Expand All @@ -77,6 +78,3 @@ jobs:
run: aws s3 sync ./builds "s3://${S3_BUCKET}"
- name: Output Rubygems version
run: bundle exec rake "rubygems_version[${{inputs.ruby_version}},$STACK]"
- name: Output CHANGELOG
if: (!inputs.dry_run)
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
- push
- pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true
- name: Linting
run: bundle exec standardrb

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true
- name: test
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]"


5 changes: 5 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ruby_version: 3.1
ignore:
- 'builds/**/*'
- 'rubies/**/*'
- 'test/fixtures/**/*'
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ gem "aws-sdk"
gem "heroku_hatchet"
gem "webrick"
gem "nokogiri"
gem "rspec"
gem "standard"
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.665.0)
aws-sdk (3.0.1)
Expand Down Expand Up @@ -915,6 +916,7 @@ GEM
aws-sigv2 (1.0.1)
aws-sigv4 (1.5.2)
aws-eventstream (~> 1, >= 1.0.2)
diff-lcs (1.5.0)
erubis (2.7.0)
excon (0.85.0)
heroics (0.1.2)
Expand All @@ -936,16 +938,54 @@ GEM
nokogiri (1.14.4)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
platform-api (3.3.0)
heroics (~> 0.1.1)
moneta (~> 1.0.0)
rate_throttle_client (~> 0.1.0)
racc (1.6.2)
rainbow (3.1.1)
rake (13.0.1)
rate_throttle_client (0.1.2)
regexp_parser (2.8.1)
rexml (3.2.5)
rrrretry (1.0.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.20.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
rubocop-performance (1.11.5)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
standard (1.3.0)
rubocop (= 1.20.0)
rubocop-performance (= 1.11.5)
thor (1.1.0)
threaded (0.0.4)
unicode-display_width (2.3.0)
webrick (1.7.0)

PLATFORMS
Expand All @@ -956,6 +996,8 @@ DEPENDENCIES
heroku_hatchet
nokogiri
rake
rspec
standard
webrick

BUNDLED WITH
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,19 @@ To configure the build, we use environment variables. All of them are listed bel
* `GIT_URL` - If this option is used, it will override fetching a source tarball from <http://ftp.ruby-lang.org/pub/ruby> with a git repo. This allows building ruby forks or trunk. This option also supports passing a treeish git object in the URL with the `#` character. For instance, `git://github.com/hone/ruby.git#ruby_1_8_7`.
* `S3_BUCKET_NAME` - This option is the S3 bucket name containing of dependencies for building ruby. If this option is not specified, hammer-ruby defaults to "heroku-buildpack-ruby". The dependencies needed are `libyaml-0.1.4.tgz` and `libffi-3.0.10.tgz`.
* `JOBS` - the number of jobs to run in parallel when running make: `make -j<jobs>`. By default this is 2.

## Development

Run unit tests

```
$ bundle exec rspec
```

Build a binary using current code and run it

```
$ bundle exec rake "generate_image[heroku-22]" && bash rubies/heroku-22/ruby-3.1.2.sh
$ 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.2.tgz -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v"
```

Loading

0 comments on commit 34e39c2

Please sign in to comment.