Skip to content

Commit 74f20a2

Browse files
authored
chore: initiate library generation if Dockerfile is changed (#2878)
In this PR: - Initiate generation process if the Dockerfile is changed. - Move `docker build` and `mvn install` in shell script to speed up the workflow run if no changes in the `generation_config.yaml` and `Dockerfile`. Example run: https://github.com/JoeWang1127/sdk-platform-java/actions/runs/9473714657/job/26101875644?pr=8
1 parent dd27fdf commit 74f20a2

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

.github/scripts/hermetic_library_generation.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
set -e
33
# This script should be run at the root of the repository.
44
# This script is used to, when a pull request changes the generation
5-
# configuration (generation_config.yaml by default):
5+
# configuration (generation_config.yaml by default) or Dockerfile:
66
# 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.
7+
# the generation configuration and Dockerfile and exit early if it doesn't have
8+
# such a change since the generation result would be the same.
99
# 2. Compare generation configurations in the current branch (with which the
1010
# pull request associated) and target branch (into which the pull request is
1111
# merged);
@@ -17,6 +17,7 @@ set -e
1717
# 1. git
1818
# 2. gh
1919
# 3. docker
20+
# 4. mvn
2021

2122
# The parameters of this script is:
2223
# 1. target_branch, the branch into which the pull request is merged.
@@ -73,21 +74,30 @@ fi
7374

7475
workspace_name="/workspace"
7576
baseline_generation_config="baseline_generation_config.yaml"
77+
docker_file="library_generation.Dockerfile"
7678
message="chore: generate libraries at $(date)"
7779

7880
git checkout "${target_branch}"
7981
git checkout "${current_branch}"
8082
# if the last commit doesn't contain changes to generation configuration,
8183
# do not generate again as the result will be the same.
8284
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+
if [[ ! ("${change_of_last_commit}" == *"${generation_config}"* || "${change_of_last_commit}" == *"${docker_file}"*) ]]; then
86+
echo "The last commit doesn't contain any changes to the generation_config.yaml or Dockerfile, skipping the whole generation process." || true
8587
exit 0
8688
fi
8789
# copy generation configuration from target branch to current branch.
8890
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}"
8991
config_diff=$(diff "${generation_config}" "${baseline_generation_config}" || true)
9092

93+
# install generator locally since we're using a SNAPSHOT version.
94+
mvn -V -B -ntp clean install -DskipTests
95+
96+
# build image locally since we want to include latest change.
97+
docker build \
98+
-f .cloudbuild/library_generation/library_generation.Dockerfile \
99+
-t gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \
100+
.
91101
# run hermetic code generation docker image.
92102
docker run \
93103
--rm \
@@ -103,7 +113,7 @@ rm -rdf output googleapis "${baseline_generation_config}"
103113
git add --all -- ':!pr_description.txt'
104114
changed_files=$(git diff --cached --name-only)
105115
if [[ "${changed_files}" == "" ]]; then
106-
echo "There is no generated code change with the generation config change ${config_diff}."
116+
echo "There is no generated code change with the generation config and Dockerfile change ${config_diff}."
107117
echo "Skip committing to the pull request."
108118
exit 0
109119
fi

.github/workflows/hermetic_library_generation.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ jobs:
2727
with:
2828
fetch-depth: 0
2929
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 all modules
38-
shell: bash
39-
run: |
40-
mvn -V -B -ntp clean install -DskipTests
4130
- name: Generate changed libraries
4231
shell: bash
4332
run: |

0 commit comments

Comments
 (0)