Skip to content
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

ci: using JDK 11+ to compile and JDK 8 to run junit (8) #1870

Merged
merged 8 commits into from
May 25, 2022

Conversation

suztomo
Copy link
Member

@suztomo suztomo commented May 5, 2022

Upgrading JDK setting to compile the code in Java 11 and run the tests in Java 8.

  • For "junit (8)" GitHub Actions, the compilation is done in JDK 11 (targeting Java 8 runtime) and test execution is on JDK 8.
  • For release, the compilation is done in JDK 11 (targeting Java 8 runtime).

Background: this helps to let the latest GraalVM-related code inside this repository while keeping the support of Java 8. GraalVM 21.1.0 (latest) started Java8-incompatible bytecode.

TODO: discuss this idea with Spanner team (and schedule appropriate time slot that avoids important milestones). -> The milestone has been done.

@suztomo suztomo requested review from a team as code owners May 5, 2022 02:22
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label May 5, 2022
@generated-files-bot
Copy link

generated-files-bot bot commented May 5, 2022

Warning: This pull request is touching the following templated files:

  • .github/workflows/ci.yaml
  • .kokoro/release/common.cfg

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label May 5, 2022
@suztomo suztomo marked this pull request as draft May 5, 2022 02:24
@suztomo suztomo added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 5, 2022
@suztomo suztomo force-pushed the java8-and-java11 branch from 4c05bcc to ba89167 Compare May 5, 2022 02:30
@suztomo suztomo changed the title ci: using JDK 11 to compile and JDK 8 to run junit (8) ci: using JDK 11+ to compile and JDK 8 to run junit (8) May 5, 2022
Comment on lines +228 to +231
<profile>
<!-- JDK 9+ has the "release" option to ensure the generated bytecode is
compatible with Java 8. -->
<id>compiler-release-8</id>
Copy link
Member Author

@suztomo suztomo May 5, 2022

Choose a reason for hiding this comment

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

This profile may be appropriate to be defined in the google-cloud-shared-config (the parent pom of this file).

The google-cloud-shared-config defines compiler option:

            <source>1.8</source>
            <target>1.8</target>

https://github.com/googleapis/java-shared-config/blob/3f84da04d9df8d0a114915e8faa8dc2e682e7cb5/pom.xml#L175

Copy link
Member Author

Choose a reason for hiding this comment

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

@suztomo
Copy link
Member Author

suztomo commented May 5, 2022

We may need to address windows build but that's feasible.

@suztomo suztomo added the owlbot:run Add this label to trigger the Owlbot post processor. label May 20, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 20, 2022
@suztomo suztomo marked this pull request as ready for review May 20, 2022 15:18
@suztomo suztomo added owlbot:run Add this label to trigger the Owlbot post processor. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. owlbot:run Add this label to trigger the Owlbot post processor. labels May 20, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label May 20, 2022
@suztomo suztomo requested a review from ansh0l May 23, 2022 20:46
Copy link
Contributor

@ansh0l ansh0l left a comment

Choose a reason for hiding this comment

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

@rajatbhatta : Please check this PR for nightly tests.

We seem to be switching to java11 from java8 at a couple of places, so we need to ensure existing builds around java8 are working allright.

@@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [8, 11, 17]
java: [11, 17]
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this impact any of the existing test runs against java8? units-java8 job should cover the unit tests, but on fusion, I can see java8-samples as another job.

cc @thiagotnunes

Copy link
Member Author

@suztomo suztomo May 24, 2022

Choose a reason for hiding this comment

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

For Kokoro builds, I have modified java8 container to have JAVA11_HOME environment variable in googleapis/testing-infra-docker#211.

suztomo@suztomo:~$ docker run --rm -it --entrypoint bash gcr.io/cloud-devrel-kokoro-resources/java8
Unable to find image 'gcr.io/cloud-devrel-kokoro-resources/java8:latest' locally
latest: Pulling from cloud-devrel-kokoro-resources/java8
...
Digest: sha256:86a9e70f109b5efd16204dea51cf30aa2295bbbd4e980d2fd2172d2f7b2382e4
Status: Downloaded newer image for gcr.io/cloud-devrel-kokoro-resources/java8:latest


root@c4a6f4994f6c:/workspace# 
root@c4a6f4994f6c:/workspace# printenv
PYENV_SHELL=bash
HOSTNAME=c4a6f4994f6c
JAVA_HOME=/usr/local/openjdk-8
JAVA8_HOME=/usr/local/openjdk-8
...
JAVA11_HOME=/usr/lib/jvm/java-11-openjdk-amd64
...

Copy link
Contributor

Choose a reason for hiding this comment

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

@suztomo We specify the docker image version for java8-samples here: https://github.com/googleapis/java-spanner/blob/main/.kokoro/nightly/java8-samples.cfg#L6

I think this will be alright, but double checking if we set the correct ENV variables in this container as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

@thiagotnunes Thank you for the info. Yes, that line value: "gcr.io/cloud-devrel-kokoro-resources/java8" matches the container image URL I have modified. It has JAVA8_HOME and JAVA11_HOME now. (I added the docker command invocation to my comment above)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the info LGTM

RETURN_CODE=0
set +e

case ${JOB_TYPE} in
test)
mvn test -B \
mvn test -B -V \
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we need the version of mvn for - does it tie to native image compilation in some way?

Copy link
Member Author

@suztomo suztomo May 24, 2022

Choose a reason for hiding this comment

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

This clarifies which versions of JDK it's running. We're running JDK 11 to compile and JDK 8 to run tests. (It's nice-to-have)

Comment on lines +33 to +34
if [ ! -z "${JAVA11_HOME}" ]; then
setJava "${JAVA11_HOME}"
Copy link
Member Author

Choose a reason for hiding this comment

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

JAVA11_HOME is now available in the container image for Kokoro:

#1870 (comment)

Comment on lines +58 to +59
if [ ! -z "${JAVA8_HOME}" ]; then
setJava "${JAVA8_HOME}"
Copy link
Member Author

Choose a reason for hiding this comment

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

JAVA8_HOME is now available in the container image for Kokoro:

#1870 (comment)

Copy link
Contributor

@ansh0l ansh0l left a comment

Choose a reason for hiding this comment

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

lgtm

@suztomo suztomo merged commit 4143583 into googleapis:main May 25, 2022
@suztomo
Copy link
Member Author

suztomo commented May 25, 2022

My ad-hoc invocation of the Java 8 job http://sponge2/132d68b4-9667-43b0-9d7c-49a2b3f12571 shows good. The "Build Log" tab shows that first it compiled the project with JDK 11:

Java version: 11.0.15, vendor: Debian, runtime: /usr/lib/jvm/java-11-openjdk-amd64

and then it ran tests with JDK 8:

Java version: 1.8.0_332, vendor: Oracle Corporation, runtime: /usr/local/openjdk-8/jre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants