forked from FINkit/development-environment-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_github_projects.groovy
executable file
·68 lines (57 loc) · 2.45 KB
/
update_github_projects.groovy
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
#!/usr/bin/env groovy
String.metaClass.json = { new groovy.json.JsonSlurper().parseText(delegate) }
String.metaClass.xml = { new groovy.util.XmlSlurper().parseText(delegate) }
def ant = new groovy.util.AntBuilder()
def projects = [
'cloudfoundry/cli':'cf_cli_version',
'cloudfoundry/bosh-bootloader':'bosh_bootloader_version',
'cloudfoundry-incubator/credhub-cli':'credhub_cli_version',
'cloudfoundry/bosh-cli':'bosh_cli_version',
'opencontrol/compliance-masonry':'compliance_masonry_version',
// 'mikefarah/yq':'yq_linux_version',
'hashicorp/terraform':'terraform_version',
'atom/atom':'atom_version',
'docker/compose':'docker_compose_version',
'golang/go':'go_version',
'gradle/gradle':'gradle_version',
'concourse/concourse':'fly_version',
'github/hub':'hub_version'
]
projects.each { project, ansibleKey ->
def url = "https://github.com/${project}/releases.atom"
def idString = url.toURL().text.xml().entry[0].id.text()
def versionPrefix
if ('golang/go'.equals(project)) {
versionPrefix = 'go'
} else {
versionPrefix = 'v'
}
def newVersion = idString.substring(idString.lastIndexOf('/') + 1).replace(versionPrefix,'')
if ('gradle/gradle'.equals(project)) {
newVersion = formatGradleVersion(newVersion)
}
def ansible = new File('ansible/main.yml')
def oldVersion = ansible.readLines().find{ it.contains(ansibleKey) }.replace("${ansibleKey}: ","").replace('"','').trim()
if (newVersion != oldVersion && isSameMajorRelease(oldVersion, newVersion, project)
&& !newVersion.contains("beta") && !newVersion.toLowerCase().contains("rc")) {
println "${url}: ${oldVersion} -> ${newVersion}"
ant.replace(file: "ansible/main.yml", token: "${ansibleKey}: \"${oldVersion}\"", value: "${ansibleKey}: \"${newVersion}\"")
}
}
def isSameMajorRelease (String oldVersion, String newVersion, String project) {
if (getMajorVersion(oldVersion).equals(getMajorVersion(newVersion))) {
return true
}
println "$project has changed major version from $oldVersion to $newVersion, skipping..."
return false
}
def getMajorVersion (String version) {
return version.substring(0, version.indexOf("."))
}
def formatGradleVersion (String version) {
// if a new minor release comes out, the download link doesn't include the patch version
if (version.endsWith(".0")) {
return version.substring(0, version.size() - 2)
}
return version
}