Skip to content

Commit 645951c

Browse files
authored
Merge branch 'main' into renovate/markupsafe-2.x
2 parents cd92f75 + 766646a commit 645951c

31 files changed

+317
-253
lines changed

.cloudbuild/library_generation/library_generation.Dockerfile

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,68 @@
1515
# build from the root of this repo:
1616
FROM gcr.io/cloud-devrel-public-resources/python
1717

18-
# install tools
18+
ARG SYNTHTOOL_COMMITTISH=63cc541da2c45fcfca2136c43e638da1fbae174d
19+
ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550
20+
ENV HOME=/home
21+
22+
# install OS tools
1923
RUN apt-get update && apt-get install -y \
2024
unzip openjdk-17-jdk rsync maven jq \
2125
&& apt-get clean
2226

23-
COPY library_generation /src
24-
27+
# use python 3.11 (the base image has several python versions; here we define the default one)
2528
RUN rm $(which python3)
2629
RUN ln -s $(which python3.11) /usr/local/bin/python
2730
RUN ln -s $(which python3.11) /usr/local/bin/python3
2831
RUN python -m pip install --upgrade pip
29-
RUN cd /src && python -m pip install -r requirements.txt
30-
RUN cd /src && python -m pip install .
3132

32-
# set dummy git credentials for empty commit used in postprocessing
33-
RUN git config --global user.email "[email protected]"
34-
RUN git config --global user.name "Cloud Java Bot"
33+
# copy source code
34+
COPY library_generation /src
3535

36-
WORKDIR /workspace
37-
RUN chmod 750 /workspace
38-
RUN chmod 750 /src/generate_repo.py
36+
# install scripts as a python package
37+
WORKDIR /src
38+
RUN python -m pip install -r requirements.txt
39+
RUN python -m pip install .
40+
41+
# install synthtool
42+
WORKDIR /tools
43+
RUN git clone https://github.com/googleapis/synthtool
44+
WORKDIR /tools/synthtool
45+
RUN git checkout "${SYNTHTOOL_COMMITTISH}"
46+
RUN python3 -m pip install --no-deps -e .
47+
RUN python3 -m pip install -r requirements.in
3948

