Skip to content

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

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions .github/scripts/hermetic_library_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.


# 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}."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually mentioned Dockerfile change in the message but it was not achieved before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dockerfile is not part of generation config, so the previous docker run won't generate anything if Dockerfile is the only change.

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.
Expand Down
Loading