Skip to content

Commit 2eceae8

Browse files
authored
Merge pull request #24 from berkos/fix-release-rb-sys-dock
Fix release workflow: build native gems with rb-sys-dock
2 parents 40f4a60 + 90c4f1e commit 2eceae8

3 files changed

Lines changed: 50 additions & 99 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,76 @@ on:
33
push:
44
tags:
55
- "[0-9]*.[0-9]*.[0-9]*"
6+
- "v[0-9]*.[0-9]*.[0-9]*"
67

78
jobs:
8-
build_gem:
9+
build_source_gem:
910
name: Build source gem
1011
runs-on: ubuntu-latest
1112
steps:
12-
- uses: actions/checkout@v4
13-
- uses: ruby/setup-ruby-pkgs@v1
13+
- uses: actions/checkout@v6.0.2
14+
- uses: ruby/setup-ruby@v1
1415
with:
15-
ruby-version: 3.4
16-
- run: sudo apt-get update && sudo apt-get install -y libopencv-dev libvips
17-
- run: gem update --system
18-
- run: rake gem
16+
ruby-version: "3.4"
17+
bundler-cache: true
18+
- run: bundle exec rake build
1919
- name: Upload source gem
20-
uses: actions/upload-artifact@v4
20+
uses: actions/upload-artifact@v7.0.0
2121
with:
22-
name: libfacedetection.gem
22+
name: source-gem
2323
path: pkg/*.gem
2424
retention-days: 1
2525

26-
compile_native_gems:
27-
name: Compile native gem
28-
needs: build_gem
26+
build_native_gems:
27+
name: Build native gem (${{ matrix.platform }})
28+
runs-on: ubuntu-latest
2929
strategy:
30+
fail-fast: false
3031
matrix:
31-
include:
32-
- os: ubuntu-24.04
33-
platform: x86_64-linux
34-
ruby: "3.4"
35-
- os: ubuntu-24.04-arm
36-
platform: aarch64-linux
37-
ruby: "3.4"
38-
- os: macos-latest
39-
platform: arm64-darwin
40-
ruby: "3.4"
41-
runs-on: ${{ matrix.os }}
32+
platform:
33+
- x86_64-linux
34+
- aarch64-linux
35+
- x86_64-darwin
36+
- arm64-darwin
4237
steps:
43-
- uses: actions/checkout@v4
44-
45-
- uses: ruby/setup-ruby-pkgs@v1
46-
with:
47-
ruby-version: ${{ matrix.ruby }}
48-
49-
- name: Install system dependencies on Linux
50-
if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-latest-arm64'
51-
run: sudo apt-get update && sudo apt-get install -y libopencv-dev libvips
52-
53-
- name: Install system dependencies on macOS
54-
if: matrix.os == 'macos-latest'
55-
run: brew install opencv vips
56-
57-
- name: Install gem-compiler
58-
run: gem install gem-compiler
59-
60-
- name: Download source gem
61-
uses: actions/download-artifact@v4
38+
- uses: actions/checkout@v6.0.2
39+
- uses: ruby/setup-ruby@v1
6240
with:
63-
name: libfacedetection.gem
64-
path: pkg/
65-
66-
- name: Compile gem
67-
run: |
68-
SOURCE_GEM=$(ls pkg/*.gem | grep -v -- '-x86_64-linux\|aarch64-linux\|arm64-darwin')
69-
gem compile $SOURCE_GEM --prune
70-
71-
- name: Upload compiled gem
72-
uses: actions/upload-artifact@v4
41+
ruby-version: "3.4"
42+
bundler-cache: true
43+
- name: Build native gems
44+
run: bundle exec rb-sys-dock --platform ${{ matrix.platform }} --build
45+
- name: Upload native gems
46+
uses: actions/upload-artifact@v7.0.0
7347
with:
74-
name: libfacedetection-${{ matrix.platform }}.gem
75-
path: ./*.gem
48+
name: native-gem-${{ matrix.platform }}
49+
path: pkg/*-${{ matrix.platform }}.gem
7650
retention-days: 1
7751

7852
release:
7953
name: Create GitHub Release
80-
needs: compile_native_gems
54+
needs:
55+
- build_source_gem
56+
- build_native_gems
8157
runs-on: ubuntu-latest
58+
permissions:
59+
contents: write
8260
steps:
83-
- uses: actions/checkout@v4
84-
8561
- name: Extract version
86-
id: extract_version
8762
run: |
8863
VERSION=${GITHUB_REF#refs/tags/}
64+
VERSION=${VERSION#v}
8965
echo "GEM_VERSION=$VERSION" >> $GITHUB_ENV
9066
9167
- name: Download all artifacts
92-
uses: actions/download-artifact@v4
68+
uses: actions/download-artifact@v8.0.1
9369
with:
9470
path: artifacts
9571

96-
- name: Rename gem files with version
97-
run: |
98-
mkdir -p release_gems
99-
for gem in artifacts/libfacedetection-*.gem/*.gem; do
100-
platform=$(basename $gem | sed -E 's/libfacedetection-([^-]+-[^-]+)\.gem/\1/')
101-
102-
# Construct the target filename: NAME-VERSION-PLATFORM.gem
103-
target_filename="libfacedetection-${GEM_VERSION}-${platform}.gem"
104-
target_path="release_gems/$target_filename"
105-
mv "$gem" "$target_path"
106-
done
107-
# Move source gem to release_gems directory
108-
mv artifacts/libfacedetection.gem/*.gem release_gems/libfacedetection-${GEM_VERSION}.gem
109-
11072
- name: Create release
11173
uses: softprops/action-gh-release@v2
11274
with:
113-
tag_name: ${{ env.GEM_VERSION }}
114-
files: release_gems/*.gem
75+
tag_name: ${{ github.ref_name }}
76+
name: libfacedetection ${{ env.GEM_VERSION }}
77+
files: artifacts/**/*.gem
11578
generate_release_notes: true

