Skip to content

Commit 54460a7

Browse files
committed
CI: Add test run on Fedora and Alpine
1 parent bc0eac4 commit 54460a7

File tree

10 files changed

+113
-19
lines changed

10 files changed

+113
-19
lines changed

.github/workflows/binary-gems.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3
99

1010
jobs:
11-
job_build_x64:
11+
rcd_build:
1212
name: Build
1313
runs-on: ubuntu-latest
1414
strategy:
@@ -18,7 +18,7 @@ jobs:
1818
- platform: "x64-mingw-ucrt"
1919
- platform: "x64-mingw32"
2020
- platform: "x86-mingw32"
21-
- platform: "x86_64-linux-gnu"
21+
- platform: "x86_64-linux"
2222
steps:
2323
- uses: actions/checkout@v4
2424
- name: Set up Ruby
@@ -45,7 +45,7 @@ jobs:
4545

4646
job_test_binary:
4747
name: Test
48-
needs: job_build_x64
48+
needs: rcd_build
4949
strategy:
5050
fail-fast: false
5151
matrix:
@@ -63,7 +63,7 @@ jobs:
6363
PGVERSION: 16.6-1-windows-x64
6464
- os: ubuntu-latest
6565
ruby: "3.2"
66-
platform: "x86_64-linux-gnu"
66+
platform: "x86_64-linux"
6767

6868
runs-on: ${{ matrix.os }}
6969
env:
@@ -132,3 +132,33 @@ jobs:
132132
ridk enable
133133
find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat
134134
find -name setup.log -print0 | xargs -0 cat
135+
136+
137+
job_binary_multiarch:
138+
name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}})
139+
needs: rcd_build
140+
strategy:
141+
fail-fast: false
142+
matrix:
143+
include:
144+
- from_image: fedora:39
145+
image_platform: linux/x86_64
146+
gem_platform: x86_64-linux
147+
dockerfile: centos
148+
- from_image: alpine
149+
image_platform: linux/x86_64
150+
gem_platform: x86_64-linux
151+
dockerfile: alpine
152+
153+
runs-on: ubuntu-latest
154+
steps:
155+
- uses: actions/checkout@v4
156+
- name: Download gem-${{ matrix.gem_platform }}
157+
uses: actions/download-artifact@v4
158+
with:
159+
name: binary-gem-${{ matrix.gem_platform }}
160+
- name: Build image and Run tests
161+
run: |
162+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
163+
docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} .
164+
docker run --rm -t --network=host -v `pwd`:/build ruby-test

Gemfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ gemspec
55

66
source "https://rubygems.org/"
77

8-
group :development, :test do
8+
group :development do
9+
gem "rdoc", "~> 6.4"
10+
gem "mini_portile2", "~> 2.1"
11+
end
12+
13+
group :test do
914
gem "bundler", ">= 1.16", "< 3.0"
1015
gem "rake-compiler", "~> 1.0"
1116
gem "rake-compiler-dock", "~> 1.5"
12-
gem "rdoc", "~> 6.4"
1317
gem "rspec", "~> 3.5"
14-
gem "mini_portile2", "~> 2.1"
1518
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
1619
# Specs should succeed without it, but 4 examples are then excluded.
1720
# With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CrossLibraries = [
4747
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
4848
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
4949
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
50-
['x86_64-linux-gnu', 'linux-x86_64', 'x86_64-redhat-linux-gnu'],
50+
['x86_64-linux', 'linux-x86_64', 'x86_64-redhat-linux-gnu'],
5151
].map do |platform, openssl_config, toolchain|
5252
CrossLibrary.new platform, openssl_config, toolchain
5353
end

ext/extconf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def install
140140
$LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{gem_platform}/lib'"
141141
# Don't use pg_config for cross build, but --with-pg-* path options
142142
dir_config('pg', "#{postgresql_recipe.path}/include", "#{postgresql_recipe.path}/lib")
143+
144+
$defs.push( "-DPG_IS_BINARY_GEM")
143145
else
144146
# Native build
145147

ext/pg.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,12 @@ Init_pg_ext(void)
671671
/* PostgreSQL compiled in default port */
672672
rb_define_const(rb_mPGconstants, "DEF_PGPORT", INT2FIX(DEF_PGPORT));
673673

674+
#ifdef PG_IS_BINARY_GEM
675+
rb_define_const(rb_mPG, "IS_BINARY_GEM", Qtrue);
676+
#else
677+
rb_define_const(rb_mPG, "IS_BINARY_GEM", Qfalse);
678+
#endif
679+
674680
/* Add the constants to the toplevel namespace */
675681
rb_include_module( rb_mPG, rb_mPGconstants );
676682

lib/pg.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
module PG
77

