mirror of
https://github.com/accelforce/Yuito
synced 2024-12-22 13:24:46 +01:00
28 lines
924 B
Groovy
28 lines
924 B
Groovy
|
import org.gradle.api.provider.ValueSourceParameters
|
||
|
import javax.inject.Inject
|
||
|
|
||
|
// Must wrap this in a ValueSource in order to get well-defined fail behavior without confusing Gradle on repeat builds.
|
||
|
abstract class GitShaValueSource implements ValueSource<String, ValueSourceParameters.None> {
|
||
|
@Inject abstract ExecOperations getExecOperations()
|
||
|
|
||
|
@Override String obtain() {
|
||
|
try {
|
||
|
def output = new ByteArrayOutputStream()
|
||
|
|
||
|
execOperations.exec {
|
||
|
it.commandLine 'git', 'rev-parse', '--short=8', 'HEAD'
|
||
|
it.standardOutput = output
|
||
|
}
|
||
|
return output.toString().trim()
|
||
|
} catch (GradleException ignore) {
|
||
|
// Git executable unavailable, or we are not building in a git repo. Fall through:
|
||
|
}
|
||
|
return "unknown"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Export closure
|
||
|
ext.getGitSha = {
|
||
|
providers.of(GitShaValueSource) {}.get()
|
||
|
}
|