Skip to content

Commit ddfec9e

Browse files
authored
[PROF-11827] Enable publishing ruby gem from CI using trusted publishing (#1070)
* Fix bundler not working in rubygems/release-gem The `rubygems/release-gem` step was failing with: ``` Run bundle exec rake release Could not locate Gemfile or .bundle/ directory ``` ...because it runs that command from the root of the repository, not the `ruby/` folder. It seems a bit harder to specify the folder, so instead I'm adding a bundler config file to tell bundler (the `bundle` command) where to find what it needs. * Move all files needed to release Ruby to a single folder This way we don't need to litter the repository with random files outside the Ruby folder. * Enable publish step, now that the rest of the workflow is working fine * Add logging to push step * Simplify Ruby publish steps even further This also fixes ruby/setup-ruby caching! * Use `eval_gemfile` instead of copying Gemfile to root (Because the `gems.rb` uses `gemspec` and this failed because it wouldn't find the `gemspec` when run from the root of the repo) * Tweak test name
1 parent e193877 commit ddfec9e

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

.github/workflows/publish-ruby.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ jobs:
1212
id-token: write # Required for trusted publishing, see https://github.com/rubygems/release-gem
1313
steps:
1414
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- name: Set up publish environment # This is needed to allow the following steps to run from the root of the repository
16+
run: |
17+
echo 'eval_gemfile("ruby/gems.rb")' > Gemfile
18+
cp ruby/publish/rakefile.rb .
19+
ln -sf ruby/pkg/ pkg
1520
- name: Set up Ruby
1621
uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
1722
with:
1823
ruby-version: 'ruby'
24+
bundler-cache: true
1925
- name: Install dependencies
20-
working-directory: ruby
2126
run: bundle install
2227
- uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1

ruby/Rakefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ task push_to_rubygems: [
129129
:package,
130130
:"release:guard_clean"
131131
] do
132-
puts "TODO: DISABLED PUSHING TO RUBYGEMS"
133-
# abort unless system("gem push pkg/libdatadog-#{Libdatadog::VERSION}.gem")
134-
# abort unless system("gem push pkg/libdatadog-#{Libdatadog::VERSION}-x86_64-linux.gem")
135-
# abort unless system("gem push pkg/libdatadog-#{Libdatadog::VERSION}-aarch64-linux.gem")
132+
[
133+
"gem push pkg/libdatadog-#{Libdatadog::VERSION}.gem",
134+
"gem push pkg/libdatadog-#{Libdatadog::VERSION}-x86_64-linux.gem",
135+
"gem push pkg/libdatadog-#{Libdatadog::VERSION}-aarch64-linux.gem"
136+
].each do |command|
137+
puts "Running: #{command}"
138+
abort unless system(command)
139+
end
136140
end
137141

138142
module Helpers

ruby/gems.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
source "https://rubygems.org"
44

5-
# Specify your gem's dependencies in libdatadog.gemspec
65
gemspec
76

87
gem "rake", ">= 12.0", "< 14"

ruby/libdatadog.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
3131
`git ls-files -z`
3232
.split("\x0")
3333
.reject do |f|
34-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
34+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|publish)/|\.(?:git|travis|circleci)|appveyor)})
3535
end
3636
.reject do |f|
3737
[".rspec", ".standard.yml", "Rakefile", "docker-compose.yml", "gems.rb", "README.md"].include?(f)
File renamed without changes.

ruby/spec/gem_packaging.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
let(:packaged_gem_file) { "pkg/libdatadog-#{gem_version}.gem" }
1212
let(:executable_permissions) { ["libdatadog-crashtracking-receiver", "libdatadog_profiling.so"] }
1313

14-
it "sets the right permissions on the gem files" do
14+
it "sets the right permissions on the .gem files" do
1515
gem_files = Dir.glob("pkg/*.gem")
1616
expect(gem_files).to include(packaged_gem_file)
1717

0 commit comments

Comments
 (0)