88
# Is this file part of a fat binary gem with bundled libpq?
9-
bundled_libpq_path = Dir[File.expand_path("../ports/#{RUBY_PLATFORM.gsub(/^i386-/, "x86-")}*/lib", __dir__)].first
9+
# This path must be enabled by add_dll_directory on Windows.
10+
gplat = Gem::Platform.local
11+
bundled_libpq_path = Dir[File.expand_path("../ports/#{gplat.cpu}-#{gplat.os}*/lib", __dir__)].first
1012
if bundled_libpq_path
1113
POSTGRESQL_LIB_PATH = bundled_libpq_path
1214
else
@@ -21,7 +23,7 @@ module PG
2123
end
2224

2325
add_dll_path = proc do |path, &block|
24-
if RUBY_PLATFORM =~/(mswin|mingw)/i && path && File.exist?(path)
26+
if RUBY_PLATFORM =~/(mswin|mingw)/i && path
2527
BUNDLED_LIBPQ_WITH_UNIXSOCKET = false
2628
begin
2729
require 'ruby_installer/runtime'
@@ -32,14 +34,11 @@ module PG
3234
block.call
3335
ENV['PATH'] = old_path
3436
end
35-
elsif RUBY_PLATFORM =~/(linux)/i && bundled_libpq_path && File.exist?(bundled_libpq_path)
36-
BUNDLED_LIBPQ_WITH_UNIXSOCKET = true
37-
# libpq is found by a relative rpath in the cross compiled extension dll
38-
block.call
3937
else
40-
BUNDLED_LIBPQ_WITH_UNIXSOCKET = false
41-
# No need to set a load path manually - it's set as library rpath.
38+
# libpq is found by a relative rpath in the cross compiled extension dll
39+
# or by the system library loader
4240
block.call
41+
BUNDLED_LIBPQ_WITH_UNIXSOCKET = RUBY_PLATFORM=~/linux/i && PG::IS_BINARY_GEM
4342
end
4443
end
4544

lib/pg/connection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ def new(*args)
860860
if PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET && iopts[:host].to_s.empty?
861861
# Many distors patch the hardcoded default UnixSocket path in libpq to /var/run/postgresql instead of /tmp .
862862
# We simply try them all.
863-
iopts[:host] = "/var/run/postgresql" # Ubuntu, Debian, Fedora, Opensuse
864-
",/run/postgresql" # Alpine, Archlinux, Gentoo
863+
iopts[:host] = "/var/run/postgresql" + # Ubuntu, Debian, Fedora, Opensuse
864+
",/run/postgresql" + # Alpine, Archlinux, Gentoo
865865
",/tmp" # Stock PostgreSQL
866866
end
867867

spec/env/Dockerfile.alpine

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG from_image
2+
FROM ${from_image}
3+
4+
RUN uname -a
5+
RUN apk add ruby ruby-etc ruby-rake ruby-dev git gcc make musl-dev gcompat postgresql16 sudo
6+
7+
RUN git config --global --add safe.directory /build
8+
RUN ruby --version
9+
RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")'
10+
RUN gem env
11+
RUN gem inst bundler --conservative
12+
RUN gem list
13+
RUN sudo -u postgres initdb -D /var/lib/postgresql/ && \
14+
mkdir -p /run/postgresql && \
15+
chown postgres /run/postgresql
16+
17+
WORKDIR /build
18+
19+
CMD ruby -v && \
20+
ruby -e "puts Gem::Platform.local.to_s" && \
21+
rm /var/run && sudo -u postgres pg_ctl -D /var/lib/postgresql/ start && \
22+
chmod -R ugo+wrX . && \
23+
gem install --local *.gem --verbose --no-document && \
24+
bundle config set --local without 'development' && \
25+
bundle install && \
26+
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
27+
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb

spec/env/Dockerfile.centos

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG from_image
2+
FROM ${from_image}
3+
4+
RUN uname -a
5+
RUN yum install -y ruby-devel rake git gcc make redhat-rpm-config postgresql-server
6+
7+
RUN git config --global --add safe.directory /build
8+
RUN ruby --version
9+
RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")'
10+
RUN gem env
11+
RUN gem inst bundler --conservative
12+
RUN gem list
13+
RUN sudo -u postgres initdb -D /var/lib/pgsql/data && \
14+
mkdir -p /run/postgresql && \
15+
chown postgres /run/postgresql
16+
17+
WORKDIR /build
18+
19+
CMD ruby -v && \
20+
ruby -e "puts Gem::Platform.local.to_s" && \
21+
sudo -u postgres pg_ctl -D /var/lib/pgsql/data start && \
22+
chmod -R ugo+wrX . && \
23+
gem install --local *.gem --verbose --no-document && \
24+
bundle config set --local without 'development' && \
25+
bundle install && \
26+
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
27+
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb

spec/pg/connection_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
end
699699

700700
it "rejects to send lots of COPY data" do
701-
unless RUBY_PLATFORM =~ /i386-mingw|x86_64-darwin|x86_64-linux/
701+
unless RUBY_PLATFORM =~ /i386-mingw|x86_64-darwin|x86_64-linux$/
702702
skip "this spec depends on out-of-memory condition in put_copy_data, which is not reliable on all platforms"
703703
end
704704

0 commit comments

Comments
 (0)