Skip to content

Commit

Permalink
CI: Add test run on Fedora and Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Nov 27, 2024
1 parent bc0eac4 commit c7203bf
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 12 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/binary-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3

jobs:
job_build_x64:
rcd_build:
name: Build
runs-on: ubuntu-latest
strategy:
Expand All @@ -18,7 +18,7 @@ jobs:
- platform: "x64-mingw-ucrt"
- platform: "x64-mingw32"
- platform: "x86-mingw32"
- platform: "x86_64-linux-gnu"
- platform: "x86_64-linux"
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
Expand All @@ -45,7 +45,7 @@ jobs:

job_test_binary:
name: Test
needs: job_build_x64
needs: rcd_build
strategy:
fail-fast: false
matrix:
Expand All @@ -63,7 +63,7 @@ jobs:
PGVERSION: 16.6-1-windows-x64
- os: ubuntu-latest
ruby: "3.2"
platform: "x86_64-linux-gnu"
platform: "x86_64-linux"

runs-on: ${{ matrix.os }}
env:
Expand Down Expand Up @@ -132,3 +132,33 @@ jobs:
ridk enable
find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat
find -name setup.log -print0 | xargs -0 cat
job_binary_multiarch:
name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}})
needs: rcd_build
strategy:
fail-fast: false
matrix:
include:
- from_image: fedora:39
image_platform: linux/x86_64
gem_platform: x86_64-linux
dockerfile: centos
- from_image: alpine
image_platform: linux/x86_64
gem_platform: x86_64-linux
dockerfile: alpine

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download gem-${{ matrix.gem_platform }}
uses: actions/download-artifact@v4
with:
name: binary-gem-${{ matrix.gem_platform }}
- name: Build image and Run tests
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} .
docker run --rm -t --network=host -v `pwd`:/build ruby-test
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ gemspec

source "https://rubygems.org/"

group :development, :test do
group :development do
gem "rdoc", "~> 6.4"
gem "mini_portile2", "~> 2.1"
end

group :test do
gem "bundler", ">= 1.16", "< 3.0"
gem "rake-compiler", "~> 1.0"
gem "rake-compiler-dock", "~> 1.5"
gem "rdoc", "~> 6.4"
gem "rspec", "~> 3.5"
gem "mini_portile2", "~> 2.1"
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
# Specs should succeed without it, but 4 examples are then excluded.
# With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CrossLibraries = [
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
['x86_64-linux-gnu', 'linux-x86_64', 'x86_64-redhat-linux-gnu'],
['x86_64-linux', 'linux-x86_64', 'x86_64-redhat-linux-gnu'],
].map do |platform, openssl_config, toolchain|
CrossLibrary.new platform, openssl_config, toolchain
end
Expand Down
3 changes: 2 additions & 1 deletion lib/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
module PG

# Is this file part of a fat binary gem with bundled libpq?
bundled_libpq_path = Dir[File.expand_path("../ports/#{RUBY_PLATFORM.gsub(/^i386-/, "x86-")}*/lib", __dir__)].first
gem_platform = Gem::Platform.local.to_s
bundled_libpq_path = Dir[File.expand_path("../ports/#{gem_platform}*/lib", __dir__)].first
if bundled_libpq_path
POSTGRESQL_LIB_PATH = bundled_libpq_path
else
Expand Down
4 changes: 2 additions & 2 deletions lib/pg/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ def new(*args)
if PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET && iopts[:host].to_s.empty?
# Many distors patch the hardcoded default UnixSocket path in libpq to /var/run/postgresql instead of /tmp .
# We simply try them all.
iopts[:host] = "/var/run/postgresql" # Ubuntu, Debian, Fedora, Opensuse
",/run/postgresql" # Alpine, Archlinux, Gentoo
iopts[:host] = "/var/run/postgresql" + # Ubuntu, Debian, Fedora, Opensuse
",/run/postgresql" + # Alpine, Archlinux, Gentoo
",/tmp" # Stock PostgreSQL
end

Expand Down
25 changes: 25 additions & 0 deletions spec/env/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG from_image
FROM ${from_image}

RUN uname -a
RUN apk add ruby ruby-etc ruby-rake ruby-dev git gcc make musl-dev gcompat postgresql16 sudo openrc

RUN git config --global --add safe.directory /build
RUN ruby --version
RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")'
RUN gem env
RUN gem inst bundler --conservative
RUN gem list
RUN rc-update add postgresql

WORKDIR /build

CMD ruby -v && \
(rc-service postgresql start || true) && \
ruby -e "puts Gem::Platform.local.to_s" && \
chmod -R ugo+wrX . && \
gem install --local *.gem --verbose --no-document && \
bundle config set --local without 'development' && \
bundle install && \
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values" && \
sudo -u postgres ruby -rpg -S rake test
23 changes: 23 additions & 0 deletions spec/env/Dockerfile.centos
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG from_image
FROM ${from_image}

RUN uname -a
RUN yum install -y ruby-devel rake git gcc make redhat-rpm-config postgresql-server

RUN git config --global --add safe.directory /build
RUN ruby --version
RUN ruby -e 'puts File.read("/proc/#{Process.pid}/maps")'
RUN gem env
RUN gem inst bundler --conservative
RUN gem list

WORKDIR /build

CMD ruby -v && \
ruby -e "puts Gem::Platform.local.to_s" && \
chmod -R ugo+wrX . && \
gem install --local *.gem --verbose --no-document && \
bundle config set --local without 'development' && \
bundle install && \
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values" && \
sudo -u postgres ruby -rpg -S rake test
2 changes: 1 addition & 1 deletion spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@
end

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

Expand Down

0 comments on commit c7203bf

Please sign in to comment.