Skip to content

Commit 299f651

Browse files
authored
Merge pull request #1187 from seuros/updates
Update CI
2 parents 725da07 + e0462b6 commit 299f651

File tree

6 files changed

+66
-149
lines changed

6 files changed

+66
-149
lines changed

.github/workflows/ruby.yml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
services:
3535
mysql:
36-
image: mysql:5.7
36+
image: mysql:8
3737
ports:
3838
- 3306
3939

@@ -56,6 +56,9 @@ jobs:
5656
with:
5757
ruby-version: ${{ matrix.ruby-version }}
5858
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
59+
- name: Setup gdiff
60+
run: |
61+
sudo ln -s /usr/bin/diff /usr/bin/gdiff || true
5962
- name: Setup database
6063
run: |
6164
sudo service mysql start
@@ -89,10 +92,10 @@ jobs:
8992

9093
services:
9194
postgres:
92-
image: postgres:11
95+
image: postgres:17
9396
env:
9497
POSTGRES_PASSWORD: postgres
95-
POSTGRES_HOST_AUTH_METHOD: trust
98+
POSTGRES_DB: postgres
9699
ports:
97100
- 5432:5432
98101
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
@@ -104,7 +107,8 @@ jobs:
104107
PREPARED_STATEMENTS: ${{ matrix.prepared_statements }}
105108
PGHOST: localhost
106109
PGPORT: 5432
107-
PGUSER: postgres
110+
PGUSER: arjdbc
111+
PGPASSWORD: arjdbc
108112

109113
steps:
110114
- uses: actions/checkout@v4
@@ -118,10 +122,23 @@ jobs:
118122
with:
119123
ruby-version: ${{ matrix.ruby-version }}
120124
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
125+
- name: Install PostgreSQL 17 client
126+
run: |
127+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
128+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
129+
sudo apt-get update
130+
sudo apt-get install -y postgresql-client-17
131+
- name: Setup gdiff
132+
run: |
133+
sudo ln -s /usr/bin/diff /usr/bin/gdiff || true
121134
- name: Setup database
122135
run: |
123-
psql -c "create database activerecord_unittest;" -U postgres
124-
psql -c "create database activerecord_unittest2;" -U postgres
136+
PGPASSWORD=postgres psql -h localhost -U postgres -c "CREATE USER arjdbc WITH SUPERUSER CREATEDB LOGIN PASSWORD 'arjdbc';"
137+
echo "Testing connection as arjdbc user..."
138+
PGPASSWORD=arjdbc psql -h localhost -d postgres -U arjdbc -c '\l'
139+
echo "Exit status: $?"
140+
PGPASSWORD=arjdbc psql -h localhost -d postgres -c "create database activerecord_unittest;" -U arjdbc
141+
PGPASSWORD=arjdbc psql -h localhost -d postgres -c "create database activerecord_unittest2;" -U arjdbc
125142
- name: Build
126143
run: |
127144
rake jar # compiles ext generates: lib/arjdbc/jdbc/adapter_java.jar
@@ -158,6 +175,9 @@ jobs:
158175
with:
159176
ruby-version: ${{ matrix.ruby-version }}
160177
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
178+
- name: Setup gdiff
179+
run: |
180+
sudo ln -s /usr/bin/diff /usr/bin/gdiff || true
161181
- name: Build
162182
run: |
163183
echo "JAVA_OPTS=$JAVA_OPTS"
@@ -181,7 +201,7 @@ jobs:
181201

182202
services:
183203
mysql:
184-
image: mysql:5.7
204+
image: mysql:8
185205
ports:
186206
- 3306
187207

@@ -231,10 +251,10 @@ jobs:
231251

232252
services:
233253
postgres:
234-
image: postgres:11
254+
image: postgres:17
235255
env:
236256
POSTGRES_PASSWORD: postgres
237-
POSTGRES_HOST_AUTH_METHOD: trust
257+
POSTGRES_DB: postgres
238258
ports:
239259
- 5432:5432
240260
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
@@ -247,7 +267,8 @@ jobs:
247267
INSERT_RETURNING: ${{ matrix.insert_returning }}
248268
PGHOST: localhost
249269
PGPORT: 5432
250-
PGUSER: postgres
270+
PGUSER: arjdbc
271+
PGPASSWORD: arjdbc
251272

252273
steps:
253274
- uses: actions/checkout@v4
@@ -261,6 +282,20 @@ jobs:
261282
with:
262283
ruby-version: ${{ matrix.ruby-version }}
263284
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
285+
- name: Install PostgreSQL 17 client
286+
run: |
287+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
288+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
289+
sudo apt-get update
290+
sudo apt-get install -y postgresql-client-17
291+
- name: Setup PostgreSQL user
292+
run: |
293+
PGPASSWORD=postgres psql -h localhost -U postgres -c "CREATE USER arjdbc WITH SUPERUSER CREATEDB LOGIN PASSWORD 'arjdbc';"
294+
- name: Test PostgreSQL connection
295+
run: |
296+
echo "Testing connection as arjdbc user..."
297+
PGPASSWORD=arjdbc psql -h localhost -d postgres -U arjdbc -c '\l'
298+
echo "Exit status: $?"
264299
- name: Build
265300
run: |
266301
rake jar

