Skip to content

Commit b361ec9

Browse files
authored
[PROF-11827] Bootstrap publishing ruby gem from CI using trusted publishing (#1067)
**What does this PR do?** This PR bootstraps a new GitHub workflow to publish the `libdatadog` Ruby gem directly from CI and using [trusted publishing](https://guides.rubygems.org/trusted-publishing/). It's not fully set up completely, as I'm having trouble testing the authentication part, I suspect because I'm working off a branch and because the workflow does not yet exist on main. Note also that I've set up a `publish-ruby` environment in https://github.com/datadog/libdatadog/settings/environments which can be used to control who can run this action. **Motivation:** Replace our current release approach that requires manually accessing authentication keys to one that's fully automated and verified. **Additional Notes:** N/A **How to test the change?** As I said above, this is not yet fully wired up. Also, on purpose I've disabled the step where we would upload actual packages until we can fully validate everything is working fine.
1 parent f292b76 commit b361ec9

File tree

6 files changed

+41
-30
lines changed

6 files changed

+41
-30
lines changed

.github/workflows/publish-ruby.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Publish Ruby gem
2+
on: workflow_dispatch
3+
4+
concurrency: "publish-ruby" # Only one publish job at a time
5+
6+
jobs:
7+
publish-ruby:
8+
name: Build and push gem to RubyGems.org
9+
runs-on: ubuntu-24.04
10+
environment: "publish-ruby" # see: https://github.com/datadog/libdatadog/settings/environments
11+
permissions:
12+
id-token: write # Required for trusted publishing, see https://github.com/rubygems/release-gem
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- name: Set up Ruby
16+
uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
17+
with:
18+
ruby-version: 'ruby'
19+
- name: Install dependencies
20+
working-directory: ruby
21+
run: bundle install
22+
- uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1

rakefile.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file is used so that the Ruby `rake` command can be used from the root of the repository.
2+
# This is needed for the publish-ruby.yml CI workflow to work.
3+
4+
require "rake"
5+
6+
Dir.chdir("ruby")
7+
Rake.application.add_import("Rakefile")
8+
Rake.application.load_imports

ruby/README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
`libdatadog` provides a shared library containing common code used in the implementation of Datadog's libraries,
44
including [Continuous Profilers](https://docs.datadoghq.com/tracing/profiler/).
55

6-
(In a past life, `libdatadog` was known as [`libddprof`](https://github.com/datadog/libddprof) but it was renamed when
7-
we decided to increase its scope).
8-
96
**NOTE**: If you're building a new Datadog library/profiler or want to contribute to Datadog's existing tools, you've come to the
107
right place!
118
Otherwise, this is possibly not the droid you were looking for.
@@ -19,20 +16,18 @@ You can also run `bundle exec pry` for an interactive prompt that will allow you
1916

2017
You can use `bundle exec rake package` to generate packages locally without publishing them.
2118

22-
TIP: If the test that checks for permissions ("gem release process ... sets the right permissions on the gem files"), you
19+
TIP: If the test that checks for permissions ("gem release process ... sets the right permissions on the gem files"), fails you
2320
may need to run `umask 0022 && bundle exec rake package` so that the generated packages have the correct permissions.
2421

2522
## Releasing a new version to rubygems.org
2623

27-
Note: No Ruby needed to run this! It all runs inside docker :)
28-
29-
Note: Publishing new releases to rubygems.org can only be done by Datadog employees.
24+
Note: No Ruby needed to run this! It all runs in CI!
3025

3126
1. [ ] Locate the new libdatadog release on GitHub: <https://github.com/datadog/libdatadog/releases>
3227
2. [ ] Update the `LIB_GITHUB_RELEASES` section of the `Rakefile` with the hashes from the new version
3328
3. [ ] Update the <lib/libdatadog/version.rb> file with the `LIB_VERSION` and `VERSION` to use
3429
4. [ ] Commit change, open PR, get it merged
35-
5. [ ] Release by running `docker-compose run push_to_rubygems`.
30+
5. [ ] Trigger the "Publish Ruby gem" workflow in <https://github.com/DataDog/libdatadog/actions/workflows/publish-ruby.yml>
3631
6. [ ] Verify that release shows up correctly on: <https://rubygems.org/gems/libdatadog>
3732

3833
## Contributing

ruby/Rakefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,10 @@ task push_to_rubygems: [
129129
:package,
130130
:"release:guard_clean"
131131
] do
132-
puts "Please input 'libdatadog ruby release key' from 'Shared-Profiling' Datadog 1Password:"
133-
input = $stdin.gets.strip
134-
135-
ENV["GEM_HOST_API_KEY"] = input
136-
137-
system("gem push pkg/libdatadog-#{Libdatadog::VERSION}.gem")
138-
system("gem push pkg/libdatadog-#{Libdatadog::VERSION}-x86_64-linux.gem")
139-
system("gem push pkg/libdatadog-#{Libdatadog::VERSION}-aarch64-linux.gem")
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")
140136
end
141137

142138
module Helpers
@@ -198,3 +194,6 @@ end
198194

199195
Rake::Task["build"].clear
200196
task(:build) { raise "Build task is disabled, use package instead" }
197+
198+
Rake::Task["release"].clear
199+
task(:release) { Rake::Task["push_to_rubygems"].invoke }

ruby/docker-compose.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

ruby/gems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
gem "http", "~> 5.0" unless RUBY_VERSION < "2.5"
1212
gem "pry"
1313
gem "pry-byebug" unless RUBY_VERSION > "3.1"
14+
gem "rubygems-await"

0 commit comments

Comments
 (0)