Skip to content

Commit 7049d7d

Browse files
authored
chore: test ruby 2.3 thru 3.4 [SC-35314] (#211)
* chore: test more rubies [SC-35314] * add local testing with `make lint test RUBY_VERSION=X.Y` * ruby 2.7 also gets the newer activesupport * use make in github action ci * stop testing ruby 2.1 and 2.2
1 parent ac5116b commit 7049d7d

File tree

6 files changed

+108
-13
lines changed

6 files changed

+108
-13
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,17 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
RUBY_VERSION: [2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 3.3, 3.4]
20+
RUBY_VERSION: [2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4]
21+
env:
22+
RUBY_VERSION: ${{ matrix.RUBY_VERSION }}
2123
steps:
2224
- name: Check out code
2325
uses: actions/checkout@v4
2426
with:
2527
persist-credentials: false
2628

27-
- name: Install Ruby
28-
uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0
29-
with:
30-
ruby-version: ${{ matrix.RUBY_VERSION }}
31-
bundler: 1.17.3
32-
33-
- name: Bundle install
34-
run: bundle install
35-
3629
- name: Rubocop
37-
run: bundle exec rake rubocop
30+
run: make lint
3831

3932
- name: Rspec
40-
run: bundle exec rspec
33+
run: make test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ spec/reports
1515
test/tmp
1616
test/version_tmp
1717
tmp
18+
/docker/ruby-*/

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG RUBY_VERSION=2.3.1
2+
FROM ruby:${RUBY_VERSION}
3+
4+
ARG BUNDLER_VERSION=1.17.3
5+
ENV BUNDLER_VERSION=${BUNDLER_VERSION}
6+
RUN if [ "${BUNDLER_VERSION}" != "" ] ; then \
7+
gem install bundler -v "${BUNDLER_VERSION}" ; \
8+
fi
9+
10+
WORKDIR /app
11+
COPY Gemfile /app/
12+
COPY aptible-api.gemspec /app/
13+
RUN mkdir -p /app/lib/aptible/api/
14+
COPY lib/aptible/api/version.rb /app/lib/aptible/api/
15+
16+
RUN bundle install
17+
18+
COPY . /app
19+
20+
CMD ["bash"]

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
source 'https://rubygems.org'
22

33
# ActiveSupport version depends on Ruby version for compatibility
4-
if RUBY_VERSION < '3.0'
4+
# ActiveSupport 4.x is incompatible with Ruby 2.7+ (BigDecimal.new removed)
5+
if RUBY_VERSION < '2.7'
56
gem 'activesupport', '~> 4.0'
67
else
78
gem 'activesupport', '>= 5.2'

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
export COMPOSE_IGNORE_ORPHANS ?= true
3+
export RUBY_VERSION ?= 2.3.1
4+
RUBY_VERSION_MAJOR = $(word 1,$(subst ., ,$(RUBY_VERSION)))
5+
export BUNDLER_VERSION ?=
6+
ifeq ($(BUNDLER_VERSION),)
7+
ifeq ($(RUBY_VERSION_MAJOR),2)
8+
export BUNDLER_VERSION = 1.17.3
9+
endif
10+
endif
11+
PROJECT_NAME = $(shell ls *.gemspec | sed 's/\.gemspec//')
12+
export COMPOSE_PROJECT_NAME ?= $(PROJECT_NAME)-$(subst .,_,$(RUBY_VERSION))
13+
14+
default: help
15+
16+
## Show this help message
17+
help:
18+
@echo "\n\033[1;34mAvailable targets:\033[0m\n"
19+
@awk 'BEGIN {FS = ":"; prev = ""} \
20+
/^## / {prev = substr($$0, 4); next} \
21+
/^[a-zA-Z_-]+:/ {if (prev != "") printf " \033[1;36m%-20s\033[0m %s\n", $$1, prev; prev = ""} \
22+
{prev = ""}' $(MAKEFILE_LIST) | sort
23+
@echo
24+
25+
BUILD_ARGS ?=
26+
## Build and pull docker compose images
27+
build: gemfile-lock
28+
docker compose build --pull $(BUILD_ARGS)
29+
30+
## Create a Gemfile.lock specific to the container (i.e., for the ruby version)
31+
gemfile-lock:
32+
mkdir -pv ./docker/ruby-$(RUBY_VERSION)/ && \
33+
echo '' > ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock
34+
35+
## Open shell in a docker container, supports CMD=
36+
bash: build
37+
$(MAKE) run CMD=bash
38+
39+
CMD ?= bash
40+
## Run command in a docker container, supports CMD=
41+
run:
42+
docker compose run --rm runner $(CMD)
43+
44+
## Run tests in a docker container, supports ARGS=
45+
test: build
46+
$(MAKE) test-direct ARGS="$(ARGS)"
47+
48+
## Run tests in a docker container without building, supports ARGS=
49+
test-direct:
50+
$(MAKE) run CMD="bundle exec rspec $(ARGS)"
51+
52+
## Run rubocop in a docker container, supports ARGS=
53+
lint: build
54+
$(MAKE) lint-direct ARGS="$(ARGS)"
55+
56+
## Run rubocop in a docker container without building, supports ARGS=
57+
lint-direct:
58+
$(MAKE) run CMD="bundle exec rake rubocop $(ARGS)"
59+
60+
## Clean up docker compose resources
61+
clean: clean-gemfile-lock
62+
docker compose down --remove-orphans --volumes
63+
64+
## Clean up the container specific Gemfile.lock
65+
clean-gemfile-lock:
66+
rm -v ./docker/ruby-$(RUBY_VERSION)/Gemfile.lock ||:
67+
68+
.PHONY: build bash test

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
runner:
3+
build:
4+
context: .
5+
args:
6+
RUBY_VERSION: ${RUBY_VERSION:-2.3.1}
7+
BUNDLER_VERSION: ${BUNDLER_VERSION:-}
8+
volumes:
9+
- type: bind
10+
source: .
11+
target: /app
12+
- ./docker/ruby-${RUBY_VERSION}/Gemfile.lock:/app/Gemfile.lock

0 commit comments

Comments
 (0)