Skip to content

Commit 1e2436d

Browse files
committed
Merge commit '3d076e4db89ece0b0c30cbc59dc8aedc91e014e3' as 'third_party/googleapis'
2 parents f35584a + 3d076e4 commit 1e2436d

File tree

8,465 files changed

+2243128
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,465 files changed

+2243128
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.bcr/

third_party/googleapis/.bazeliskrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# See https://github.com/bazelbuild/bazelisk
2+
USE_BAZEL_VERSION=6.3.0

third_party/googleapis/.bazelrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# To make proto_library rules to include source info in the descriptor
2+
build --protocopt=--include_source_info
3+
build --protocopt=--experimental_allow_proto3_optional
4+
# New boringssl requires C++14
5+
build --repo_env=BAZEL_CXXOPTS="-std=c++14"
6+
7+
# This is to avoid JVM SIGBUS crashes on highly parallel builds,
8+
# see https://github.com/bazelbuild/bazel/issues/3236 for more details
9+
build --enable_platform_specific_config
10+
build:linux --sandbox_tmpfs_path=/tmp
11+
12+
# Do not create bazel-* symlinks in the workspace directory
13+
build:linux --experimental_convenience_symlinks=ignore
14+
test:linux --experimental_convenience_symlinks=ignore
15+
run:linux --experimental_convenience_symlinks=ignore
16+
17+
### Required Typecheck Performance Selection
18+
# passes an argument `--skipLibCheck` to *every* spawn of tsc
19+
# Bazel 6.4 or greater: 'common' means 'any command that supports this flag'
20+
common --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
21+
22+
# Between Bazel 6.0 and 6.3, you need all of this, to avoid discarding the analysis cache:
23+
build --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
24+
fetch --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
25+
query --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
26+
### END Required Typecheck Performance Selection
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# BCR Publisher
2+
3+
This document explains how to use the `publish-to-bcr.sh` script to publish `googleapis` to the Bazel Central Registry (BCR).
4+
5+
## Usage
6+
7+
The `publish-to-bcr.sh` script is used to automate the process of creating a new version of the `googleapis` module in the BCR.
8+
9+
### Arguments
10+
11+
The script accepts the following arguments:
12+
13+
* `-r`, `--ref`: **(Required)** The git ref (commit SHA, tag, or branch) of `googleapis` to be published.
14+
* `-t`, `--templates_ref`: The git ref to use for the templates. Defaults to the value of `--ref`.
15+
* `-o`, `--org`: The GitHub organization. Defaults to `googleapis`.
16+
* `-p`, `--protobuf_version`: The version of protobuf to use. Defaults to `21.7`.
17+
* `-b`, `--bcr_organization`: The GitHub organization for the Bazel Central Registry. Defaults to `bazelbuild`.
18+
* `-f`, `--bcr_folder`: The local path to a fork of the `bazel-central-registry` repository. If not provided, the script will clone it from `https://github.com/{bcr_organization}/bazel-central-registry`.
19+
20+
### Example
21+
22+
```bash
23+
./publish-to-bcr.sh --ref <your-commit-sha>
24+
```
25+
26+
### After running the script
27+
28+
After the script is executed, it will perform the following actions:
29+
30+
1. A new branch will be created in your local fork of `bazel-central-registry`.
31+
2. The script will prompt you to create a Pull Request. If you agree, a new PR will be created in the `bazelbuild/bazel-central-registry` repository.
32+
3. The script will automatically add a comment to the PR with the content: `@bazel-io skip_check unstable_url`. This is necessary to bypass the URL stability check.
33+
34+
Once the Pull Request has been created and all Continuous Integration (CI) checks are passing, a maintainer of the Bazel Central Registry will review and merge it.
35+
36+
#### Note on re-running the script
37+
38+
During development, you may need to run the script several times.
39+
Between each call, it's strongly recommended to reset your local fork of bazel-central-registry.
40+
For this, you can run the following command:
41+
42+
```bash
43+
pushd "${fork_location}"
44+
git reset --hard
45+
git checkout main
46+
git clean -d -f
47+
popd
48+
```
49+
50+
## Testing
51+
52+
To run the unit tests for the script, use the following command:
53+
54+
```bash
55+
./publish-to-bcr_test.sh
56+
```
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2025 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
set -e
19+
20+
readonly DEFAULT_REPO="googleapis"
21+
readonly DEFAULT_ORG="googleapis"
22+
readonly DEFAULT_PROTOBUF_VERSION="21.7"
23+
readonly DEFAULT_BCR_ORGANIZATION="bazelbuild"
24+
readonly SKIP_URL_CHECK_COMMENT='@bazel-io skip_check unstable_url'
25+
readonly SKIP_FLAG_CHECK_COMMENT='@bazel-io skip_check incompatible_flags'
26+
27+
# This function checks out the .bcr folder
28+
# to the specified commit SHA ($1) into the folder
29+
# specified in $2
30+
function checkout_definitions() {
31+
local target_folder="$1"
32+
local repo_url="$2"
33+
local templates_ref="$3"
34+
local definitions_ref="$4"
35+
36+
pushd "${target_folder}" > /dev/null
37+
git init
38+
git remote add origin "${repo_url}"
39+
git sparse-checkout init --cone
40+
git sparse-checkout set ".bcr"
41+
git fetch --depth 1 origin "${templates_ref}"
42+
git fetch --depth 2 origin "${definitions_ref}"
43+
git checkout "${definitions_ref}"
44+
git checkout "${templates_ref}" -- .bcr/ || (echo "--templates_ref does not contain the templates .bcr folder" && exit 1)
45+
popd > /dev/null
46+
}
47+
48+
function get_version() {
49+
local target_folder="$1"
50+
local ref="$2"
51+
pushd "${target_folder}" &> /dev/null
52+
local commit_sha=$(git rev-parse "${ref}")
53+
local commit_date=$(git log --format=%cd '--date=format:%Y%m%d' "${ref}~1..${ref}")
54+
popd &> /dev/null
55+
echo "0.0.0-${commit_date}-${commit_sha:0:8}"
56+
}
57+
58+
# Replaces values in all files containing the ".template." string in
59+
# their filenames
60+
function render_templates() {
61+
local target_folder="$1"
62+
local ref="$2"
63+
local protobuf_version="$3"
64+
local org="$4"
65+
66+
local template_files=$(find "${target_folder}" -type f -name '*.template.*')
67+
local version_string="$(get_version "${target_folder}" "${ref}")"
68+
for file in ${template_files}; do
69+
# here we render the values in each template file
70+
sed -i "s|{VERSION}|${ref}|" "${file}"
71+
sed -i "s|{GOOGLEAPIS_VERSION}|${version_string}|" "${file}"
72+
sed -i "s|{PROTOBUF_VERSION}|${protobuf_version}|" "${file}"
73+
sed -i "s|{OWNER}|${DEFAULT_ORG}|" "${file}"
74+
sed -i "s|{REPO}|${DEFAULT_REPO}|" "${file}"
75+
# we remove the .template string from the filename
76+
mv "${file}" $(sed 's|\.template||' <<< "${file}")
77+
done
78+
}
79+
80+
# Creates a .patch file to indicate the introduction of MODULE.bazel
81+
function create_module_patch() {
82+
target_googleapis_module="$1"
83+
filename="$(basename "${target_googleapis_module}")"
84+
destination="$2"
85+
diff -Nau /dev/null "${target_googleapis_module}" \
86+
| sed "1 s|.*|--- ${filename}|" \
87+
| sed "2 s|.*|+++ ${filename}|" > "${destination}"
88+
}
89+
90+
# append the version specified in $2 to the specified metadata file
91+
function append_version_to_metadata() {
92+
local version="$1"
93+
local metadata_file="$2"
94+
cat <<< $(jq ".versions += [\"${version}\"]" "${metadata_file}") > "${metadata_file}"
95+
}
96+
97+
function copy_module() {
98+
local bcr_module_folder="$1"
99+
local file_dest="${bcr_module_folder}/overlay/MODULE.bazel"
100+
local file_source="${bcr_module_folder}/MODULE.bazel"
101+
if [[ -f "${file_dest}" ]]; then
102+
rm "${file_dest}"
103+
fi
104+
105+
cp "${file_source}" "${file_dest}"
106+
}
107+
108+
function update_module_integrity() {
109+
bcr_folder="$1"
110+
version="$2"
111+
pushd "${bcr_folder}" > /dev/null
112+
bazelisk run -- //tools:update_integrity "googleapis" \
113+
|| exit 1
114+
popd > /dev/null
115+
}
116+
117+
function prepare_bcr_repo() {
118+
119+
local target_folder="$1"
120+
local bcr_folder="$2"
121+
local ref="$3"
122+
123+
local version=$(get_version "${target_folder}" "${ref}")
124+
pushd "${bcr_folder}"
125+
local googleapis_module_root="${bcr_folder}/modules/googleapis"
126+
local googleapis_target_module="${googleapis_module_root}/${version}"
127+
cp -r "${target_folder}" "${googleapis_target_module}"
128+
copy_module "${googleapis_target_module}"
129+
append_version_to_metadata "${version}" "${googleapis_module_root}/metadata.json"
130+
update_module_integrity "${bcr_folder}" "${version}"
131+
popd
132+
}
133+
134+
function validate_bcr_module() {
135+
local target_folder="$1"
136+
local bcr_folder="$2"
137+
local ref="$3"
138+
139+
version="$(get_version "${target_folder}" "${ref}")"
140+
pushd "${bcr_folder}" > /dev/null
141+
# we skip the url stability check because we don't have releases of googleapis/googleapis
142+
bazelisk run -- //tools:bcr_validation --skip_validation url_stability "--check=googleapis@${version}" \
143+
|| exit "$?"
144+
popd > /dev/null
145+
}
146+
147+
function create_pull_request() {
148+
local target_folder="$1"
149+
local bcr_folder="$2"
150+
local bcr_organization="$3"
151+
local ref="$4"
152+
153+
local version=$(get_version "${target_folder}" "${ref}")
154+
pushd "${bcr_folder}"
155+
# we create a branch with a random string in case of multiple local runs
156+
git checkout -b "add-googleapis-${version}-$(openssl rand -hex 3)"
157+
git add "modules"
158+
commit_message="Add googleapis ${version}"
159+
git commit -m "${commit_message}"
160+
git push origin
161+
pr_command="gh pr create --title \"${commit_message}\" --body \"\" --repo \"${bcr_organization}/bazel-central-registry\""
162+
read -p "The PR is ready to be raised. Do you wish to proceed? [y/N]: " -n 1 -r confirmation
163+
if [[ "${confirmation}" =~ ^[Yy]$ ]]
164+
then
165+
echo "Creating Pull Request"
166+
export pr_creation_output=$(bash -c "${pr_command}")
167+
pr_url=$(grep '/pull/' <<< "${pr_creation_output}")
168+
gh pr comment --body "${SKIP_URL_CHECK_COMMENT}" "${pr_url}"
169+
gh pr comment --body "${SKIP_FLAG_CHECK_COMMENT}" "${pr_url}"
170+
echo "Done! You can see the created PR in ${pr_url}"
171+
else
172+
echo "The branch is ready. You can create a PR by runing:"
173+
echo "cd $(pwd) && ${pr_command}"
174+
echo "Make sure to add a comment with the content: '${SKIP_URL_CHECK_COMMENT}'"
175+
echo "as well as a comment with the content '${SKIP_FLAG_CHECK_COMMENT}'"
176+
fi
177+
popd
178+
}
179+
180+
function confirm_tools() {
181+
for tool in gh bazelisk git jq; do
182+
if ! command -v "${tool}" &> /dev/null ; then
183+
echo "Tool ${tool} is not installed. Please install it and try again."
184+
exit 1
185+
fi
186+
done
187+
}
188+
189+
function main() {
190+
local ref="$1"
191+
local templates_ref="$2"
192+
local org="$3"
193+
local protobuf_version="$4"
194+
local bcr_organization="$5"
195+
local bcr_folder="$6"
196+
197+
local target_folder="$(mktemp -d)"
198+
readonly target_folder
199+
local template_folder="${target_folder}/.bcr/template"
200+
local repo_url="https://github.com/${org}/${DEFAULT_REPO}"
201+
confirm_tools
202+
checkout_definitions "${target_folder}" "${repo_url}" "${templates_ref}" "${ref}"
203+
render_templates "${template_folder}" "${ref}" "${protobuf_version}" "${org}"
204+
create_module_patch "${template_folder}/MODULE.bazel" "${template_folder}/patches/module_dot_bazel.patch"
205+
206+
if [[ -z "${bcr_folder}" ]] || [[ ! -d "${bcr_folder}" ]]; then
207+
bcr_folder="${target_folder}/bazel-central-registry"
208+
git clone "https://github.com/${bcr_organization}/bazel-central-registry" "${bcr_folder}"
209+
fi
210+
prepare_bcr_repo "${template_folder}" "${bcr_folder}" "${ref}"
211+
validate_bcr_module "${template_folder}" "${bcr_folder}" "${ref}"
212+
create_pull_request "${template_folder}" "${bcr_folder}" "${bcr_organization}" "${ref}"
213+
}
214+
215+
# parse input parameters
216+
while [[ $# -gt 0 ]]; do
217+
key="$1"
218+
case $key in
219+
-r|--ref)
220+
ref="$2"
221+
shift
222+
;;
223+
-t|--templates_ref)
224+
templates_ref="$2"
225+
shift
226+
;;
227+
-o|--org)
228+
org="$2"
229+
shift
230+
;;
231+
-p|--protobuf_version)
232+
protobuf_version="$2"
233+
shift
234+
;;
235+
-b|--bcr_organization)
236+
bcr_organization="$2"
237+
shift
238+
;;
239+
-f|--bcr_folder)
240+
bcr_folder="$2"
241+
shift
242+
;;
243+
-d|--dry_run)
244+
dry_run="$2"
245+
shift
246+
;;
247+
*)
248+
echo "Invalid option: [$1]"
249+
exit 1
250+
;;
251+
esac
252+
shift # past argument or value
253+
done
254+
255+
if [[ -z "${ref}" ]]; then
256+
echo "Missing option --ref"
257+
exit 0
258+
fi
259+
260+
if [[ -z "${templates_ref}" ]]; then
261+
echo "assuming templates_ref to be the HEAD of master"
262+
templates_ref="$(git ls-remote https://github.com/googleapis/googleapis HEAD | awk '{ print $1}')"
263+
fi
264+
265+
if [[ -z "${org}" ]]; then
266+
echo "Using default value for --org: ${DEFAULT_ORG}"
267+
org="${DEFAULT_ORG}"
268+
fi
269+
270+
if [[ -z "${protobuf_version}" ]]; then
271+
echo "Using default value for --protobuf_version: ${DEFAULT_PROTOBUF_VERSION}"
272+
protobuf_version="${DEFAULT_PROTOBUF_VERSION}"
273+
fi
274+
275+
if [[ -z "${bcr_organization}" ]]; then
276+
echo "Using default value for --bcr_organization: ${DEFAULT_BCR_ORGANIZATION}"
277+
bcr_organization="${DEFAULT_BCR_ORGANIZATION}"
278+
fi
279+
280+
if [[ -z "${bcr_folder}" ]] && [[ "${bcr_organization}" == "${DEFAULT_BCR_ORGANIZATION}" ]]; then
281+
echo "Cannot create branches in the ${DEFAULT_BCR_ORGANIZATION}/bazel-central-registry repo."
282+
echo "Please specify either a --bcr_folder or --bcr_organization we can push to."
283+
echo "(This needs a fork of the repo.)"
284+
exit 1
285+
fi
286+
287+
main "${ref}" "${templates_ref}" "${org}" "${protobuf_version}" "${bcr_organization}" "${bcr_folder}"

0 commit comments

Comments
 (0)