Skip to content

Commit 7d6d66a

Browse files
authored
feat: Move release note generation to a sub module (#3299)
In this PR: - Separate projects to three modules: common, library_generation and release_note_generation - Add `generate_release_note.py` to separate PR description generation from `entrypoint.py`. - Only install common and library_generation module in image. - Remove PR description comparison in integration test. Example generation workflow in downstream library: https://github.com/googleapis/java-bigtable/actions/runs/11442581326/job/31833887512 Note that `release_note_generation` module still depends on `library_generation` module because we didn't separate config change functions into `common` module. This will be in a follow up PR.
1 parent d5e74d9 commit 7d6d66a

File tree

251 files changed

+961
-824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+961
-824
lines changed

.cloudbuild/library_generation/library_generation.Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ RUN apt-get update && apt-get install -y \
4545
&& apt-get clean
4646

4747
# copy source code
48-
COPY library_generation /src
48+
COPY hermetic_build/common /src/common
49+
COPY hermetic_build/library_generation /src/library_generation
4950

5051
# install protoc
5152
WORKDIR /protoc
52-
RUN source /src/utils/utilities.sh \
53+
RUN source /src/library_generation/utils/utilities.sh \
5354
&& download_protoc "${PROTOC_VERSION}" "${OS_ARCHITECTURE}"
5455
# we indicate protoc is available in the container via env vars
5556
ENV DOCKER_PROTOC_LOCATION=/protoc
5657
ENV DOCKER_PROTOC_VERSION="${PROTOC_VERSION}"
5758

5859
# install grpc
5960
WORKDIR /grpc
60-
RUN source /src/utils/utilities.sh \
61+
RUN source /src/library_generation/utils/utilities.sh \
6162
&& download_grpc_plugin "${GRPC_VERSION}" "${OS_ARCHITECTURE}"
6263
# similar to protoc, we indicate grpc is available in the container via env vars
6364
ENV DOCKER_GRPC_LOCATION="/grpc/protoc-gen-grpc-java-${GRPC_VERSION}-${OS_ARCHITECTURE}.exe"
@@ -71,16 +72,18 @@ ENV DOCKER_GRPC_VERSION="${GRPC_VERSION}"
7172
COPY --from=ggj-build "/sdk-platform-java/gapic-generator-java.jar" "${HOME}/.library_generation/gapic-generator-java.jar"
7273
RUN chmod 755 "${HOME}/.library_generation/gapic-generator-java.jar"
7374

74-
# use python 3.11 (the base image has several python versions; here we define the default one)
75+
# use python 3.12 (the base image has several python versions; here we define the default one)
7576
RUN rm $(which python3)
76-
RUN ln -s $(which python3.11) /usr/local/bin/python
77-
RUN ln -s $(which python3.11) /usr/local/bin/python3
77+
RUN ln -s $(which python3.12) /usr/local/bin/python
78+
RUN ln -s $(which python3.12) /usr/local/bin/python3
7879
RUN python -m pip install --upgrade pip
7980

8081
# install main scripts as a python package
81-
WORKDIR /src
82-
RUN python -m pip install -r requirements.txt
83-
RUN python -m pip install .
82+
WORKDIR /
83+
RUN python -m pip install --require-hashes -r src/common/requirements.txt
84+
RUN python -m pip install src/common
85+
RUN python -m pip install --require-hashes -r src/library_generation/requirements.txt
86+
RUN python -m pip install src/library_generation
8487

8588
# Install nvm with node and npm
8689
ENV NODE_VERSION 20.12.0
@@ -120,4 +123,4 @@ RUN chmod -R a+rw /home
120123
RUN chmod -R a+rx /home/.nvm
121124

122125
WORKDIR /workspace
123-
ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ]
126+
ENTRYPOINT [ "python", "/src/library_generation/cli/entry_point.py", "generate" ]

