Skip to content

Commit 6c93439

Browse files
Merge branch 'main' into renovate/watchdog-4.x
2 parents 3347c6b + 1638f99 commit 6c93439

23 files changed

+391
-160
lines changed

.cloudbuild/graalvm/cloudbuild.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ steps:
2222
args: [
2323
"build",
2424
"-t", "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:${_SHARED_DEPENDENCIES_VERSION}",
25+
"-t", "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:infrastructure-public-image-$SHORT_SHA",
2526
"--file", "graalvm_a.Dockerfile",
2627
"--build-arg", "JAVA_SHARED_CONFIG_VERSION=$_JAVA_SHARED_CONFIG_VERSION",
2728
"."
@@ -35,6 +36,7 @@ steps:
3536
args: [
3637
"build",
3738
"-t", "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:${_SHARED_DEPENDENCIES_VERSION}",
39+
"-t", "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:infrastructure-public-image-$SHORT_SHA",
3840
"--file", "graalvm_b.Dockerfile",
3941
"--build-arg", "JAVA_SHARED_CONFIG_VERSION=$_JAVA_SHARED_CONFIG_VERSION",
4042
"."
@@ -47,3 +49,5 @@ steps:
4749
images:
4850
- gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:${_SHARED_DEPENDENCIES_VERSION}
4951
- gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:${_SHARED_DEPENDENCIES_VERSION}
52+
- gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:infrastructure-public-image-$SHORT_SHA
53+
- gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:infrastructure-public-image-$SHORT_SHA

.github/release-please.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ bumpMinorPreMajor: true
33
handleGHRelease: true
44
primaryBranch: main
55
manifest: true
6-
extraFiles: ["WORKSPACE", ".cloudbuild/graalvm/cloudbuild.yaml", ".cloudbuild/graalvm/cloudbuild-test-a.yaml", ".cloudbuild/graalvm/cloudbuild-test-b.yaml", ".cloudbuild/library_generation/cloudbuild-library-generation-release.yaml" ]
6+
extraFiles: ["WORKSPACE", ".cloudbuild/graalvm/cloudbuild.yaml", ".cloudbuild/graalvm/cloudbuild-test-a.yaml", ".cloudbuild/graalvm/cloudbuild-test-b.yaml", ".cloudbuild/library_generation/cloudbuild-library-generation-release.yaml", "generation_config.yaml"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
set -e
3+
# This script should be run at the root of the repository.
4+
# This script is used to, when a pull request changes the generation
5+
# configuration (generation_config.yaml by default):
6+
# 1. Find whether the last commit in this pull request contains changes to
7+
# the generation configuration and exit early if it doesn't have such a change
8+
# since the generation result would be the same.
9+
# 2. Compare generation configurations in the current branch (with which the
10+
# pull request associated) and target branch (into which the pull request is
11+
# merged);
12+
# 3. Generate changed libraries using library_generation image;
13+
# 4. Commit the changes to the pull request, if any.
14+
# 5. Edit the PR body with generated pull request description, if applicable.
15+
16+
# The following commands need to be installed before running the script:
17+
# 1. git
18+
# 2. gh
19+
# 3. docker
20+
21+
# The parameters of this script is:
22+
# 1. target_branch, the branch into which the pull request is merged.
23+
# 2. current_branch, the branch with which the pull request is associated.
24+
# 3. image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
25+
# 3. [optional] generation_config, the path to the generation configuration,
26+
# the default value is generation_config.yaml in the repository root.
27+
while [[ $# -gt 0 ]]; do
28+
key="$1"
29+
case "${key}" in
30+
--target_branch)
31+
target_branch="$2"
32+
shift
33+
;;
34+
--current_branch)
35+
current_branch="$2"
36+
shift
37+
;;
38+
--image_tag)
39+
image_tag="$2"
40+
shift
41+
;;
42+
--generation_config)
43+
generation_config="$2"
44+
shift
45+
;;
46+
*)
47+
echo "Invalid option: [$1]"
48+
exit 1
49+
;;
50+
esac
51+
shift
52+
done
53+
54+
if [ -z "${target_branch}" ]; then
55+
echo "missing required argument --target_branch"
56+
exit 1
57+
fi
58+
59+
if [ -z "${current_branch}" ]; then
60+
echo "missing required argument --current_branch"
61+
exit 1
62+
fi
63+
64+
if [ -z "${image_tag}" ]; then
65+
echo "missing required argument --image_tag"
66+
exit 1
67+
fi
68+
69+
if [ -z "${generation_config}" ]; then
70+
generation_config=generation_config.yaml
71+
echo "Use default generation config: ${generation_config}"
72+
fi
73+
74+
workspace_name="/workspace"
75+
baseline_generation_config="baseline_generation_config.yaml"
76+
message="chore: generate libraries at $(date)"
77+
78+
git checkout "${target_branch}"
79+
git checkout "${current_branch}"
80+
# if the last commit doesn't contain changes to generation configuration,
81+
# do not generate again as the result will be the same.
82+
change_of_last_commit="$(git diff-tree --no-commit-id --name-only HEAD~1..HEAD -r)"
83+
if [[ ! ("${change_of_last_commit}" == *"${generation_config}"*) ]]; then
84+
echo "The last commit doesn't contain any changes to the generation_config.yaml, skipping the whole generation process." || true
85+
exit 0
86+
fi
87+
# copy generation configuration from target branch to current branch.
88+
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}"
89+
config_diff=$(diff "${generation_config}" "${baseline_generation_config}" || true)
90+
91+
# run hermetic code generation docker image.
92+
docker run \
93+
--rm \
94+
-u "$(id -u):$(id -g)" \
95+
-v "$(pwd):${workspace_name}" \
96+
-v "$HOME"/.m2:/home/.m2 \
97+
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \
98+
--baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \
99+
--current-generation-config-path="${workspace_name}/${generation_config}"
100+
101+
# commit the change to the pull request.
102+
rm -rdf output googleapis "${baseline_generation_config}"
103+
git add --all -- ':!pr_description.txt'
104+
changed_files=$(git diff --cached --name-only)
105+
if [[ "${changed_files}" == "" ]]; then
106+
echo "There is no generated code change with the generation config change ${config_diff}."
107+
echo "Skip committing to the pull request."
108+
exit 0
109+
fi
110+
111+
echo "Configuration diff:"
112+
echo "${config_diff}"
113+
git commit -m "${message}"
114+
git push
115+
# set pr body if pr_description.txt is generated.
116+
if [[ -f "pr_description.txt" ]]; then
117+
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
118+
gh pr edit "${pr_num}" --body "$(cat pr_description.txt)"
119+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
set -e
3+
# This script should be run at the root of the repository.
4+
# This script is used to update googleapis commit to latest in generation
5+
# configuration at the time of running and create a pull request.
6+
7+
# The following commands need to be installed before running the script:
8+
# 1. git
9+
# 2. gh
10+
11+
# The parameters of this script is:
12+
# 1. base_branch, the base branch of the result pull request.
13+
# 2. repo, organization/repo-name, e.g., googleapis/google-cloud-java
14+
# 3. [optional] generation_config, the path to the generation configuration,
15+
# the default value is generation_config.yaml in the repository root.
16+
while [[ $# -gt 0 ]]; do
17+
key="$1"
18+
case "${key}" in
19+
--base_branch)
20+
base_branch="$2"
21+
shift
22+
;;
23+
--repo)
24+
repo="$2"
25+
shift
26+
;;
27+
--generation_config)
28+
generation_config="$2"
29+
shift
30+
;;
31+
*)
32+
echo "Invalid option: [$1]"
33+
exit 1
34+
;;
35+
esac
36+
shift
37+
done
38+
39+
if [ -z "${base_branch}" ]; then
40+
echo "missing required argument --base_branch"
41+
exit 1
42+
fi
43+
44+
if [ -z "${repo}" ]; then
45+
echo "missing required argument --repo"
46+
exit 1
47+
fi
48+
49+
if [ -z "${generation_config}" ]; then
50+
generation_config="generation_config.yaml"
51+
echo "Use default generation config: ${generation_config}"
52+
fi
53+
54+
current_branch="generate-libraries-${base_branch}"
55+
title="chore: update googleapis commit at $(date)"
56+
57+
# try to find a open pull request associated with the branch
58+
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
59+
# create a branch if there's no open pull request associated with the
60+
# branch; otherwise checkout the pull request.
61+
if [ -z "${pr_num}" ]; then
62+
git checkout -b "${current_branch}"
63+
else
64+
gh pr checkout "${pr_num}"
65+
fi
66+
67+
mkdir tmp-googleapis
68+
# use partial clone because only commit history is needed.
69+
git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis
70+
pushd tmp-googleapis
71+
git pull
72+
latest_commit=$(git rev-parse HEAD)
73+
popd
74+
rm -rf tmp-googleapis
75+
sed -i -e "s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit}/" "${generation_config}"
76+
77+
git add "${generation_config}"
78+
changed_files=$(git diff --cached --name-only)
79+
if [[ "${changed_files}" == "" ]]; then
80+
echo "The latest googleapis commit is not changed."
81+
echo "Skip committing to the pull request."
82+
exit 0
83+
fi
84+
git commit -m "${title}"
85+
if [ -z "${pr_num}" ]; then
86+
git remote add remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${repo}.git"
87+
git fetch -q --unshallow remote_repo
88+
git push -f remote_repo "${current_branch}"
89+
gh pr create --title "${title}" --head "${current_branch}" --body "${title}" --base "${base_branch}"
90+
else
91+
git push
92+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# GitHub action job to test core java library features on
15+
# downstream client libraries before they are released.
16+
name: Hermetic library generation upon generation config change through pull requests
17+
on:
18+
pull_request:
19+
20+
jobs:
21+
library_generation:
22+
# skip pull requests come from a forked repository
23+
if: github.event.pull_request.head.repo.full_name == github.repository
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
30+
- name: Build image
31+
shell: bash
32+
run: |
33+
docker build \
34+
-f .cloudbuild/library_generation/library_generation.Dockerfile \
35+
-t gcr.io/cloud-devrel-public-resources/java-library-generation:latest \
36+
.
37+
- name: Install gapic-generator-java-pom-parent
38+
shell: bash
39+
run: |
40+
mvn clean install -pl gapic-generator-java-pom-parent
41+
- name: Generate changed libraries
42+
shell: bash
43+
run: |
44+
set -x
45+
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
46+
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
47+
bash .github/scripts/hermetic_library_generation.sh \
48+
--target_branch "${base_ref}" \
49+
--current_branch "${head_ref}" \
50+
--image_tag latest
51+
env:
52+
base_ref: ${{ github.base_ref }}
53+
head_ref: ${{ github.head_ref }}
54+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# GitHub action job to test core java library features on
15+
# downstream client libraries before they are released.
16+
name: Update googleapis commit
17+
on:
18+
schedule:
19+
- cron: '0 2 * * *'
20+
workflow_dispatch:
21+
22+
jobs:
23+
update-googleapis-commit:
24+
runs-on: ubuntu-22.04
25+
env:
26+
# the branch into which the pull request is merged
27+
base_branch: main
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
32+
- name: Update googleapis commit to latest
33+
shell: bash
34+
run: |
35+
set -x
36+
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
37+
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
38+
bash .github/scripts/update_googleapis_commit.sh \
39+
--base_branch "${base_branch}"\
40+
--repo ${{ github.repository }}
41+
env:
42+
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

0 commit comments

Comments
 (0)