-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.gradle
109 lines (78 loc) · 2.88 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
apply plugin: 'java'
apply plugin: 'groovy'
import groovy.json.*
import org.ajoberstar.grgit.*
import org.ajoberstar.grgit.exception.GrgitException
group = 'org.terasology'
version = '0.1.0'
def uploader = new Person(name: "Gooey", email: "[email protected]")
def creds = new Credentials(username: indexerUsername, password: indexerPassword)
def repoPath = project.file('module-index')
def repo; // will be set in syncRepo
buildscript {
repositories {
// External libs - jcenter is Bintray and is supposed to be a superset of Maven Central, but do both just in case
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:0.9.0'
}
}
task syncRepo() << {
try {
logger.lifecycle("Opening repository $repoPath")
repo = Grgit.open(repoPath, creds)
logger.lifecycle("Performing pull..")
repo.pull(rebase: false)
} catch (Exception e) {
// TODO: find a better way to test if the repo exists
logger.lifecycle(e.message)
logger.lifecycle("Cloning repository $repoPath")
repo = Grgit.clone(dir: repoPath, uri: 'https://github.com/Terasology/Index.git', credentials: creds)
}
}
task updateModuleInfo(type: Copy, dependsOn: syncRepo) {
def targetFolder = "modules/$project.name"
def fname = 'module.txt'
from fname
into "module-index/$targetFolder"
doLast {
repo.add(patterns: ["$targetFolder/$fname"])
}
}
task updateIndexFile(dependsOn: syncRepo) {
mustRunAfter updateModuleInfo
// TODO: define inputs/outputs
def repoRoot = repoPath;
def modFolder = new File(repoRoot, 'modules')
def modFiles = fileTree(modFolder) {
include '**/module.txt'
}
def indexFile = file("$repoRoot/README.md")
doLast {
logger.info("Searching folder $modFolder")
logger.lifecycle("Updating $indexFile")
indexFile.text = '# Index\n\n'
indexFile.text += '| ID | Version | Name | Author\n'
indexFile.text += '|----|---------|------|-------\n'
for (File file : modFiles.files) {
def content = file.text
def json = new JsonSlurper().parseText(content)
indexFile.text += "| $json.id | $json.version | $json.displayName | $json.author |\n"
}
repo.add(patterns: [indexFile.name])
}
}
task updateRepo(dependsOn: [updateModuleInfo, updateIndexFile]) << {
// check for changes to avoid empty commits
def changes = repo.status().staged.allChanges
if (!changes.isEmpty()) {
logger.lifecycle("Committing changes in $changes")
repo.commit(author: uploader, committer: uploader, message: "Updating module info for $project.name")
repo.push()
logger.lifecycle("Pushed commits to remote")
} else {
logger.lifecycle("No files have been staged - skipping commit process")
}
}