-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradle.go
51 lines (48 loc) · 1.03 KB
/
gradle.go
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
package pkg
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
)
func getGradleFiles() []string {
var paths []string
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
var extension = filepath.Ext(info.Name())
if extension == ".gradle" || extension == ".kts" {
paths = append(paths, path)
}
return nil
})
if err != nil {
log.Println(err)
}
return paths
}
func UpdateVersionCode(versionCode int64, step int) {
for _, path := range getGradleFiles() {
input, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalln(err)
}
lines := strings.Split(string(input), "\n")
for i, line := range lines {
if strings.Contains(line, "versionCode") {
var re = regexp.MustCompile(`[\d]+`)
temp := re.ReplaceAllString(line, strconv.Itoa(int(versionCode)+step))
lines[i] = temp
}
}
output := strings.Join(lines, "\n")
err = ioutil.WriteFile(path, []byte(output), 0644)
if err != nil {
log.Fatalln(err)
}
}
}