mirror of https://github.com/tuskyapp/Tusky.git
Browse Source
This uses unusual code provided by Mikhail Lopatkin of Gradle Inc: https://github.com/gradle/gradle/issues/23914#issuecomment-1431909019 It wraps the git sha function in a "value source". This allows it to interact correctly with configuration caching. Because the code is longer than before, it is now broken out into its own file getGitSha.gradle.pull/3327/head
2 changed files with 29 additions and 12 deletions
@ -0,0 +1,27 @@
|
||||
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() |
||||
} |
||||
Loading…
Reference in new issue