Skip to content

Commit 35e7755

Browse files
committed
chore(do not merge): demo of template files fix
1 parent 63037d3 commit 35e7755

File tree

6 files changed

+69
-18
lines changed

6 files changed

+69
-18
lines changed

.github/scripts/update_generation_config.sh

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ set -e
1515
function get_latest_released_version() {
1616
local group_id=$1
1717
local artifact_id=$2
18-
latest=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json" | jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' | sort -V | tail -n 1)
19-
echo "${latest}"
18+
json_content=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json")
19+
latest=$(jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' <<< "${json_content}" | sort -V | tail -n 1)
20+
if [[ -z "${latest}" ]]; then
21+
echo "The latest version of ${group_id}:${artifact_id} is empty."
22+
echo "The returned json from maven.org is invalid: ${json_content}"
23+
exit 1
24+
else
25+
echo "${latest}"
26+
fi
2027
}
2128

2229
# Update a key to a new value in the generation config.
@@ -28,11 +35,23 @@ function update_config() {
2835
sed -i -e "s/^${key_word}.*$/${key_word}: ${new_value}/" "${file}"
2936
}
3037

38+
# Update an action to a new version in GitHub action.
39+
function update_action() {
40+
local key_word=$1
41+
local new_value=$2
42+
local file=$3
43+
echo "Update ${key_word} to ${new_value} in ${file}"
44+
# use a different delimiter because the key_word contains "/".
45+
sed -i -e "s|${key_word}@v.*$|${key_word}@v${new_value}|" "${file}"
46+
}
47+
3148
# The parameters of this script is:
3249
# 1. base_branch, the base branch of the result pull request.
3350
# 2. repo, organization/repo-name, e.g., googleapis/google-cloud-java
3451
# 3. [optional] generation_config, the path to the generation configuration,
3552
# the default value is generation_config.yaml in the repository root.
53+
# 4. [optional] workflow, the library generation workflow file,
54+
# the default value is .github/workflows/hermetic_library_generation.yaml.
3655
while [[ $# -gt 0 ]]; do
3756
key="$1"
3857
case "${key}" in
@@ -48,6 +67,10 @@ case "${key}" in
4867
generation_config="$2"
4968
shift
5069
;;
70+
--workflow)
71+
workflow="$2"
72+
shift
73+
;;
5174
*)
5275
echo "Invalid option: [$1]"
5376
exit 1
@@ -71,21 +94,34 @@ if [ -z "${generation_config}" ]; then
7194
echo "Use default generation config: ${generation_config}"
7295
fi
7396

97+
if [ -z "${workflow}" ]; then
98+
workflow=".github/workflows/hermetic_library_generation.yaml"
99+
echo "Use default library generation workflow file: ${workflow}"
100+
fi
101+
74102
current_branch="generate-libraries-${base_branch}"
75103
title="chore: Update generation configuration at $(date)"
76104

77-
# try to find a open pull request associated with the branch
105+
git checkout "${base_branch}"
106+
# Try to find a open pull request associated with the branch
78107
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")
79-
# create a branch if there's no open pull request associated with the
108+
# Create a branch if there's no open pull request associated with the
80109
# branch; otherwise checkout the pull request.
81110
if [ -z "${pr_num}" ]; then
82111
git checkout -b "${current_branch}"
112+
# Push the current branch to remote so that we can
113+
# compare the commits later.
114+
git push -u origin "${current_branch}"
83115
else
84116
gh pr checkout "${pr_num}"
85117
fi
86118

119+
# Only allow fast-forward merging; exit with non-zero result if there's merging
120+
# conflict.
121+
git merge -m "chore: merge ${base_branch} into ${current_branch}" "${base_branch}"
122+
87123
mkdir tmp-googleapis
88-
# use partial clone because only commit history is needed.
124+
# Use partial clone because only commit history is needed.
89125
git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis
90126
pushd tmp-googleapis
91127
git pull
@@ -94,25 +130,43 @@ popd
94130
rm -rf tmp-googleapis
95131
update_config "googleapis_commitish" "${latest_commit}" "${generation_config}"
96132

97-
# update gapic-generator-java version to the latest
133+
# Update gapic-generator-java version to the latest
98134
latest_version=$(get_latest_released_version "com.google.api" "gapic-generator-java")
99135
update_config "gapic_generator_version" "${latest_version}" "${generation_config}"
100136

101-
# update libraries-bom version to the latest
137+
# Update composite action version to latest gapic-generator-java version
138+
update_action "googleapis/sdk-platform-java/.github/scripts" \
139+
"${latest_version}" \
140+
"${workflow}"
141+
142+
# Update libraries-bom version to the latest
102143
latest_version=$(get_latest_released_version "com.google.cloud" "libraries-bom")
103144
update_config "libraries_bom_version" "${latest_version}" "${generation_config}"
104145

105-
git add "${generation_config}"
146+
git add "${generation_config}" "${workflow}"
106147
changed_files=$(git diff --cached --name-only)
107148
if [[ "${changed_files}" == "" ]]; then
108149
echo "The latest generation config is not changed."
109150
echo "Skip committing to the pull request."
151+
else
152+
git commit -m "${title}"
153+
fi
154+
155+
# There are potentially at most two commits: merge commit and change commit.
156+
# We want to exit the script if no commit happens (otherwise this will be an
157+
# infinite loop).
158+
# `git cherry` is a way to find whether the local branch has commits that are
159+
# not in the remote branch.
160+
# If we find any such commit, push them to remote branch.
161+
unpushed_commit=$(git cherry -v "origin/${current_branch}" | wc -l)
162+
if [[ "${unpushed_commit}" -eq 0 ]]; then
163+
echo "No unpushed commits, exit"
110164
exit 0
111165
fi
112-
git commit -m "${title}"
166+
113167
if [ -z "${pr_num}" ]; then
114168
git remote add remote_repo https://cloud-java-bot:"${GH_TOKEN}@github.com/${repo}.git"
115-
git fetch -q --unshallow remote_repo
169+
git fetch -q remote_repo
116170
git push -f remote_repo "${current_branch}"
117171
gh pr create --title "${title}" --head "${current_branch}" --body "${title}" --base "${base_branch}"
118172
else

.github/workflows/renovate_config_check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Node.js
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: '22'
19+
node-version: '20'
2020

2121
- name: Install Renovate and Config Validator
2222
run: |

.github/workflows/samples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: actions/setup-java@v4
2525
with:
2626
distribution: temurin
27-
java-version: 11
27+
java-version: 8
2828
- name: Run checkstyle
2929
run: mvn -P lint --quiet --batch-mode checkstyle:check
3030
working-directory: samples/snippets

.github/workflows/update_generation_config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v4
3030
with:
31+
fetch-depth: 0
3132
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
3233
- name: Update params in generation config to latest
3334
shell: bash
@@ -36,7 +37,8 @@ jobs:
3637
[ -z "$(git config user.email)" ] && git config --global user.email "[email protected]"
3738
[ -z "$(git config user.name)" ] && git config --global user.name "cloud-java-bot"
3839
bash .github/scripts/update_generation_config.sh \
39-
--base_branch "${base_branch}"\
40+
--base_branch "${base_branch}" \
4041
--repo ${{ github.repository }}
4142
env:
4243
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
44+

.kokoro/build.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTI
4242
export GOOGLE_APPLICATION_CREDENTIALS=$(realpath ${KOKORO_GFILE_DIR}/${GOOGLE_APPLICATION_CREDENTIALS})
4343
fi
4444

45-
export TEST_UNIVERSE_DOMAIN_CREDENTIAL=$(realpath ${KOKORO_GFILE_DIR}/secret_manager/client-library-test-universe-domain-credential)
46-
export TEST_UNIVERSE_DOMAIN=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-domain)
47-
export TEST_UNIVERSE_PROJECT_ID=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-project-id)
48-
export TEST_UNIVERSE_LOCATION=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-storage-location)
49-
5045
RETURN_CODE=0
5146
set +e
5247

.kokoro/trampoline.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)