Skip to content

Commit

Permalink
Add release.sh script that pushes crates.
Browse files Browse the repository at this point in the history
Temporarily rename the crates `staging-` while we're iterating on this.

This works for the protobuf and protobuf_codegen crates, but the protobuf_example crate fails to publish as cargo does not want build.rs to affect files outside of the OUT_DIR.

PiperOrigin-RevId: 702840478
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 4, 2024
1 parent 787eb48 commit 2ca39a2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
12 changes: 12 additions & 0 deletions rust/release_crates/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ sh_binary(
tags = ["manual"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)

sh_binary(
name = "release",
srcs = ["release.sh"],
data = [
"//rust/release_crates/protobuf:protobuf_crate",
"//rust/release_crates/protobuf_codegen:protobuf_codegen_crate",
"//rust/release_crates/protobuf_example:protobuf_example_crate",
],
tags = ["manual"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
2 changes: 1 addition & 1 deletion rust/release_crates/protobuf/Cargo-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://developers.google.com/open-source/licenses/bsd

[package]
name = "protobuf"
name = "staging-protobuf"
version = "{VERSION}"
edition = "2021" # The Rust edition (not to be confused with Protobuf Edition).
links = "libupb"
Expand Down
2 changes: 1 addition & 1 deletion rust/release_crates/protobuf_codegen/Cargo-template.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
edition = "2021" # The Rust edition (not to be confused with Protobuf Edition).
name = "protobuf-codegen"
name = "staging-protobuf-codegen"
readme = "README.md"
version = "{VERSION}"
description = "Code generator for Rust Protocol Buffers bindings"
Expand Down
6 changes: 3 additions & 3 deletions rust/release_crates/protobuf_example/Cargo-template.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "protobuf-example"
name = "staging-protobuf-example"
version = "{VERSION}"
edition = "2021"

[dependencies]
protobuf = { version = "{VERSION}", path = "../protobuf" }
protobuf = { version = "{VERSION}", path = "../protobuf", package = "staging-protobuf" }

[build-dependencies]
protobuf-codegen = { version = "{VERSION}", path = "../protobuf_codegen" }
protobuf-codegen = { version = "{VERSION}", path = "../protobuf_codegen", package = "staging-protobuf-codegen" }
69 changes: 69 additions & 0 deletions rust/release_crates/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# A script that publishes the protobuf crates to crates.io.

# --- 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 ---

read -p 'Enter cratesio auth token: ' AUTH_TOKEN

TMP_DIR=$(mktemp -d)
trap 'rm -rf -- "$TMP_DIR"' EXIT

CARGO_HOME=$TMP_DIR/cargo_home
mkdir $CARGO_HOME

CRATE_ROOT=$TMP_DIR/protobuf
mkdir $CRATE_ROOT

PROTOBUF_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf/protobuf_crate.tar)

echo "Expanding protobuf crate tar"
tar -xvf $PROTOBUF_TAR -C $CRATE_ROOT

CODEGEN_ROOT=$TMP_DIR/protobuf_codegen
mkdir $CODEGEN_ROOT

CODEGEN_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_codegen/protobuf_codegen_crate.tar)

echo "Expanding protbuf_codegen crate tar"
tar -xvf $CODEGEN_TAR -C $CODEGEN_ROOT

EXAMPLE_ROOT=$TMP_DIR/protobuf_example
mkdir $EXAMPLE_ROOT

EXAMPLE_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_example/protobuf_example_crate.tar)

echo "Expanding protobuf_example crate tar"
tar -xvf $EXAMPLE_TAR -C $EXAMPLE_ROOT

cd $CRATE_ROOT
CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish

cd $CODEGEN_ROOT
CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish

# The example crate cannot be published due to it having a build.rs that
# modifies files outside of the OUT_DIR.
#cd $EXAMPLE_ROOT
# CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish

0 comments on commit 2ca39a2

Please sign in to comment.