40-
CMD [ "/src/generate_repo.py" ]
49+
# Install nvm with node and npm
50+
ENV NODE_VERSION 20.12.0
51+
WORKDIR /home
52+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
53+
RUN chmod o+rx /home/.nvm
54+
ENV NODE_PATH=/home/.nvm/versions/node/v${NODE_VERSION}/bin
55+
ENV PATH=${PATH}:${NODE_PATH}
56+
RUN node --version
57+
RUN npm --version
58+
59+
# install the owl-bot CLI
60+
WORKDIR /tools
61+
RUN git clone https://github.com/googleapis/repo-automation-bots
62+
WORKDIR /tools/repo-automation-bots/packages/owl-bot
63+
RUN git checkout "${OWLBOT_CLI_COMMITTISH}"
64+
RUN npm i && npm run compile && npm link
65+
RUN owl-bot copy-code --version
66+
RUN chmod -R o+rx ${NODE_PATH}
67+
RUN ln -sf ${NODE_PATH}/* /usr/local/bin
68+
69+
# allow users to access the script folders
70+
RUN chmod -R o+rx /src
71+
72+
# set dummy git credentials for the empty commit used in postprocessing
73+
# we use system so all users using the container will use this configuration
74+
RUN git config --system user.email "[email protected]"
75+
RUN git config --system user.name "Cloud Java Bot"
76+
77+
# allow read-write for /home and execution for binaries in /home/.nvm
78+
RUN chmod -R a+rw /home
79+
RUN chmod -R a+rx /home/.nvm
80+
81+
WORKDIR /workspace
82+
ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ]

.github/workflows/anaylze_dependency.yaml renamed to .github/workflows/analyze_dependency.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/setup-java@v4
2626
with:
2727
distribution: temurin
28-
java-version: 11
28+
java-version: 17
2929
cache: maven
3030
- name: Set up Maven
3131
uses: stCarolas/[email protected]

.github/workflows/verify_library_generation.yaml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,38 @@ on:
33
branches:
44
- main
55
pull_request:
6-
paths:
7-
- library_generation/**
86

97
workflow_dispatch:
108
name: verify_library_generation
119
jobs:
12-
integration_tests:
10+
should-run-library-generation-tests:
1311
runs-on: ubuntu-22.04
12+
outputs:
13+
should_run: ${{ steps.get_changed_directories.outputs.should_run }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: get changed directories in the pull request
19+
id: get_changed_directories
20+
shell: bash
21+
run: |
22+
set -ex
23+
git checkout "${base_ref}"
24+
git checkout "${head_ref}"
25+
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
26+
if [[ ${changed_directories} =~ "library_generation/" ]]; then
27+
echo "should_run=true" >> $GITHUB_OUTPUT
28+
else
29+
echo "should_run=false" >> $GITHUB_OUTPUT
30+
fi
31+
env:
32+
base_ref: ${{ github.event.pull_request.base.ref }}
33+
head_ref: ${{ github.event.pull_request.head.ref }}
34+
library-generation-integration-tests:
35+
runs-on: ubuntu-22.04
36+
needs: should-run-library-generation-tests
37+
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
1438
steps:
1539
- uses: actions/checkout@v4
1640
- uses: actions/setup-python@v5
@@ -41,12 +65,14 @@ jobs:
4165
run: |
4266
set -x
4367
python -m unittest library_generation/test/integration_tests.py
44-
unit_tests:
68+
library-generation-unit-tests:
69+
runs-on: ${{ matrix.os }}
70+
needs: should-run-library-generation-tests
71+
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
4572
strategy:
4673
matrix:
4774
java: [ 8 ]
4875
os: [ ubuntu-22.04, macos-12 ]
49-
runs-on: ${{ matrix.os }}
5076
steps:
5177
- uses: actions/checkout@v4
5278
- name: install utils (macos)
@@ -88,8 +114,10 @@ jobs:
88114
run: |
89115
set -x
90116
python -m unittest discover -s library_generation/test/ -p "*unit_tests.py"
91-
lint-shell:
117+
library-generation-lint-shell:
92118
runs-on: ubuntu-22.04
119+
needs: should-run-library-generation-tests
120+
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
93121
steps:
94122
- uses: actions/checkout@v4
95123
- name: Run ShellCheck
@@ -98,8 +126,10 @@ jobs:
98126
scandir: 'library_generation'
99127
format: tty
100128
severity: error
101-
lint-python:
129+
library-generation-lint-python:
102130
runs-on: ubuntu-22.04
131+
needs: should-run-library-generation-tests
132+
if: needs.should-run-library-generation-tests.outputs.should_run == 'true'
103133
steps:
104134
- uses: actions/checkout@v4
105135
- name: install python dependencies

gapic-generator-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
<plugin>
352352
<groupId>org.apache.maven.plugins</groupId>
353353
<artifactId>maven-shade-plugin</artifactId>
354-
<version>3.5.2</version>
354+
<version>3.5.3</version>
355355
<executions>
356356
<execution>
357357
<phase>package</phase>

gax-java/dependencies.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ maven.org_mockito_mockito_core=org.mockito:mockito-core:2.28.2
8383
maven.org_hamcrest_hamcrest_core=org.hamcrest:hamcrest-core:1.3
8484
maven.com_google_truth_truth=com.google.truth:truth:1.4.2
8585
maven.com_googlecode_java_diff_utils_diffutils=com.googlecode.java-diff-utils:diffutils:1.3.0
86-
maven.net_bytebuddy_byte_buddy=net.bytebuddy:byte-buddy:1.14.13
86+
maven.net_bytebuddy_byte_buddy=net.bytebuddy:byte-buddy:1.14.14
8787
maven.org_objenesis_objenesis=org.objenesis:objenesis:2.6

gax-java/gax/src/main/java/com/google/api/gax/core/InstantiatingExecutorProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@
3434
import java.util.concurrent.ScheduledThreadPoolExecutor;
3535
import java.util.concurrent.ThreadFactory;
3636
import java.util.concurrent.atomic.AtomicInteger;
37+
import java.util.logging.Level;
38+
import java.util.logging.Logger;
3739

3840
/**
3941
* InstantiatingChannelProvider is an ExecutorProvider which constructs a new
4042
* ScheduledExecutorService every time getExecutor() is called.
4143
*/
4244
@AutoValue
4345
public abstract class InstantiatingExecutorProvider implements ExecutorProvider {
46+
private static final Logger LOGGER =
47+
Logger.getLogger(InstantiatingExecutorProvider.class.getName());
48+
4449
// Thread factory to use to create our worker threads
4550
private static final ThreadFactory DEFAULT_THREAD_FACTORY =
4651
new ThreadFactory() {
@@ -95,6 +100,8 @@ public static Builder newBuilder() {
95100
public static Builder newIOBuilder() {
96101
int numCpus = Runtime.getRuntime().availableProcessors();
97102
int numThreads = IO_THREAD_MULTIPLIER * Math.max(MIN_THREAD_AMOUNT, numCpus);
103+
LOGGER.log(
104+
Level.CONFIG, String.format("Thread Pool for requests has Core Pool Size: %d", numThreads));
98105

99106
return new AutoValue_InstantiatingExecutorProvider.Builder()
100107
.setExecutorThreadCount(numThreads)

library_generation/DEVELOPMENT.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
> [!IMPORTANT]
2+
> All examples assume you are inside the `library_generation` folder
3+
4+
5+
# Linting
6+
7+
When contributing, ensure your changes to python code have a valid
8+
format.
9+
10+
```
11+
python -m pip install black
12+
black .
13+
```
14+
15+
# Running the integration tests
16+
17+
The integration tests build the docker image declared in
18+
`.cloudbuild/library_generation/library_generation.Dockerfile`, pull GAPIC
19+
repositories, generate the libraries and compares the results with the source
20+
code declared in a "golden branch" of the repo.
21+
22+
It requires docker and python 3.x to be installed.
23+
24+
```
25+
python -m pip install .
26+
python -m pip install -r requirements.txt
27+
python -m unittest test/integration_tests.py
28+
```
29+
30+
# Running the unit tests
31+
32+
The unit tests of the hermetic build scripts are contained in several scripts,
33+
corresponding to a specific component. Every unit test script ends with
34+
`unit_tests.py`. To avoid them specifying them
35+
individually, we can use the following command:
36+
37+
```bash
38+
python -m unittest discover -s test/ -p "*unit_tests.py"
39+
```
40+
41+
> [!NOTE]
42+
> The output of this command may look erratic during the first 30 seconds.
43+
> This is normal. After the tests are done, an "OK" message should be shown.
44+
45+
# Running the scripts in your local environment
46+
47+
Although the scripts are designed to be run in a Docker container, you can also
48+
run them directly. This section explains how to run the entrypoint script
49+
(`library_generation/cli/entry_point.py`).
50+
51+
## Installing prerequisites
52+
53+
In order to run the generation scripts directly, there are a few tools we
54+
need to install beforehand.
55+
56+
### Install synthtool
57+
58+
It requires python 3.x to be installed.
59+
You will need to specify a committish of the synthtool repo in order to have
60+
your generation results matching exactly what the docker image would produce.
61+
You can achieve this by inspecting `SYNTHTOOL_COMMITISH` in
62+
`.cloudbuild/library_generation/library_generation.Dockerfile`.
63+
64+
```bash
65+
# obtained from .cloudbuild/library_generation/library_generation.Dockerfile
66+
export SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
67+
```
68+
69+
```bash
70+
git clone https://github.com/googleapis/synthtool
71+
cd synthtool
72+
git checkout "${SYNTHTOOL_COMMITTISH}"
73+
python -m pip install --require-hashes -r requirements.txt
74+
python -m pip install --no-deps -e .
75+
python -m synthtool --version
76+
```
77+
78+
### Install the owl-bot CLI
79+
80+
Requires node.js to be installed.
81+
Check this [installation guide](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script)
82+
for NVM, Node.js's version manager.
83+
84+
After you install it, you can install the owl-bot CLI with the following
85+
commands:
86+
```bash
87+
git clone https://github.com/googleapis/repo-automation-bots
88+
cd repo-automation-bots/packages/owl-bot
89+
npm i && npm run compile && npm link
90+
owl-bot copy-code --version
91+
```
92+
93+
The key step is `npm link`, which will make the command available in you current
94+
shell session.
95+
96+
## Running the script
97+
The entrypoint script (`library_generation/cli/entry_point.py`) allows you to
98+
update the target repository with the latest changes starting from the
99+
googleapis committish declared in `generation_config.yaml`.
100+
101+
### Download the repo
102+
For example, google-cloud-java
103+
```
104+
git clone https://github.com/googleapis/google-cloud-java
105+
export path_to_repo="$(pwd)/google-cloud-java"
106+
```
107+
108+
### Install the scripts
109+
```
110+
python -m pip install .
111+
```
112+
113+
### Run the script
114+
```
115+
python cli/entry_point.py generate --repository-path="${path_to_repo}"
116+
```
117+
118+
119+
# Running the scripts using the docker container image
120+
This is convenient in order to avoid installing the dependencies manually.
121+
122+
> [!IMPORTANT]
123+
> From now, the examples assume you are in the root of your sdk-platform-java
124+
> folder
125+
126+
## Build the docker image
127+
```bash
128+
docker build --file .cloudbuild/library_generation/library_generation.Dockerfile --iidfile image-id .
129+
```
130+
131+
This will create an `image-id` file at the root of the repo with the hash ID of
132+
the image.
133+
134+
## Run the docker image
135+
The docker image will perform changes on its internal `/workspace` folder, to which you
136+
need to map a folder on your host machine (i.e. map your downloaded repo to this
137+
folder).
138+
139+
To run the docker container on the google-cloud-java repo, you must run:
140+
```bash
141+
docker run -u "$(id -u)":"$(id -g)" -v/path/to/google-cloud-java:/workspace $(cat image-id)
142+
```
143+
144+
* `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating
145+
yourself. This avoids folder ownership changes since it runs as root by
146+
default.
147+
* `-v/path/to/google-cloud-java:/workspace` maps the host machine's
148+
google-cloud-java folder to the /workspace folder. The image is configured to
149+
perform changes in this directory
150+
* `$(cat image-id)` obtains the image ID created in the build step
151+
152+
## Debug the created containers
153+
If you are working on changing the way the containers are created, you may want
154+
to inspect the containers to check the setup. It would be convenient in such
155+
case to have a text editor/viewer available. You can achieve this by modifying
156+
the Dockerfile as follows:
157+
158+
```docker
159+
# install OS tools
160+
RUN apt-get update && apt-get install -y \
161+
unzip openjdk-17-jdk rsync maven jq less vim \
162+
&& apt-get clean
163+
```
164+
165+
We add `less` and `vim` as text tools for further inspection.
166+
167+
You can also run a shell in a new container by running:
168+
169+
```bash
170+
docker run --rm -it -u=$(id -u):$(id -g) -v/path/to/google-cloud-java:/workspace --entrypoint="bash" $(cat image-id)
171+
```

0 commit comments

Comments
 (0)