-
Notifications
You must be signed in to change notification settings - Fork 66
chore: re-generate when config or Dockerfile is changed #3146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
262fe45
a10c1fd
1e4b8c9
8ba24f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,22 +64,17 @@ fi | |
|
||
image_tag=local | ||
workspace_name="/workspace" | ||
baseline_generation_config="baseline_generation_config.yaml" | ||
docker_file="library_generation.Dockerfile" | ||
message="chore: generate libraries at $(date)" | ||
|
||
git checkout "${target_branch}" | ||
git checkout "${current_branch}" | ||
# if the last commit doesn't contain changes to generation configuration, | ||
# do not generate again as the result will be the same. | ||
# if the last commit doesn't contain changes to generation configuration | ||
# or Dockerfile, do not generate again as the result will be the same. | ||
change_of_last_commit="$(git diff-tree --no-commit-id --name-only HEAD~1..HEAD -r)" | ||
if [[ ! ("${change_of_last_commit}" == *"${generation_config}"* || "${change_of_last_commit}" == *"${docker_file}"*) ]]; then | ||
echo "The last commit doesn't contain any changes to the generation_config.yaml or Dockerfile, skipping the whole generation process." || true | ||
exit 0 | ||
fi | ||
# copy generation configuration from target branch to current branch. | ||
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}" | ||
config_diff=$(diff "${generation_config}" "${baseline_generation_config}" || true) | ||
|
||
generator_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl gapic-generator-java) | ||
echo "Local generator version: ${generator_version}" | ||
|
@@ -99,22 +94,18 @@ docker run \ | |
-v "$(pwd):${workspace_name}" \ | ||
-v "$HOME"/.m2:/home/.m2 \ | ||
-e GENERATOR_VERSION="${generator_version}" \ | ||
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \ | ||
--baseline-generation-config-path="${workspace_name}/${baseline_generation_config}" \ | ||
--current-generation-config-path="${workspace_name}/${generation_config}" | ||
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" | ||
|
||
# commit the change to the pull request. | ||
rm -rdf output googleapis "${baseline_generation_config}" | ||
rm -rdf output googleapis | ||
git add --all -- ':!pr_description.txt' | ||
changed_files=$(git diff --cached --name-only) | ||
if [[ "${changed_files}" == "" ]]; then | ||
echo "There is no generated code change with the generation config and Dockerfile change ${config_diff}." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually mentioned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dockerfile is not part of generation config, so the previous |
||
echo "There is no generated code change." | ||
echo "Skip committing to the pull request." | ||
exit 0 | ||
fi | ||
|
||
echo "Configuration diff:" | ||
echo "${config_diff}" | ||
git commit -m "${message}" | ||
git push | ||
# set pr body if pr_description.txt is generated. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the commit history going to be populated correctly if we don't pass the baseline generation config into the image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the commit history has to go through baseline/current config comparison.
However, in this repo, we don't have config changes other than googleapis commit since everything else is baked in the image.