.github/scripts/action.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,33 @@ inputs:
3737
runs:
3838
using: "composite"
3939
steps:
40+
- uses: actions/setup-python@v5
41+
with:
42+
python-version: 3.12
43+
- name: Copy python script
44+
shell: bash
45+
run: |
46+
set -x
47+
# repository root
48+
cd ${{ github.action_path }}/../../
49+
rsync -rv \
50+
--exclude=tests \
51+
hermetic_build "${GITHUB_WORKSPACE}"
4052
- name: Copy shell script
4153
shell: bash
4254
run: |
4355
cd ${{ github.action_path }}
44-
cp hermetic_library_generation.sh $GITHUB_WORKSPACE
56+
cp hermetic_library_generation.sh "${GITHUB_WORKSPACE}"
57+
- name: Install python packages
58+
shell: bash
59+
run: |
60+
cd "${GITHUB_WORKSPACE}"
61+
pip install --require-hashes -r hermetic_build/common/requirements.txt
62+
pip install hermetic_build/common
63+
pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
64+
pip install hermetic_build/library_generation
65+
pip install --require-hashes -r hermetic_build/release_note_generation/requirements.txt
66+
pip install hermetic_build/release_note_generation
4567
- name: Generate changed libraries
4668
shell: bash
4769
run: |

.github/scripts/hermetic_library_generation.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ docker run \
106106
--current-generation-config-path="${workspace_name}/${generation_config}" \
107107
--api-definitions-path="${workspace_name}/googleapis"
108108

109+
python hermetic_build/release_note_generation/cli/generate_release_note.py generate \
110+
--baseline-generation-config-path="${baseline_generation_config}" \
111+
--current-generation-config-path="${generation_config}"
112+
109113
# remove api definitions after generation
110114
rm -rf "${api_def_dir}"
111115

112116
# commit the change to the pull request.
113117
rm -rdf output googleapis "${baseline_generation_config}"
114-
git add --all -- ':!pr_description.txt' ':!hermetic_library_generation.sh'
118+
git add --all -- ':!pr_description.txt' ':!hermetic_library_generation.sh' ':!hermetic_build'
115119
changed_files=$(git diff --cached --name-only)
116120
if [[ "${changed_files}" != "" ]]; then
117121
echo "Commit changes..."

