Skip to content

Commit f46d286

Browse files
committed
update gen script
1 parent 52a99dd commit f46d286

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

.github/scripts/hermetic_library_generation.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,24 @@ message="chore: generate libraries at $(date)"
6767

6868
git checkout "${target_branch}"
6969
git checkout "${current_branch}"
70-
# if the last commit doesn't contain changes to generation configuration,
71-
# do not generate again as the result will be the same.
72-
change_of_last_commit="$(git diff-tree --no-commit-id --name-only HEAD~1..HEAD -r)"
73-
if [[ ! ("${change_of_last_commit}" == *"${generation_config}"*) ]]; then
74-
echo "The last commit doesn't contain any changes to the generation_config.yaml, skipping the whole generation process." || true
75-
exit 0
76-
fi
70+
7771
# copy generation configuration from target branch to current branch.
7872
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}"
79-
config_diff=$(diff "${generation_config}" "${baseline_generation_config}" || true)
8073

8174
# parse image tag from the generation configuration.
8275
image_tag=$(grep "gapic_generator_version" "${generation_config}" | cut -d ':' -f 2 | xargs)
8376

77+
repo_root_dir=$(pwd)
78+
mkdir -p "${repo_root_dir}/output"
79+
# download api definitions from googleapis repository
80+
googleapis_commitish=$(grep googleapis_commitish "${generation_config}" | cut -d ":" -f 2 | xargs)
81+
api_def_dir=$(mktemp -d)
82+
git clone https://github.com/googleapis/googleapis.git "${api_def_dir}"
83+
pushd "${api_def_dir}"
84+
git checkout "${googleapis_commitish}"
85+
cp -r google/ grafeas/ "${repo_root_dir}/output"
86+
popd
87+
8488
# run hermetic code generation docker image.
8589
docker run \
8690
--rm \
@@ -90,26 +94,21 @@ docker run \
9094
--baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \
9195
--current-generation-config-path="${workspace_name}/${generation_config}"
9296

97+
# remove api definitions after generation
98+
rm -rf "${api_def_dir}"
9399

94100
# commit the change to the pull request.
95-
if [[ $(basename $(pwd)) == "google-cloud-java" ]]; then
96-
git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt
97-
else
98-
# The image leaves intermediate folders and files it works with. Here we remove them
99-
rm -rdf output googleapis "${baseline_generation_config}"
100-
git add --all -- ':!pr_description.txt'
101-
fi
101+
rm -rdf output googleapis "${baseline_generation_config}"
102+
git add --all -- ':!pr_description.txt' ':!hermetic_library_generation.sh'
102103
changed_files=$(git diff --cached --name-only)
103-
if [[ "${changed_files}" == "" ]]; then
104-
echo "There is no generated code change with the generation config change ${config_diff}."
105-
echo "Skip committing to the pull request."
106-
exit 0
104+
if [[ "${changed_files}" != "" ]]; then
105+
echo "Commit changes..."
106+
git commit -m "${message}"
107+
git push
108+
else
109+
echo "There is no generated code change, skip commit."
107110
fi
108111

109-
echo "Configuration diff:"
110-
echo "${config_diff}"
111-
git commit -m "${message}"
112-
git push
113112
# set pr body if pr_description.txt is generated.
114113
if [[ -f "pr_description.txt" ]]; then
115114
pr_num=$(gh pr list -s open -H "${current_branch}" -q . --json number | jq ".[] | .number")

0 commit comments

Comments
 (0)