This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbuild.gradle
54 lines (46 loc) · 1.71 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.revwalk.RevWalk
import java.util.stream.StreamSupport
buildscript {
ext {
compose_version = '1.3.0-alpha01'
accompanist_version = '0.24.12-rc'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'org.eclipse.jgit:org.eclipse.jgit:6.2.0.202206071550-r'
}
}
ext {
def gitLatestTag = null
def gitCommitId = null
def gitCommitCount = 0
try (FileRepository repo = new FileRepository(rootProject.file(".git"))) {
def allTags = repo.getRefDatabase().getRefsByPrefix(Constants.R_TAGS)
try (RevWalk revWalk = new RevWalk(repo)) {
revWalk.markStart(revWalk.parseCommit(repo.resolve("HEAD")))
RevCommit next = revWalk.next()
while (next != null) {
for (tag in allTags) {
if (tag.getObjectId() == next.id) {
gitLatestTag = tag.name.substring(Constants.R_TAGS.length())
break
}
}
if (gitLatestTag != null) break
next = revWalk.next()
}
}
def gitObjectId = repo.refDatabase.exactRef("refs/remotes/origin/master").objectId
gitCommitId = gitObjectId.abbreviate(10).name()
gitCommitCount = StreamSupport.stream(new Git(repo).log().add(gitObjectId).call().spliterator(), false).count()
}
version_code = (int) gitCommitCount
version_name = "${gitLatestTag}.r${gitCommitCount}.${gitCommitId}".toString()
}