Skip to content

Commit

Permalink
Setup next_rails to dual-boot Rails
Browse files Browse the repository at this point in the history
With a workflow in GitHub Actions to detect potential issues with the
next Rails version. It's not possible to use CircleCI since we can't
filter PRs based on their branch name.

The module RailsVersion is to help with migrating code to a newer Rails
version.
  • Loading branch information
Dany Marcoux committed Apr 20, 2021
1 parent b38d311 commit 314cfc7
Show file tree
Hide file tree
Showing 8 changed files with 644 additions and 4 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/next_rails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Continuous integration for next Rails version

# Run this workflow on the branch master and on PRs with the prefix next_rails- in their branch name
on:
push:
branches:
- master
- 'next_rails-*'
pull_request:
branches:
- 'next_rails-*'

jobs:
next_rails:
runs-on: ubuntu-20.04 # This is required, but we're running all steps in the container defined below
container:
image: registry.opensuse.org/obs/server/unstable/container/ci/containers/openbuildservice/frontend-base:latest
env:
NOKOGIRI_USE_SYSTEM_LIBRARIES: 1
options: --user frontend
services:
database:
image: registry.opensuse.org/obs/server/unstable/container/ci/containers/openbuildservice/mariadb:latest
# TODO: How to change the command of a service container?
# command: |
# /bin/bash -c 'echo -e "[mysqld]\ndatadir = /dev/shm" > /etc/my.cnf.d/obs.cnf && cp -a /var/lib/mysql/* /dev/shm && /usr/lib/mysql/mysql-systemd-helper start'
options: --name db
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
uses: ruby/setup-ruby@v1
- name: Install dependencies from src/api/Gemfile.next
run: cd ./src/api && && next bundle install --jobs=4 --retry=3
- name: Init submodule
run: git submodule update --init --recursive --remote
- name: Wait for DB
run: mysqladmin ping -h db
- name: Create database with next Rails version
run: cd src/api; next bundle exec rake db:setup RAILS_ENV=test
- name: Run specs
run: cd src/api && next bundle exec rspec --format progress --format RspecJunitFormatter -o /home/frontend/rspec/rspec.db.xml
- name: Run minitest test suite
run: cd src/api && next bundle exec rake test:api:group1 test:api:group2
3 changes: 3 additions & 0 deletions dist/obs-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ rm -rf %{buildroot}%{__obs_api_prefix}/spec
# only config for CI
rm %{buildroot}%{__obs_api_prefix}/config/brakeman.ignore

# Remove Gemfile.next and Gemfile.next.lock since they are only for testing the next Rails version in development and test environments
rm %{buildroot}%{__obs_api_prefix}/Gemfile.next %{buildroot}%{__obs_api_prefix}/Gemfile.next.lock

# fail when Makefiles created a directory
if ! test -L %{buildroot}/usr/lib/obs/server/build; then
echo "/usr/lib/obs/server/build is not a symlink!"
Expand Down
16 changes: 14 additions & 2 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# next? was generated with `next --init`
# src/api/Gemfile.next.lock was generated with `next bundle install`
def next?
File.basename(__FILE__) == 'Gemfile.next'
end

# Edit this Gemfile to bundle your application's dependencies.
source 'https://rubygems.org'

# We have a version constraint to tackle Rails updates whenever we have time
gem 'rails', '~> 6.0'
# Start the Rails application using src/api/Gemfile.next with `next rails s`
if next?
gem 'rails', '~> 6.1'
else
gem 'rails', '~> 6.0'
end

# as our database
gem 'mysql2'
Expand Down Expand Up @@ -173,6 +183,8 @@ end
group :development do
# add a comment summarizing the current schema
gem 'annotate'
# toolkit to upgrade your Rails application
gem 'next_rails'
end

# Gems used only for assets and not required in production environments by default.
Expand Down
4 changes: 4 additions & 0 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ GEM
codecov (0.5.1)
simplecov (>= 0.15, < 0.22)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.1.8)
coveralls (0.8.23)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -244,6 +245,8 @@ GEM
ruby-progressbar
mocha (1.12.0)
mysql2 (0.5.3)
next_rails (1.0.4)
colorize (>= 0.8.1)
nio4r (2.5.7)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
Expand Down Expand Up @@ -493,6 +496,7 @@ DEPENDENCIES
minitest-reporters
mocha
mysql2
next_rails
nokogiri
pry
pry-byebug
Expand Down
1 change: 1 addition & 0 deletions src/api/Gemfile.next

0 comments on commit 314cfc7

Please sign in to comment.