.travis.yml

Lines changed: 0 additions & 128 deletions
This file was deleted.

rakelib/db.rake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
3939
task :postgresql do
4040
require File.expand_path('../../test/shared_helper', __FILE__)
4141
fail 'could not create test database: psql executable not found' unless psql = which('psql')
42-
fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
42+
fail 'could not create test database: missing "arjdbc" role' unless PostgresHelper.postgres_role?
4343

4444
load 'test/db/postgres_config.rb' # rescue nil
4545
puts POSTGRES_CONFIG.inspect if $VERBOSE
@@ -53,11 +53,13 @@ CREATE DATABASE #{POSTGRES_CONFIG[:database]} OWNER #{POSTGRES_CONFIG[:username]
5353
ENCODING '#{POSTGRES_CONFIG[:encoding]}' LC_COLLATE '#{POSTGRES_CONFIG[:collate]}' LC_CTYPE '#{POSTGRES_CONFIG[:collate]}';
5454
SQL
5555

56-
params = { '-U' => ENV['PSQL_USER'] || 'postgres' }
56+
params = { '-U' => ENV['PGUSER'] || 'arjdbc', '-d' => 'postgres' }
57+
params['-h'] = ENV['PGHOST'] if ENV['PGHOST']
58+
params['-p'] = ENV['PGPORT'] if ENV['PGPORT']
5759
params['-q'] = nil unless $VERBOSE
5860

5961
puts "Creating PostgreSQL (test) database: #{POSTGRES_CONFIG[:database]}"
60-
sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", verbose: $VERBOSE
62+
sh "PGPASSWORD=#{ENV['PGPASSWORD'] || 'arjdbc'} cat #{script.path} | #{psql} #{params.to_a.join(' ')}", verbose: $VERBOSE
6163
end
6264
task postgres: :postgresql
6365

test/db/postgres_config.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
POSTGRES_CONFIG = {
22
:adapter => 'postgresql',
3-
:database => 'arjdbc_test',
3+
:database => ENV['PGDATABASE'] || 'arjdbc_test',
44
:host => 'localhost',
5-
:username => 'arjdbc',
6-
:password => 'arjdbc',
5+
:username => ENV['PGUSER'] || 'arjdbc',
6+
:password => ENV['PGPASSWORD'] || 'arjdbc',
77
:connect_timeout => 10, # seconds
88
:encoding => 'utf8',
99
:collate => 'en_US.UTF-8',

test/db/postgresql/rake_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ def psql(args)
115115
end
116116

117117
# Use the test database user or fallback to ENV
118-
username = db_config[:username] || ENV['PSQL_USERNAME'] || 'postgres'
118+
username = db_config[:username] || ENV['PGUSER'] || 'arjdbc'
119119
args = "--username=#{username} #{args}"
120120

121121
puts "psql args: #{args}"
122122

123123
# Set PGPASSWORD for authentication
124124
env = {}
125-
env['PGPASSWORD'] = db_config[:password] || 'postgres'
125+
env['PGPASSWORD'] = db_config[:password] || 'arjdbc'
126126

127127
IO.popen(env, "#{PSQL_EXE} #{args}") { |io| io.read }
128128
end

test/shared_helper.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ module PostgresHelper
2525
class << self
2626
def postgres_role?(warn = nil)
2727
if psql = which('psql')
28-
if `#{psql} -c '\\l' -U postgres #{psql_params}2>&1` && $?.exitstatus == 0
28+
user = ENV['PGUSER'] || 'arjdbc'
29+
password = ENV['PGPASSWORD'] || 'arjdbc'
30+
host = ENV['PGHOST'] || 'localhost'
31+
port = ENV['PGPORT'] || '5432'
32+
33+
# Use simpler command with explicit parameters
34+
cmd = "PGPASSWORD=#{password} #{psql} -h #{host} -p #{port} -d postgres -U #{user} -c '\\q' 2>&1"
35+
36+
if `#{cmd}` && $?.exitstatus == 0
2937
true
3038
else
3139
if warn.nil?
32-
warn = "No \"postgres\" role ? Make sure service postgresql is running, "
33-
warn << "than you might need to execute `createuser postgres -drs' first."
40+
warn = "No \"#{user}\" role ? Make sure service postgresql is running, "
41+
warn << "than you might need to execute `createuser #{user} -drs' first."
3442
end
3543
send(:warn, warn) if warn # warn == false disables warnings
3644
false

0 commit comments

Comments
 (0)