Rakefile

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
require 'rubygems/package_task'
1+
# frozen_string_literal: true
22

3-
spec = eval(File.read("libfacedetection.gemspec"))
4-
GEM_RUBY_VERSION = "3.4.0"
5-
DOCKER_IMAGE = "ruby:#{GEM_RUBY_VERSION}-bullseye"
3+
require "bundler/gem_tasks"
64

7-
def compile_cmd(_arch)
8-
"gem instal gem-compiler; curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; source '/root/.cargo/env'; rake gem:native"
9-
end
5+
task gem: :build
106

11-
gem_task = Gem::PackageTask.new(spec) do |pkg|
12-
pkg.need_zip = true
13-
pkg.need_tar = true
14-
end
7+
begin
8+
require "rb_sys/extensiontask"
159

16-
desc "Generate a pre-compiled native gem for #{RUBY_PLATFORM}"
17-
task "gem:native" => ["gem"] do
18-
sh "gem compile #{gem_task.package_dir_path}.gem"
19-
end
20-
21-
desc "Generate a pre-compiled native gem for aarch64-linux"
22-
task "gem:native:aarch64-linux" => ["gem"] do
23-
sh %{docker run --rm --platform linux/arm64 -v $(pwd):/src -w /src #{DOCKER_IMAGE} /bin/bash -c "#{compile_cmd('aarch64-unknown-linux-musl')}"}
24-
end
10+
GEMSPEC = Gem::Specification.load("libfacedetection.gemspec")
2511

26-
desc "Generate a pre-compiled native gem for x86_64-linux"
27-
task "gem:native:x86_64-linux" => ["gem"] do
28-
sh %{docker run --rm --platform linux/amd64 -v $(pwd):/src -w /src #{DOCKER_IMAGE} /bin/bash -c "#{compile_cmd('x86_64-unknown-linux-musl')}"}
12+
RbSys::ExtensionTask.new("libfacedetection-ruby", GEMSPEC) do |ext|
13+
ext.lib_dir = "lib/libfacedetection"
14+
end
15+
rescue LoadError
16+
warn "rb_sys not available, skipping compile tasks (run `bundle install` to enable them)"
2917
end

lib/libfacedetection/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Libfacedetection
2-
VERSION = "0.4.0".freeze
2+
VERSION = "0.4.1".freeze
33
end

0 commit comments

Comments
 (0)