Skip to content

Commit

Permalink
move cross_gems and publish to publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecsl committed Oct 16, 2024
1 parent fb6b21d commit 173110f
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 198 deletions.
166 changes: 162 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,196 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

cross_gems:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ruby-sdk
strategy:
fail-fast: false
matrix:
_:
- platform: x86_64-linux
# This is necessary because rb-sys-dock depends on manylinux2014,
# which is based on CentOS 7 which is EOL as of July 2024 Once
# rake-compiler-dock switches to manylinux_2_28 and rb-sys-dock
# picks that up, we can pick their updates up and then drop this.
# See https://github.com/oxidize-rb/rb-sys/issues/402 and
# https://github.com/rake-compiler/rake-compiler-dock/issues/122
# for more details.
rb-sys-dock-setup: ./build/x86-64_linux-setup.sh
- platform: x86_64-linux-musl
- platform: aarch64-linux
- platform: aarch64-linux-musl
- platform: arm-linux
- platform: arm64-darwin
# - platform: x64-mingw32
# - platform: x86-mingw-ucrt
steps:
- uses: actions/checkout@v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.3"
bundler-cache: true
cargo-cache: true
cargo-vendor: true
cache-version: v2-${{ matrix._.platform }}

- name: Set vars
id: vars
run: |
echo "rb-sys-version=$(bundle exec ruby -rrb_sys -e 'puts RbSys::VERSION')" >> $GITHUB_OUTPUT
- uses: "ruby/setup-ruby@v1"
with:
ruby-version: "3.2"
bundler-cache: true

- name: Configure environment
shell: bash
id: configure
run: |
: Configure environment
echo "RB_SYS_DOCK_UID=$(id -u)" >> $GITHUB_ENV
echo "RB_SYS_DOCK_GID=$(id -g)" >> $GITHUB_ENV
rb_sys_version="$((grep rb_sys Gemfile.lock | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') || (gem info rb_sys --remote | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') || echo "latest")"
rb_sys_dock_cache_dir="$HOME/.cache/rb-sys-$rb_sys_version"
mkdir -p "$rb_sys_dock_cache_dir"
echo "RB_SYS_DOCK_CACHE_DIR=$rb_sys_dock_cache_dir" >> $GITHUB_ENV
echo "rb_sys_version=$rb_sys_version" >> $GITHUB_OUTPUT
- name: Setup caching
uses: actions/cache@v4
with:
path: |
${{ env.RB_SYS_DOCK_CACHE_DIR }}
ruby-sdk/tmp/rb-sys-dock/${{ matrix._.platform }}/target
key: rb-sys-dock-v0-${{ matrix._.platform }}-${{ hashFiles('**/Gemfile.lock', '**/Cargo.lock') }}
save-always: true
restore-keys: |
rb-sys-dock-v0-${{ matrix._.platform }}-
- name: Install cargo-cache
uses: oxidize-rb/actions/cargo-binstall@v1
id: install-cargo-cache
with:
crate: cargo-cache
version: 0.8.3
strategies: quick-install

- name: Clean the cargo cache
uses: oxidize-rb/actions/post-run@v1
with:
run: cargo-cache --autoclean
cwd: ruby-sdk
always: true

- name: Setup rb-sys
shell: bash
working-directory: ruby-sdk
run: |
version="${{ steps.configure.outputs.rb_sys_version }}"
echo "Installing rb_sys@$version"
if [ "$version" = "latest" ]; then
gem install rb_sys
else
gem install rb_sys -v $version
fi
- name: Build gem
shell: bash
run: |
: Compile gem
echo "Docker Working Directory: $(pwd)"
set -x
# We can't actually parallelize the Ruby versions because
# they get bundled into the same gem.
#
# However, not parallelizing versions is actually helpful
# because Cargo is able to reuse most of compile work
# between versions.
rb-sys-dock \
--platform ${{ matrix._.platform }} \
--mount-toolchains \
--ruby-versions 3.3,3.2,3.1,3.0 \
--build \
-- ${{ matrix._.rb-sys-dock-setup }}
- name: Set outputs
id: set-outputs
shell: bash
run: |
: Set output
echo "gem-path=ruby-sdk/$(find pkg -name '*-${{ matrix._.platform }}.gem')" >> $GITHUB_OUTPUT
- name: Upload the cross-compiled gems
uses: actions/upload-artifact@v3
with:
name: cross-gem
path: ${{ steps.set-outputs.outputs.gem-path }}

publish_ruby:
name: Publish to RubyGems
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref_name, 'ruby-sdk@') }}
needs: cross_gems
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-node@v3
with:
node-version: '20'

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Download the cross-compiled gems
uses: actions/download-artifact@v3
with:
name: cross-gem

- name: Check Cargo.lock
# Ensure that Cargo.lock matches Cargo.toml
run: cargo update --workspace --locked --verbose
working-directory: ruby-sdk

- name: Install dependencies
run: bundle install
working-directory: ruby-sdk

- name: Build
run: bundle exec rake build
working-directory: ruby-sdk

- name: Move the downloaded artifacts
run: |
mv *.gem ruby-sdk/pkg
- name: Publish to RubyGems
working-directory: ruby-sdk/pkg/
env:
RUBYGEMS_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
gem push pkg/eppo-server-sdk-*.gem
env:
RUBYGEMS_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
working-directory: ruby-sdk
ls -l
for i in *.gem; do
if [ -f "$i" ]; then
if ! gem push "$i" >push.out; then
gemerr=$?
sed 's/^/::error:: /' push.out
if ! grep -q "Repushing of gem" push.out; then
exit $gemerr
fi
fi
fi
done
194 changes: 0 additions & 194 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,197 +53,3 @@ jobs:

