Skip to content

Commit b31dcb5

Browse files
committed
build: Improve dev setup
1 parent 74790fc commit b31dcb5

File tree

16 files changed

+114
-102
lines changed

16 files changed

+114
-102
lines changed

.github/workflows/linters.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,35 @@
22
name: Linters
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
6+
branches: [main]
7+
push:
8+
branches: [main]
99

1010
jobs:
1111
reviewdog:
12-
name: reviewdog
12+
name: Reviewdog
1313
runs-on: ubuntu-latest
1414

15-
strategy:
16-
matrix:
17-
ruby: ['3.0']
18-
1915
env:
20-
RUBY_VERSION: ${{ matrix.ruby }}
16+
RAILS_VERSION: 7.0
2117

2218
steps:
23-
- name: Check out code
19+
- name: Checkout repository
2420
uses: actions/checkout@v4
2521

2622
- name: Set up Ruby
2723
uses: ruby/setup-ruby@v1
2824
with:
29-
ruby-version: ${{ matrix.ruby }}
25+
ruby-version: 3.0
3026
bundler-cache: true
3127

32-
- uses: reviewdog/action-setup@v1
28+
- name: Set up Reviewdog
29+
uses: reviewdog/action-setup@v1
3330
with:
3431
reviewdog_version: latest
3532

36-
- name: Run reviewdog
33+
- name: Run Reviewdog
3734
env:
3835
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3936
run: |

.github/workflows/specs_rails61.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
---
2-
name: Specs Rails 6.1
2+
name: Specs Rails 6.1 with ActiveAdmin 2.9
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
9-
branches:
10-
- main
6+
branches: [main]
7+
push:
8+
branches: [main]
119

1210
jobs:
13-
tests:
11+
test:
1412
runs-on: ubuntu-latest
1513

1614
strategy:
1715
matrix:
18-
ruby: ['3.0', '3.1']
16+
ruby: ['3.0']
1917

2018
env:
21-
RAILS_VERSION: 6.1.0
19+
RAILS_VERSION: 6.0
20+
ACTIVEADMIN_VERSION: 2.9.0
2221

2322
steps:
2423
- name: Checkout repository
@@ -30,6 +29,9 @@ jobs:
3029
ruby-version: ${{ matrix.ruby }}
3130
bundler-cache: true
3231

32+
- name: Database setup
33+
run: bin/rails db:create db:migrate db:test:prepare
34+
3335
- name: Run tests
3436
run: bundle exec rspec --profile
3537

.github/workflows/specs_rails70.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
name: Specs Rails 7.0
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
9-
branches:
10-
- main
6+
branches: [main]
7+
push:
8+
branches: [main]
119

1210
jobs:
13-
tests:
11+
test:
1412
runs-on: ubuntu-latest
1513

1614
strategy:
1715
matrix:
18-
ruby: ['3.1']
16+
ruby: ['3.0', '3.2']
1917

2018
env:
21-
RAILS_VERSION: 7.0.0
19+
RAILS_VERSION: 7.0
2220

2321
steps:
2422
- name: Checkout repository
@@ -30,6 +28,9 @@ jobs:
3028
ruby-version: ${{ matrix.ruby }}
3129
bundler-cache: true
3230

31+
- name: Database setup
32+
run: bin/rails db:create db:migrate db:test:prepare
33+
3334
- name: Run tests
3435
run: bundle exec rspec --profile
3536

.github/workflows/specs_rails71.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
name: Specs Rails 7.1
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
9-
branches:
10-
- main
6+
branches: [main]
7+
push:
8+
branches: [main]
119

1210
jobs:
13-
tests:
11+
test:
1412
runs-on: ubuntu-latest
1513

1614
strategy:
1715
matrix:
18-
ruby: ['3.2']
16+
ruby: ['3.2', '3.4']
1917

2018
env:
21-
RAILS_VERSION: 7.1.0
19+
RAILS_VERSION: 7.1
2220

2321
steps:
2422
- name: Checkout repository
@@ -30,6 +28,9 @@ jobs:
3028
ruby-version: ${{ matrix.ruby }}
3129
bundler-cache: true
3230

31+
- name: Database setup
32+
run: bin/rails db:create db:migrate db:test:prepare
33+
3334
- name: Run tests
3435
run: bundle exec rspec --profile
3536

.github/workflows/specs_rails72.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
name: Specs Rails 7.2
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
9-
branches:
10-
- main
6+
branches: [main]
7+
push:
8+
branches: [main]
119

1210
jobs:
13-
tests:
11+
test:
1412
runs-on: ubuntu-latest
1513

1614
strategy:
1715
matrix:
1816
ruby: ['3.2', '3.4']
1917

2018
env:
21-
RAILS_VERSION: 7.2.0
19+
RAILS_VERSION: 7.2
2220

2321
steps:
2422
- name: Checkout repository
@@ -30,6 +28,9 @@ jobs:
3028
ruby-version: ${{ matrix.ruby }}
3129
bundler-cache: true
3230

31+
- name: Database setup
32+
run: bin/rails db:create db:migrate db:test:prepare
33+
3334
- name: Run tests
3435
run: bundle exec rspec --profile
3536

.github/workflows/specs_rails80.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
name: Specs Rails 8.0
33

