Skip to content

Conversation

@Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Sep 21, 2023

Use stable version number on clean workspace

Previously, the graphql-java build would always produce a new version
number based on the current date and time in local development. Because
the version number would always be different between 2 Gradle
invocations, some tasks, such as javadoc or jar could never be
cached because they depend on the version number.

With this patch, the version number will no longer include the date and
time when the Git workspace is clean, because the commit hash is
sufficient to uniquely identify the state of the workspace. This allows
the tasks that depend on the version number to be properly cached.

Relativize Antlr sources in cache key

Previously, the cache key of the antlr task would be computed using
(among other things) the absolute paths of its input files. Because the
absolute paths were part of the cache key, the build cache would rarely
be hit.

With this patch, the task is configured to use relative paths
when computing the cache key.

Previously, the graphql-java build would always produce a new version
number based on the current date and time in local development. Because
the version number would always be different between 2 Gradle
invocations, some tasks, such as `javadoc` or `jar` could never be
cached because they depend on the version number.

With this patch, the version number will no longer include the date and
time when the Git workspace is clean, because the commit hash is
sufficient to uniquely identify the state of the workspace. This allows
the tasks that depend on the version number to be properly cached.
Previously, the cache key of the antlr task would be computed using
(among other things) the absolute paths of its input files. Because the
absolute paths were part of the cache key, the build cache would rarely
be hit.

With this patch, the task is configured to use relative paths
when computing the cache key.
@bbakerman bbakerman added this to the 2023 October milestone Sep 21, 2023
@bbakerman
Copy link
Member

Thanks for this PR - we are all for better builds and faster build times.

This allows the tasks that depend on the version number to be properly cached.

can I ask what cache we are talking about here - it's is a gradle external cache or just locally.

We have to add more to this PR to cater for the master release mechanism.

Every merge to master is released as a datetime+git encoded version

https://repo1.maven.org/maven2/com/graphql-java/graphql-java/0.0.0-2023-09-12T06-21-36-aae3069/

This is driven by this GitHub workflow : https://github.com/graphql-java/graphql-java/blob/master/.github/workflows/master.yml

and it currently drives the build as

./gradlew assemble && ./gradlew check --info && ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -x check --info --stacktrace

I think this PR as is will have a clean git state and hence the master release version will be -aae3069 and not 0.0.0-2023-09-12T06-21-36-aae3069 say.

We need to tweak the above code and the workflow such that we indicate we WANT a datatime+githash explcitly

@Duhemm
Copy link
Contributor Author

Duhemm commented Sep 22, 2023

Hi @bbakerman, thanks for taking a look.

can I ask what cache we are talking about here - it's is a gradle external cache or just locally.

These fixes would apply to any cache. At the moment, since there's no remote cache configured, it would apply only to the local cache however. With these fixes, the result of the jar and javadoc tasks can be cached. Previously, their results could not be cached because they depend on the version number which would be different for every Gradle run.

You're right that with this PR, releases on merge would no longer include the date and time in the version number. I'm thinking that maybe a better strategy to generate the version numbers would be:

  • In CI, version number is 000-<datetime>-<short hash> (unless we're releasing) (ie. same as current status)
  • In local development, version number is 000-<branch name>-SNAPSHOT, regardless of whether the workspace is clean or dirty

This way, there'll be no changes in the product of CI builds and local development will benefit from the local cache regardless of the developer workflow (eg. always commit before build).

What do you think?

@bbakerman
Copy link
Member

In CI, version number is 000-- (unless we're releasing) (ie. same as current status)
In local development, version number is 000--SNAPSHOT, regardless of whether the workspace is clean or dirty
What do you think?

I like that idea.

@Duhemm
Copy link
Contributor Author

Duhemm commented Sep 25, 2023

Hi @bbakerman , I've updated the build to follow the versioning scheme that we discussed. Please let me know what you think.

@dondonz
Copy link
Member

dondonz commented Oct 17, 2023

Thanks!

@dondonz dondonz added this pull request to the merge queue Oct 17, 2023
Merged via the queue into graphql-java:master with commit 35825ad Oct 17, 2023
@Duhemm Duhemm deleted the build branch October 17, 2023 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants