[Build/Core] - Add a Gradle task to create a git version properties file for core module#5186
[Build/Core] - Add a Gradle task to create a git version properties file for core module#5186kbendick wants to merge 16 commits intoapache:masterfrom
Conversation
|
$ jar -tvf spark/v3.3/spark-runtime/build/libs/iceberg-spark-runtime-3.3_2.12-0.14.0-SNAPSHOT.jar | grep version.properties
291 Fri Feb 01 00:00:00 PST 1980 org/apache/iceberg/util/version.properties
903 Fri Feb 01 00:00:00 PST 1980 org/apache/hc/client5/version.properties
839 Fri Feb 01 00:00:00 PST 1980 org/apache/hc/core5/version.properties
$ spark-shell --jars spark/v3.3/spark-runtime/build/libs/iceberg-spark-runtime-3.3_2.12-0.14.0-SNAPSHOT.jar
scala> import org.apache.iceberg.util.VersionPropertiesUtil;
import org.apache.iceberg.util.VersionPropertiesUtil
scala> VersionPropertiesUtil.gitHashFull()
res0: String = aceda8990a62e0b36a895cb5f5d49c4ee8d82d6f
scala> VersionPropertiesUtil.gitHash()
res1: String = aceda8990a
scala> VersionPropertiesUtil.projectName()
res0: String = iceberg-core
scala> VersionPropertiesUtil.projectVersion()
res1: String = 0.14.0-SNAPSHOTIn CI, |
|
In general the approach makes sense to me. However, when looking at the spark-runtime jar I noticed that there's a I looked at https://github.com/n0mer/gradle-git-properties and was wondering whether we could actually use that plugin to generate a For completeness, here's how Arrow generates that file: https://github.com/apache/arrow/blob/master/java/pom.xml#L249-L290 |
This is great. I'll try with this, as I can't find a clean way to deal with the additional file that's generated from the git tree. |
|
@nastra, @kbendick, the Iceberg release process builds the binaries that are pushed to maven central from the source release tarball, where there is no git directory. To use a plugin like this, we will need to make sure we have some process for generating the file and probably putting it in the source tree as part of the process, like how we add the Also, I couldn't tell from a brief look at the README, can that plugin produce a |
core/src/main/java/org/apache/iceberg/util/VersionPropertiesUtil.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Could this be a local variable?
There was a problem hiding this comment.
Yeah. I made everything static because most things in util are static and because the generated properties file is relative to this path.
But this could be a local variable if we make VersionPropertiesUtil have a public constructor etc. Maybe we should move it out of util? Being in util also means that we have to place the generated properties file in main/src/resources/org/apache/iceberg/util for it to be readable from here which I don't care for.
core/src/main/java/org/apache/iceberg/util/VersionPropertiesUtil.java
Outdated
Show resolved
Hide resolved
e3c5bff to
e6efb42
Compare
I'm not sure about the plugin. The way I'm doing it now definitely adds the file to the source tree (though I'd like to only do that for the release process). For now, I'm going to remove the |
|
I have a minimal example with the below diffset that produces a I think what's unclear to me is whether this file is something that we'd want to add to every single jar (since that would actually make sense imo to have some git info in jars) or whether we just want to generate a single properties file in the root of the project. In case we want to add the properties file to the root and to every single jar, then this minimal example does the job: Given that we don't specify which info we want, the full content of the file looks like this: |
There was a problem hiding this comment.
Even with double-check locking, I believe this should be marked volatile to prevent cache incoherence.
c6c2566 to
8717211
Compare
There was a problem hiding this comment.
We should make these Optional<String> for non-release builds.
There was a problem hiding this comment.
With the current plan to add the properties file to the release tarball, we can include these all the time.
c7603c0 to
a83dad4
Compare
… output file * Add a version.properties output file for core module to access build git sha and other property attributes at runtime * Add a utility class, VersionPropertiesUtil, to access the properties file at runtime * Add tests to ensure that VersionPropertiesUtil can read the properties file
…tBranchName is problematic in CI
…lds if file isn't found
|
@kbendick, can you either open a separate PR or update this one to only include the gradle task that drops a file into |
I saved everything that was in this branch elsewhere, but I can open a new PR if we’d like. |
|
Closed in favor of #5228. Might come back to this task to add into our manifests at a later date. |
This PR adds a gradle task
createProperties, which generates a properties file that is intended for access fromorg.apache.iceberg.util.VersionPropertiesUtil.The git build SHA (both short and full) and other useful information is accessible from that file.
This information is useful for debugging, and can also be sent as a header or request property with various catalogs for debugging catalog interactions with external resources.
The generated
version.propertiesfile is added to the runtime and test resources from within thecreatePropertiestask.If anybody knows a cleaner way to do that so as not to pollute the git sources, please let me know