-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ruby release targets #11468
Add ruby release targets #11468
Changes from 41 commits
37169e7
23ecec3
cb46372
77c071f
a86c0f7
6cff86c
b0ca44a
2d1093e
79cf753
7245f1d
1143df8
502a37c
33ac195
2168904
e06f706
a959bd9
f3d3013
f9821fa
c337ae1
4fba166
de13307
78c6163
2a2f131
c6cfbeb
5f35b87
f8d4f2b
f3cbca0
3f0d3f0
252ab69
87238e7
f3f4972
6a7a83f
22aa441
c5d2b4d
fa2aff1
13227fb
642b99a
4f9d690
6df57e6
f164ae4
b10ce37
b7b7eb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Ruby Install Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- '[0-9]+.x' | ||
pull_request: | ||
branches: | ||
- main | ||
- '[0-9]+.x' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_ruby_gems: | ||
name: Test ruby gems | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby: [2.6, 2.7, 3.0, 3.1, 3.2, jruby-9.2, jruby-9.3] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install bazel | ||
run: | | ||
sudo apt-get install -qy wget | ||
mkdir $HOME/bin | ||
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/6.0.0/bazel-6.0.0-linux-x86_64 | ||
chmod a+x $HOME/bin/bazel | ||
- name: Install git | ||
run: | | ||
sudo apt-get install -qy --no-install-recommends git | ||
- name: Install ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
- name: Build and install cruby gem | ||
run: | | ||
$HOME/bin/bazel run ruby:release | ||
gem install bazel-bin/ruby/release.runfiles/com_google_protobuf/tmp/google-protobuf-* | ||
if: ${{ !contains(matrix.ruby, 'jruby') }} | ||
- name: Build and install jruby gem | ||
run: | | ||
$HOME/bin/bazel run ruby:jruby_release | ||
gem install bazel-bin/ruby/jruby_release.runfiles/com_google_protobuf/tmp/google-protobuf-* | ||
if: ${{ contains(matrix.ruby, 'jruby') }} | ||
- name: Test installation | ||
run: | | ||
bazel run //:protoc -- --proto_path=$GITHUB_WORKSPACE/src --proto_path=$GITHUB_WORKSPACE/ruby/tests --proto_path=$GITHUB_WORKSPACE/ruby --ruby_out=$GITHUB_WORKSPACE/ruby tests/test_import_proto2.proto | ||
bazel run //:protoc -- --proto_path=$GITHUB_WORKSPACE/src --proto_path=$GITHUB_WORKSPACE/ruby/tests --proto_path=$GITHUB_WORKSPACE/ruby --ruby_out=$GITHUB_WORKSPACE/ruby tests/basic_test.proto | ||
ruby ruby/tests/basic.rb |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
# This file should be executed with jruby | ||
|
||
set -ex | ||
|
||
# --- begin runfiles.bash initialization --- | ||
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). | ||
set -euo pipefail | ||
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
if [[ -f "$0.runfiles_manifest" ]]; then | ||
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" | ||
elif [[ -f "$0.runfiles/MANIFEST" ]]; then | ||
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" | ||
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
export RUNFILES_DIR="$0.runfiles" | ||
fi | ||
fi | ||
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" | ||
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ | ||
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" | ||
else | ||
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" | ||
exit 1 | ||
fi | ||
# --- end runfiles.bash initialization --- | ||
mkruskal-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Make a temporary directory and move to it to do all packaging work | ||
mkdir -p tmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're in the sandbox now do we need a tmp directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed to make a new directory to start with a clean directory since this ends up being run in bazel-bin's runfile directory where a copy of all of the dependency files are. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets run in |
||
cd tmp | ||
|
||
# Move all generated files to lib/google/protobuf | ||
mkdir -p lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/any_pb.rb)" lib/google/protobuf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went back and forth on this. rlocation doesn't support wildcards, but I think you are suggesting that I get the dirname and then use wildcards which could be possible. I ended up manually listing them as more of a precaution. Everywhere else the files are wildcarded in which I think could make it very easy to lose a file. This will fail in that case, which I think ends up being a good check. On the other hand, a new file being added could cause this to fail silently. What do you think about that tradeoff? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we were missing a file I would expect the gem build/test to fail in our CI. This seems a bit redundant to me, and not worth the maintenance burden. One alternative that might work nicely is to add an sh_test rule that actually runs the tests using the built gem. That way we can actually run our tests locally and not have to wait for the CI to be run over a PR. It would also simplify the ruby_install.yml file I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
cp "$(rlocation com_google_protobuf/src/google/protobuf/api_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/descriptor_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/duration_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/empty_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/field_mask_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/source_context_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/struct_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/timestamp_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/type_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/wrappers_pb.rb)" lib/google/protobuf | ||
|
||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf_java.jar)" lib/google | ||
|
||
# Move all source files to the correct location | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf.rb)" lib/google | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/descriptor_dsl.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/message_exts.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/repeated_field.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/well_known_types.rb)" lib/google/protobuf | ||
|
||
# Move gemspec file to current directory | ||
cp "$(rlocation com_google_protobuf/ruby/google.protobuf.gemspec)" . | ||
|
||
# Make all files global readable/writable/executable | ||
chmod -R 777 ./ | ||
|
||
# Build gem | ||
gem build google-protobuf.gemspec |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
# This file should be executed with ruby | ||
|
||
set -ex | ||
|
||
# --- begin runfiles.bash initialization --- | ||
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). | ||
set -euo pipefail | ||
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
if [[ -f "$0.runfiles_manifest" ]]; then | ||
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" | ||
elif [[ -f "$0.runfiles/MANIFEST" ]]; then | ||
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" | ||
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
export RUNFILES_DIR="$0.runfiles" | ||
fi | ||
fi | ||
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" | ||
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ | ||
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" | ||
else | ||
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" | ||
exit 1 | ||
fi | ||
# --- end runfiles.bash initialization --- | ||
|
||
# rvm use ruby-3.0 | ||
|
||
# Make a temporary directory and move to it to do all packaging work | ||
mkdir -p tmp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments here |
||
cd tmp | ||
|
||
# Move all generated files to lib/google/protobuf | ||
mkdir -p lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/any_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/api_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/descriptor_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/duration_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/empty_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/field_mask_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/source_context_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/struct_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/timestamp_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/type_pb.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/src/google/protobuf/wrappers_pb.rb)" lib/google/protobuf | ||
|
||
# Move all utf-8 files to ext/google/protobuf_c/third_party/utf8_range | ||
UTF8_DIR=ext/google/protobuf_c/third_party/utf8_range | ||
mkdir -p $UTF8_DIR | ||
cp "$(rlocation utf8_range/LICENSE)" $UTF8_DIR/LICENSE | ||
cp "$(rlocation utf8_range/naive.c)" $UTF8_DIR | ||
cp "$(rlocation utf8_range/range2-neon.c)" $UTF8_DIR | ||
cp "$(rlocation utf8_range/range2-sse.c)" $UTF8_DIR | ||
cp "$(rlocation utf8_range/utf8_range.h)" $UTF8_DIR | ||
|
||
# Move all source files to the correct location | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/convert.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/convert.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/defs.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/defs.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/extconf.rb)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/map.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/map.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/message.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/message.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/protobuf.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/protobuf.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/repeated_field.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/repeated_field.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/ruby-upb.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/ruby-upb.h)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c)" ext/google/protobuf_c | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf.rb)" lib/google | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/descriptor_dsl.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/message_exts.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/repeated_field.rb)" lib/google/protobuf | ||
cp "$(rlocation com_google_protobuf/ruby/lib/google/protobuf/well_known_types.rb)" lib/google/protobuf | ||
|
||
# Move gemspec file to current directory | ||
cp "$(rlocation com_google_protobuf/ruby/google.protobuf.gemspec)" . | ||
|
||
# Make all files global readable/writable/executable | ||
chmod -R 777 ./ | ||
|
||
# Build gem | ||
gem build google-protobuf.gemspec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a sanity check to the beginning to make sure these tests fail before installation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how to run in GHA expecting a failure? I can't find a good way of doing that (but can confirm that I have seen this fail when the gems were not correct).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
! bazel test <target>
will invert the result