mirror of
https://github.com/pachli/pachli-android.git
synced 2025-01-22 21:20:19 +01:00
d434144922
Start building infrastructure to automatically build and deploy the `orangeRelease` variant to Google Play. The variant needs an automatically incrementing `versionCode`. That is derived from the count of all commits. Change the separator between the version and the build metadata in the `versionName` from `-` to `+` to be consistent with semantic versioning. This is still an experiment, so the workflow is triggered manually and only uploads to the internal track
48 lines
1.7 KiB
Groovy
48 lines
1.7 KiB
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"
|
|
}
|
|
}
|
|
|
|
/** Returns the number of revisions up to the current commit */
|
|
abstract class GitRevCountSource implements ValueSource<Integer, ValueSourceParameters.None> {
|
|
@Inject abstract ExecOperations getExecOperations()
|
|
|
|
@Override Integer obtain() {
|
|
try {
|
|
def output = new ByteArrayOutputStream()
|
|
|
|
execOperations.exec {
|
|
it.commandLine 'git', 'rev-list', '--first-parent', '--count', 'HEAD'
|
|
it.standardOutput = output
|
|
}
|
|
|
|
return output.toString().trim().toInteger()
|
|
} catch (GradleException ignore) {
|
|
// Git executable unavailable, or we are not building in a git repo. Fall through:
|
|
}
|
|
return -1
|
|
}
|
|
}
|
|
|
|
ext.getGitSha = { providers.of(GitShaValueSource) {}.get() }
|
|
|
|
ext.getGitRevCount = { providers.of(GitRevCountSource) {}.get() }
|