Skip to content

Commit bfe3597

Browse files
authored
Merge pull request rapid7#20001 from cgranleese-r7/add-gem-verify-shared-pipeline
Adds a shared pipeline for gems verify workflow
2 parents 3d374ab + 81aa4be commit bfe3597

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Shared Gem Verify
2+
on:
3+
workflow_call:
4+
inputs:
5+
test_commands:
6+
description: 'Test commands'
7+
required: false
8+
default: "bundle exec rspec"
9+
type: string
10+
dependencies:
11+
description: 'Array of system dependencies to install'
12+
required: false
13+
default: "[]"
14+
type: string
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 40
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
ruby:
25+
- '3.2'
26+
- '3.3'
27+
- '3.4'
28+
os:
29+
- ubuntu-20.04
30+
- ubuntu-22.04
31+
- ubuntu-24.04
32+
- ubuntu-latest
33+
- windows-2019
34+
- macos-13
35+
36+
env:
37+
RAILS_ENV: test
38+
39+
name: ${{ matrix.os }} - Ruby ${{ matrix.ruby }}
40+
steps:
41+
- name: Install system dependencies
42+
if: ${{ inputs.dependencies != '[]' && !contains(matrix.os, 'macos') && !contains(matrix.os, 'windows') }}
43+
run: |
44+
dependencies=$(echo '${{ inputs.dependencies }}' | jq -r '.[]')
45+
for dep in $dependencies; do
46+
sudo apt-get -y --no-install-recommends install "$dep"
47+
done
48+
shell: bash
49+
50+
- name: Install system dependencies (Windows)
51+
if: ${{ contains(matrix.os, 'windows') && inputs.dependencies != '[]' }}
52+
run: |
53+
$dependencies = (echo '${{ inputs.dependencies }}' | jq -r '.[]')
54+
foreach ($dep in $dependencies) {
55+
choco install $dep -y
56+
}
57+
shell: pwsh
58+
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Setup Ruby
63+
uses: ruby/setup-ruby@v1
64+
with:
65+
ruby-version: ${{ matrix.ruby }}
66+
bundler-cache: true
67+
68+
- name: Test
69+
run: ${{ inputs.test_commands }}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Shared Gem Verify Rails/PostgreSQL
2+
on:
3+
workflow_call:
4+
inputs:
5+
test_commands:
6+
description: 'Test commands'
7+
required: false
8+
default: "bundle exec rspec"
9+
type: string
10+
dependencies:
11+
description: 'Array of system dependencies to install'
12+
required: false
13+
default: "[]"
14+
type: string
15+
16+
jobs:
17+
test:
18+
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 40
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
ruby:
25+
- '3.2'
26+
- '3.3'
27+
- '3.4'
28+
rails:
29+
- '~> 7.0.0'
30+
- '~> 7.1.0'
31+
- '~> 7.2.0'
32+
postgres:
33+
- '9.6'
34+
- '16.8'
35+
os:
36+
- ubuntu-latest
37+
38+
env:
39+
RAILS_ENV: test
40+
41+
name: ${{ matrix.os }} - Ruby ${{ matrix.ruby }} - Rails ${{ matrix.rails }} - PostgreSQL ${{ matrix.postgres }}
42+
steps:
43+
- name: Install system dependencies
44+
run: |
45+
dependencies=$(echo '${{ inputs.dependencies }}' | jq -r '.[]')
46+
for dep in $dependencies; do
47+
sudo apt-get -y --no-install-recommends install "$dep"
48+
done
49+
shell: bash
50+
51+
- name: Set up PostgreSQL service
52+
run: |
53+
docker run --name postgres -d -p 5432:5432 \
54+
-e POSTGRES_USER=postgres \
55+
-e POSTGRES_PASSWORD=postgres \
56+
--health-cmd="pg_isready" \
57+
--health-interval="10s" \
58+
--health-timeout="5s" \
59+
--health-retries=5 \
60+
postgres:${{ matrix.postgres }}
61+
62+
- name: Wait for PostgreSQL to be healthy
63+
run: |
64+
docker exec postgres sh -c 'until pg_isready -U postgres; do echo waiting for postgres; sleep 2; done; echo postgres is ready'
65+
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Setup Ruby
70+
uses: ruby/setup-ruby@v1
71+
with:
72+
ruby-version: ${{ matrix.ruby }}
73+
bundler-cache: true
74+
75+
- name: Update Rails version
76+
run: |
77+
# Add the gem explicitly if it doesn't exist
78+
if ! grep -q "gem ['\"]rails['\"]" Gemfile; then
79+
echo 'gem "rails"' >> Gemfile
80+
fi
81+
82+
# Ensure the gem is on the latest version
83+
ruby -pi -e "gsub(/gem ['\"]rails['\"](, *['\"].*['\"])?/, \"gem 'rails', '${{ matrix.rails }}'\")" Gemfile
84+
bundle update
85+
bundle install
86+
bundle show rails
87+
shell: bash
88+
89+
- name: Test
90+
run: ${{ inputs.test_commands }}

0 commit comments

Comments
 (0)