|
1 | | -# This workflow uses actions that are not certified by GitHub. They are |
2 | | -# provided by a third-party and are governed by separate terms of service, |
3 | | -# privacy policy, and support documentation. |
4 | | -# |
5 | | -# This workflow will install a prebuilt Ruby version, install dependencies, and |
6 | | -# run tests and linters. |
7 | 1 | name: "Ruby on Rails CI" |
8 | | -on: |
9 | | - push: |
10 | | - branches: [ "main", "dev" ] |
11 | | - pull_request: |
12 | | - branches: [ "main", "dev" ] |
| 2 | + |
| 3 | +on: { push: { branches: [main, dev] }, pull_request: { branches: [main, dev] } } |
| 4 | + |
13 | 5 | jobs: |
14 | 6 | rspec: |
15 | 7 | runs-on: ubuntu-latest |
16 | 8 | environment: test |
| 9 | + strategy: |
| 10 | + fail-fast: false |
| 11 | + matrix: |
| 12 | + include: |
| 13 | + - ruby: '3.4.4' |
| 14 | + rails: '7.1.5.1' |
| 15 | + allowed_failure: false # ✅ required |
| 16 | + - ruby: '3.4.4' |
| 17 | + rails: '7.2' |
| 18 | + allowed_failure: true # ⚠️ allowed to fail |
| 19 | + - ruby: '3.4.4' |
| 20 | + rails: '8.0' |
| 21 | + allowed_failure: true # ⚠️ allowed to fail |
| 22 | + |
| 23 | + env: |
| 24 | + RAILS_ENV: test |
| 25 | + DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" |
| 26 | + ES_HOST: "http://localhost" |
| 27 | + RAILS_VERSION: ${{ matrix.rails }} |
| 28 | + |
17 | 29 | services: |
18 | 30 | postgres: |
19 | 31 | image: postgis/postgis:latest |
20 | | - ports: |
21 | | - - "5432:5432" |
22 | | - env: |
23 | | - POSTGRES_DB: rails_test |
24 | | - POSTGRES_USER: rails |
25 | | - POSTGRES_PASSWORD: password |
| 32 | + ports: ["5432:5432"] |
| 33 | + env: { POSTGRES_DB: rails_test, POSTGRES_USER: rails, POSTGRES_PASSWORD: password } |
26 | 34 | elasticsearch: |
27 | 35 | image: elasticsearch:7.17.23 |
28 | | - ports: |
29 | | - - "9200:9200" |
| 36 | + ports: ["9200:9200"] |
30 | 37 | env: |
31 | | - "node.name": elasticsearch |
32 | | - "cluster.name": better-together-es |
33 | | - "discovery.seed_hosts": elasticsearch |
34 | | - "discovery.type": single-node |
35 | | - "bootstrap.memory_lock": true |
36 | | - "ES_JAVA_OPTS": "-Xms512m -Xmx512m" |
37 | | - env: |
38 | | - RAILS_ENV: test |
39 | | - DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" |
40 | | - ES_HOST: "http://localhost" |
| 38 | + node.name: elasticsearch |
| 39 | + cluster.name: better-together-es |
| 40 | + discovery.seed_hosts: elasticsearch |
| 41 | + discovery.type: single-node |
| 42 | + bootstrap.memory_lock: "true" |
| 43 | + ES_JAVA_OPTS: "-Xms512m -Xmx512m" |
| 44 | + |
41 | 45 | steps: |
42 | 46 | - name: Checkout code |
43 | 47 | uses: actions/checkout@v3 |
44 | | - # Add or replace dependency steps here |
45 | | - - name: Install Ruby and gems |
| 48 | + |
| 49 | + - name: Install Ruby & gems |
46 | 50 | uses: ruby/setup-ruby@v1 |
47 | 51 | with: |
48 | | - bundler-cache: true |
49 | | - # Add or replace database setup steps here |
50 | | - - name: Set up database schema |
51 | | - run: rm -f spec/dummy/tmp/pids/server.pid && cd ./spec/dummy && bundle exec rails db:schema:load |
52 | | - # Add or replace test runners here |
53 | | - - name: Run tests |
| 52 | + ruby-version: ${{ matrix.ruby }} |
| 53 | + |
| 54 | + # Run the automatic bundle-install only on 7.1. |
| 55 | + # For 7.2 / 8.0 it just sets up Ruby *and* restores a cache layer |
| 56 | + # that we’ll reuse in the later manual install. |
| 57 | + bundler-cache: ${{ matrix.rails == '7.1.5.1' }} |
| 58 | + |
| 59 | + # One cache bucket per Rails version so they don’t clobber each other. |
| 60 | + cache-version: rails-${{ matrix.rails }} |
| 61 | + |
| 62 | + # Updating Rails can legitimately blow up on the experimental tracks, |
| 63 | + # so we allow that *step* to error out without failing the job. |
| 64 | + - name: Update Rails & install gems |
| 65 | + if: matrix.rails != '7.1.5.1' |
| 66 | + id: update |
| 67 | + run: | |
| 68 | + # turn off deployment mode |
| 69 | + bundle config set deployment false |
| 70 | + # conservative upgrade to the target rails version |
| 71 | + bundle update rails --conservative |
| 72 | + # install missing gems (writes bin/rspec, etc) |
| 73 | + bundle install --jobs 4 --retry 3 |
| 74 | + continue-on-error: ${{ matrix.allowed_failure }} |
| 75 | + |
| 76 | + - name: Prepare DB schema |
| 77 | + if: (matrix.rails == '7.1.5.1') || steps.update.outcome == 'success' |
| 78 | + run: | |
| 79 | + rm -f spec/dummy/tmp/pids/server.pid |
| 80 | + bundle exec rake -f spec/dummy/Rakefile db:schema:load |
| 81 | + continue-on-error: ${{ matrix.allowed_failure }} |
| 82 | + |
| 83 | + - name: Run RSpec |
| 84 | + if: (matrix.rails == '7.1.5.1') || steps.update.outcome == 'success' |
54 | 85 | env: |
55 | 86 | RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} |
56 | | - run: rm -f spec/dummy/tmp/pids/server.pid && bundle exec rspec |
| 87 | + run: | |
| 88 | + rm -f spec/dummy/tmp/pids/server.pid |
| 89 | + bundle exec rspec |
| 90 | + continue-on-error: ${{ matrix.allowed_failure }} |
57 | 91 |
|
| 92 | + # ── style & security jobs (unchanged) ─────────────────────────────────────── |
58 | 93 | rubocop: |
59 | 94 | runs-on: ubuntu-latest |
60 | 95 | steps: |
61 | | - - name: Checkout code |
62 | | - uses: actions/checkout@v3 |
63 | | - - name: Install Ruby and gems |
64 | | - uses: ruby/setup-ruby@v1 |
65 | | - with: |
66 | | - bundler-cache: true |
67 | | - - name: Lint Ruby files with Rubocop |
68 | | - run: bundle exec rubocop --parallel |
| 96 | + - uses: actions/checkout@v3 |
| 97 | + - uses: ruby/setup-ruby@v1 |
| 98 | + with: { bundler-cache: true } |
| 99 | + - run: bundle exec rubocop --parallel |
69 | 100 |
|
70 | 101 | security: |
71 | 102 | runs-on: ubuntu-latest |
72 | 103 | steps: |
73 | | - - name: Checkout code |
74 | | - uses: actions/checkout@v3 |
75 | | - - name: Install Ruby and gems |
76 | | - uses: ruby/setup-ruby@v1 |
77 | | - with: |
78 | | - bundler-cache: true |
79 | | - - name: Generate binstubs |
80 | | - run: bundle binstubs bundler-audit --force |
81 | | - - name: Security audit dependencies |
82 | | - run: bundle exec bundler-audit --update |
83 | | - - name: Security audit application code |
84 | | - run: bundle exec brakeman -q -w2 |
| 104 | + - uses: actions/checkout@v3 |
| 105 | + - uses: ruby/setup-ruby@v1 |
| 106 | + with: { bundler-cache: true } |
| 107 | + - run: bundle binstubs bundler-audit --force |
| 108 | + - run: bundle exec bundler-audit --update |
| 109 | + - run: bundle exec brakeman -q -w2 |
0 commit comments