44
on:
5-
push:
6-
branches:
7-
- main
85
pull_request:
9-
branches:
10-
- main
6+
branches: [main]
7+
push:
8+
branches: [main]
119

1210
jobs:
13-
tests:
11+
test:
1412
runs-on: ubuntu-latest
1513

1614
strategy:
1715
matrix:
18-
ruby: ['3.2', '3.3', '3.4']
16+
ruby: ['3.2', '3.4']
1917

2018
env:
21-
RAILS_VERSION: 8.0.0
19+
RAILS_VERSION: 8.0
2220

2321
steps:
2422
- name: Checkout repository
@@ -30,6 +28,9 @@ jobs:
3028
ruby-version: ${{ matrix.ruby }}
3129
bundler-cache: true
3230

31+
- name: Database setup
32+
run: bin/rails db:create db:migrate db:test:prepare
33+
3334
- name: Run tests
3435
run: bundle exec rspec --profile
3536

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/_misc/
99
/coverage/
1010
/spec/dummy/db/*.sqlite3*
11+
/spec/dummy/db/schema-dev.rb
1112
/spec/dummy/log/
1213
/spec/dummy/storage/
1314
/spec/dummy/tmp/

Gemfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22

33
source 'https://rubygems.org'
44

5+
def eval_version(dependency, version)
6+
return [dependency] if version.empty?
7+
8+
version.count('.') < 2 ? [dependency, "~> #{version}.0"] : [dependency, version]
9+
end
10+
511
if ENV['DEVEL'] == '1'
612
gem 'activeadmin_quill_editor', path: './'
713
else
814
gemspec
915
end
1016

1117
ruby_ver = ENV.fetch('RUBY_VERSION', '')
12-
rails_ver = ENV.fetch('RAILS_VERSION', '')
13-
activeadmin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '')
1418

15-
rails = rails_ver.empty? ? ['rails'] : ['rails', "~> #{rails_ver}"]
19+
rails_ver = ENV.fetch('RAILS_VERSION', '')
20+
rails = eval_version('rails', rails_ver)
1621
gem(*rails)
1722

18-
activeadmin = activeadmin_ver.empty? ? ['activeadmin'] : ['activeadmin', "~> #{activeadmin_ver}"]
19-
gem(*activeadmin)
23+
active_admin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '')
24+
active_admin = eval_version('activeadmin', active_admin_ver)
25+
gem(*active_admin)
2026

21-
ruby32 = Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
22-
rails72 = Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
23-
sqlite3 = ruby32 || rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
27+
ruby32 = ruby_ver.empty? || Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2')
28+
rails72 = rails_ver.empty? || Gem::Version.new(rails_ver) >= Gem::Version.new('7.2')
29+
sqlite3 = ruby32 && rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4']
2430
gem(*sqlite3)
2531

32+
gem 'zeitwerk', '~> 2.6.18' unless ruby32
33+
2634
# NOTE: to avoid error: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger
2735
gem 'concurrent-ruby', '1.3.4'
2836

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
include extra/.env
22

33
help:
4-
@echo "Main targets: build / specs / up / server / specs / shell"
4+
@echo -e "${COMPOSE_PROJECT_NAME} - Main project commands:\n\
5+
make up # starts the dev services (optional env vars: RUBY / RAILS / ACTIVEADMIN)\n\
6+
make specs # run the tests (after up)\n\
7+
make lint # run the linters (after up)\n\
8+
make server # run the server (after up)\n\
9+
make shell # open a shell (after up)\n\
10+
make down # cleanup (after up)\n\
11+
Example: RUBY=3.2 RAILS=7.1 ACTIVEADMIN=3.2.0 make up"
512

613
# System commands
714

@@ -10,7 +17,7 @@ build:
1017
@docker compose -f extra/docker-compose.yml build
1118

1219
db_reset:
13-
@docker compose -f extra/docker-compose.yml run --rm app bin/rails db:reset db:test:prepare
20+
@docker compose -f extra/docker-compose.yml run --rm app bin/rails db:create db:migrate db:test:prepare
1421

1522
up: build db_reset
1623
@docker compose -f extra/docker-compose.yml up
@@ -23,13 +30,16 @@ down:
2330

2431
# App commands
2532

26-
console:
33+
seed:
34+
@docker compose -f extra/docker-compose.yml exec app bin/rails db:seed
35+
36+
console: seed
2737
@docker compose -f extra/docker-compose.yml exec app bin/rails console
2838

2939
lint:
3040
@docker compose -f extra/docker-compose.yml exec app bin/rubocop
3141

32-
server:
42+
server: seed
3343
@docker compose -f extra/docker-compose.yml exec app bin/rails server -b 0.0.0.0 -p ${SERVER_PORT}
3444

3545
specs:

extra/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ ENV ACTIVEADMIN_VERSION=$ACTIVEADMIN_VERSION
2626
WORKDIR /app
2727
COPY . /app
2828
RUN bundle install
29-
RUN mkdir -p /app/spec/dummy/db && chown -R app:app /app/spec/dummy/db /usr/local/bundle
29+
RUN chown -R app:app /usr/local/bundle
3030

3131
RUN ln -s /app/extra/.bashrc /home/app/.bashrc

0 commit comments

Comments
 (0)