.github/workflows/verify_library_generation.yaml

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
git checkout -b "${head_ref}" fork/${head_ref}
2828
changed_directories="$(git diff --name-only "fork/${head_ref}" "origin/${base_ref}")"
2929
fi
30-
if [[ ${changed_directories} =~ "library_generation/" ]]; then
30+
if [[ ${changed_directories} =~ "hermetic_build/" ]]; then
3131
echo "should_run=true" >> $GITHUB_OUTPUT
3232
else
3333
echo "should_run=false" >> $GITHUB_OUTPUT
@@ -46,32 +46,21 @@ jobs:
4646
- uses: actions/checkout@v4
4747
- uses: actions/setup-python@v5
4848
with:
49-
python-version: 3.11
50-
- name: install pyenv
49+
python-version: 3.12
50+
- name: install python modules and dependencies
5151
shell: bash
5252
run: |
5353
set -ex
54-
curl https://pyenv.run | bash
55-
# setup environment
56-
export PYENV_ROOT="$HOME/.pyenv"
57-
export PATH="$PYENV_ROOT/bin:$PATH"
58-
echo "PYENV_ROOT=${PYENV_ROOT}" >> $GITHUB_ENV
59-
echo "PATH=${PATH}" >> $GITHUB_ENV
60-
61-
set +ex
62-
- name: install python dependencies
63-
shell: bash
64-
run: |
65-
set -ex
66-
pushd library_generation
67-
pip install -r requirements.txt
68-
pip install .
69-
popd
54+
pip install --upgrade pip
55+
pip install --require-hashes -r hermetic_build/common/requirements.txt
56+
pip install hermetic_build/common
57+
pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
58+
pip install hermetic_build/library_generation
7059
- name: Run integration tests
7160
shell: bash
7261
run: |
7362
set -x
74-
python -m unittest library_generation/test/integration_tests.py
63+
python -m unittest hermetic_build/library_generation/tests/integration_tests.py
7564
library-generation-unit-tests:
7665
runs-on: ubuntu-22.04
7766
needs: should-run-library-generation-tests
@@ -80,23 +69,26 @@ jobs:
8069
- uses: actions/checkout@v4
8170
- uses: actions/setup-python@v5
8271
with:
83-
python-version: 3.11
84-
- name: install python dependencies
72+
python-version: 3.12
73+
- name: install python modules and dependencies
8574
shell: bash
8675
run: |
8776
set -ex
88-
pushd library_generation
89-
pip install -r requirements.txt
90-
pip install .
91-
popd
77+
pip install --upgrade pip
78+
pip install --require-hashes -r hermetic_build/common/requirements.txt
79+
pip install hermetic_build/common
80+
pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
81+
pip install hermetic_build/library_generation
82+
pip install --require-hashes -r hermetic_build/release_note_generation/requirements.txt
83+
pip install hermetic_build/release_note_generation
9284
- name: Run shell unit tests
9385
run: |
9486
set -x
95-
library_generation/test/generate_library_unit_tests.sh
87+
hermetic_build/library_generation/tests/generate_library_unit_tests.sh
9688
- name: Run python unit tests
9789
run: |
9890
set -x
99-
python -m unittest discover -s library_generation/test/ -p "*unit_tests.py"
91+
python -m unittest discover -s hermetic_build -p "*unit_tests.py"
10092
library-generation-lint-shell:
10193
runs-on: ubuntu-22.04
10294
needs: should-run-library-generation-tests
@@ -106,7 +98,7 @@ jobs:
10698
- name: Run ShellCheck
10799
uses: ludeeus/[email protected]
108100
with:
109-
scandir: 'library_generation'
101+
scandir: 'hermetic_build'
110102
format: tty
111103
severity: error
112104
library-generation-lint-python:
@@ -115,16 +107,23 @@ jobs:
115107
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
116108
steps:
117109
- uses: actions/checkout@v4
110+
- uses: actions/setup-python@v5
111+
with:
112+
python-version: 3.12
118113
- name: install python dependencies
119114
shell: bash
120115
run: |
121116
set -ex
122-
pushd library_generation
123-
pip install -r requirements.txt
124-
popd
117+
pip install --upgrade pip
118+
pip install --require-hashes -r hermetic_build/common/requirements.txt
119+
pip install hermetic_build/common
120+
pip install --require-hashes -r hermetic_build/library_generation/requirements.txt
121+
pip install hermetic_build/library_generation
122+
pip install --require-hashes -r hermetic_build/release_note_generation/requirements.txt
123+
pip install hermetic_build/release_note_generation
125124
- name: Lint
126125
shell: bash
127126
run: |
128127
# exclude generated golden files
129128
# exclude owlbot until further refaction
130-
black --check library_generation --exclude "(library_generation/test/resources/goldens)"
129+
black --check hermetic_build --exclude "(library_generation/tests/resources/goldens)"
File renamed without changes.

library_generation/model/generation_config.py renamed to hermetic_build/common/model/generation_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import yaml
1818
from typing import Optional
19-
from library_generation.model.library_config import LibraryConfig
20-
from library_generation.model.gapic_config import GapicConfig
19+
from common.model.library_config import LibraryConfig
20+
from common.model.gapic_config import GapicConfig
2121

2222
REPO_LEVEL_PARAMETER = "Repo level parameter"
2323
LIBRARY_LEVEL_PARAMETER = "Library level parameter"

library_generation/model/library_config.py renamed to hermetic_build/common/model/library_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# limitations under the License.
1515
from hashlib import sha256
1616
from typing import Optional
17-
from library_generation.model.gapic_config import GapicConfig
18-
from library_generation.model.gapic_inputs import GapicInputs
17+
from common.model.gapic_config import GapicConfig
18+
from common.model.gapic_inputs import GapicInputs
1919

2020

2121
MAVEN_COORDINATE_SEPARATOR = ":"

hermetic_build/common/requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
black==24.8.0
2+
parameterized==0.9.0
3+
PyYAML==6.0.2

0 commit comments

Comments
 (0)