- name: Run tests
run: npm run with-server test:ruby
cross_gems:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ruby-sdk
strategy:
fail-fast: false
matrix:
_:
- platform: x86_64-linux
# This is necessary because rb-sys-dock depends on manylinux2014,
# which is based on CentOS 7 which is EOL as of July 2024 Once
# rake-compiler-dock switches to manylinux_2_28 and rb-sys-dock
# picks that up, we can pick their updates up and then drop this.
# See https://github.com/oxidize-rb/rb-sys/issues/402 and
# https://github.com/rake-compiler/rake-compiler-dock/issues/122
# for more details.
rb-sys-dock-setup: ./build/x86-64_linux-setup.sh
- platform: x86_64-linux-musl
- platform: aarch64-linux
- platform: aarch64-linux-musl
- platform: arm-linux
- platform: arm64-darwin
# - platform: x64-mingw32
# - platform: x86-mingw-ucrt
steps:
- uses: actions/checkout@v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.3"
bundler-cache: true
cargo-cache: true
cargo-vendor: true
cache-version: v2-${{ matrix._.platform }}

- name: Set vars
id: vars
run: |
echo "rb-sys-version=$(bundle exec ruby -rrb_sys -e 'puts RbSys::VERSION')" >> $GITHUB_OUTPUT
- uses: "ruby/setup-ruby@v1"
with:
ruby-version: "3.2"
bundler-cache: true

- name: Configure environment
shell: bash
id: configure
run: |
: Configure environment
echo "RB_SYS_DOCK_UID=$(id -u)" >> $GITHUB_ENV
echo "RB_SYS_DOCK_GID=$(id -g)" >> $GITHUB_ENV
rb_sys_version="$((grep rb_sys Gemfile.lock | head -n 1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') || (gem info rb_sys --remote | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') || echo "latest")"
rb_sys_dock_cache_dir="$HOME/.cache/rb-sys-$rb_sys_version"
mkdir -p "$rb_sys_dock_cache_dir"
echo "RB_SYS_DOCK_CACHE_DIR=$rb_sys_dock_cache_dir" >> $GITHUB_ENV
echo "rb_sys_version=$rb_sys_version" >> $GITHUB_OUTPUT
- name: Setup caching
uses: actions/cache@v4
with:
path: |
${{ env.RB_SYS_DOCK_CACHE_DIR }}
ruby-sdk/tmp/rb-sys-dock/${{ matrix._.platform }}/target
key: rb-sys-dock-v0-${{ matrix._.platform }}-${{ hashFiles('**/Gemfile.lock', '**/Cargo.lock') }}
save-always: true
restore-keys: |
rb-sys-dock-v0-${{ matrix._.platform }}-
- name: Install cargo-cache
uses: oxidize-rb/actions/cargo-binstall@v1
id: install-cargo-cache
with:
crate: cargo-cache
version: 0.8.3
strategies: quick-install

- name: Clean the cargo cache
uses: oxidize-rb/actions/post-run@v1
with:
run: cargo-cache --autoclean
cwd: ruby-sdk
always: true

- name: Setup rb-sys
shell: bash
working-directory: ruby-sdk
run: |
version="${{ steps.configure.outputs.rb_sys_version }}"
echo "Installing rb_sys@$version"
if [ "$version" = "latest" ]; then
gem install rb_sys
else
gem install rb_sys -v $version
fi
- name: Build gem
shell: bash
run: |
: Compile gem
echo "Docker Working Directory: $(pwd)"
set -x
# We can't actually parallelize the Ruby versions because
# they get bundled into the same gem.
#
# However, not parallelizing versions is actually helpful
# because Cargo is able to reuse most of compile work
# between versions.
rb-sys-dock \
--platform ${{ matrix._.platform }} \
--mount-toolchains \
--ruby-versions 3.3,3.2,3.1,3.0 \
--build \
-- ${{ matrix._.rb-sys-dock-setup }}
- name: Set outputs
id: set-outputs
shell: bash
run: |
: Set output
echo "gem-path=ruby-sdk/$(find pkg -name '*-${{ matrix._.platform }}.gem')" >> $GITHUB_OUTPUT
- name: Upload the cross-compiled gems
uses: actions/upload-artifact@v3
with:
name: cross-gem
path: ${{ steps.set-outputs.outputs.gem-path }}

publish_ruby:
name: Publish to RubyGems
runs-on: ubuntu-latest
# if: ${{ startsWith(github.ref_name, 'ruby-sdk@') }}
needs: cross_gems
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-node@v3
with:
node-version: '20'

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Download the cross-compiled gems
uses: actions/download-artifact@v3
with:
name: cross-gem

- name: Check Cargo.lock
# Ensure that Cargo.lock matches Cargo.toml
run: cargo update --workspace --locked --verbose
working-directory: ruby-sdk

- name: Install dependencies
run: bundle install
working-directory: ruby-sdk

- name: Build
run: bundle exec rake build
working-directory: ruby-sdk

- name: Move the downloaded artifacts
run: |
mv *.gem ruby-sdk/pkg
- name: Publish to RubyGems
working-directory: ruby-sdk/pkg/
env:
RUBYGEMS_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
ls -l
for i in *.gem; do
if [ -f "$i" ]; then
echo gem push $i
# if ! gem push "$i" >push.out; then
# gemerr=$?
# sed 's/^/::error:: /' push.out
# if ! grep -q "Repushing of gem" push.out; then
# exit $gemerr
# fi
# fi
fi
done

0 comments on commit 173110f

Please sign in to comment.