feat(build): remove requirement for git directory for builds (#3977)

This commit is contained in:
Swaroop Jagadish 2022-01-25 21:52:47 -08:00 committed by GitHub
parent cec541d827
commit 8dbde4bf0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 24 deletions

View File

@ -44,7 +44,7 @@ jobs:
- name: checkout upstream repo
run: |
git remote add upstream https://github.com/linkedin/datahub.git
git fetch upstream --tags
git fetch upstream --tags --force
- name: publish datahub-client jar
env:
RELEASE_USERNAME: ${{ secrets.RELEASE_USERNAME }}

View File

@ -162,6 +162,7 @@ subprojects {
// see http://ajoberstar.org/grgit/grgit-describe.html for more info about the describe method and available parameters
// 'it' is an instance of org.ajoberstar.grgit.Grgit
customProperty 'git.commit.id.describe', { it.describe(tags: true) }
failOnNoGitDirectory = false
}
plugins.withType(JavaPlugin) {

View File

@ -1,10 +1,12 @@
plugins {
id("com.palantir.git-version") apply false
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'maven-publish'
apply plugin: 'com.palantir.git-version'
import org.apache.tools.ant.filters.ReplaceTokens
jar.enabled = false // Since we only want to build shadow jars, disabling the regular jar creation
@ -27,17 +29,53 @@ jacocoTestReport {
}
def details = versionDetails()
version = details.lastTag
version = version.startsWith("v")? version.substring(1): version
// trim version if it is of size 4 to size 3
def versionParts = version.tokenize(".")
def lastPart = details.isCleanTag? versionParts[2]: (versionParts[2].toInteger()+1).toString() + "-SNAPSHOT"
version = versionParts[0] + "." + versionParts[1] + "." + lastPart
def detailedVersionString = "0.0.0-unknown-SNAPSHOT"
def snapshotVersion = false
if (project.hasProperty("releaseVersion")) {
version = releaseVersion
detailedVersionString = releaseVersion
} else {
try {
// apply this plugin in a try-catch block so that we can handle cases without .git directory
apply plugin: "com.palantir.git-version"
println("In else section")
def details = versionDetails()
detailedVersionString = gitVersion()
version = details.lastTag
version = version.startsWith("v")? version.substring(1): version
def suffix = details.isCleanTag? "": "-SNAPSHOT"
snapshotVersion = ! details.isCleanTag
}
catch (Exception e) {
e.printStackTrace()
// last fall back
version = detailedVersionString
}
}
// trim version if it is of size 4 to size 3
def versionParts = version.tokenize(".")
if (versionParts.size() > 3) {
// at-least 4 part version
// we check if the 4th part is a .0 in which case we want to create a release
if (versionParts[3] != '0') {
snapshotVersion = true
}
versionParts = versionParts[0..2]
version = versionParts[0..2].join('.')
}
processResources {
filter(ReplaceTokens, tokens:[fullVersion: gitVersion()])
}
if (snapshotVersion) {
if (versionParts[versionParts.size()-1].isInteger()) {
version = versionParts[0..versionParts.size()-2].join('.') + '.' + (versionParts[versionParts.size()-1].toInteger()+1).toString() + "-SNAPSHOT"
} else {
// we are unable to part the last token as an integer, so we just append SNAPSHOT to this version
version = versionParts[0..versionParts.size()-1].join('.') + '-SNAPSHOT'
}
}
processResources {
filter(ReplaceTokens, tokens:[fullVersion: detailedVersionString])
}
test {
useJUnit()

View File

@ -1,10 +1,12 @@
plugins {
id("com.palantir.git-version") apply false
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'signing'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'com.palantir.git-version'
import org.apache.tools.ant.filters.ReplaceTokens
jar.enabled = false // Since we only want to build shadow jars, disabling the regular jar creation
@ -19,18 +21,53 @@ configurations {
implementation.extendsFrom provided
}
def details = versionDetails()
version = details.lastTag
version = version.startsWith("v")? version.substring(1): version
// trim version if it is of size 4 to size 3
def versionParts = version.tokenize(".")
def lastPart = details.isCleanTag? versionParts[2]: (versionParts[2].toInteger()+1).toString() + "-SNAPSHOT"
version = versionParts[0] + "." + versionParts[1] + "." + lastPart
processResources {
filter(ReplaceTokens, tokens:[fullVersion: gitVersion()])
}
def detailedVersionString = "0.0.0-unknown-SNAPSHOT"
def snapshotVersion = false
if (project.hasProperty("releaseVersion")) {
version = releaseVersion
detailedVersionString = releaseVersion
} else {
try {
// apply this plugin in a try-catch block so that we can handle cases without .git directory
apply plugin: "com.palantir.git-version"
println("In else section")
def details = versionDetails()
detailedVersionString = gitVersion()
version = details.lastTag
version = version.startsWith("v")? version.substring(1): version
def suffix = details.isCleanTag? "": "-SNAPSHOT"
snapshotVersion = ! details.isCleanTag
}
catch (Exception e) {
e.printStackTrace()
// last fall back
version = detailedVersionString
}
}
// trim version if it is of size 4 to size 3
def versionParts = version.tokenize(".")
if (versionParts.size() > 3) {
// at-least 4 part version
// we check if the 4th part is a .0 in which case we want to create a release
if (versionParts[3] != '0') {
snapshotVersion = true
}
versionParts = versionParts[0..2]
version = versionParts[0..2].join('.')
}
if (snapshotVersion) {
if (versionParts[versionParts.size()-1].isInteger()) {
version = versionParts[0..versionParts.size()-2].join('.') + '.' + (versionParts[versionParts.size()-1].toInteger()+1).toString() + "-SNAPSHOT"
} else {
// we are unable to part the last token as an integer, so we just append SNAPSHOT to this version
version = versionParts[0..versionParts.size()-1].join('.') + '-SNAPSHOT'
}
}
processResources {
filter(ReplaceTokens, tokens:[fullVersion: detailedVersionString])
}
dependencies {