-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (62 loc) · 1.93 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"log"
"os/exec"
"github.com/Nicconike/AutomatedGo/v2/pkg"
)
func main() {
// Create a new VersionService
service := &pkg.VersionService{
Downloader: &pkg.DefaultDownloader{},
Remover: &pkg.DefaultRemover{},
Checksum: &pkg.DefaultChecksumCalculator{},
}
// Get the latest Go version
latestVersion, err := service.GetLatestVersion()
if err != nil {
log.Fatalf("Error getting latest version: %v", err)
}
fmt.Printf("Latest Go version: %s\n", latestVersion)
// Get current version
currentVersion, err := service.GetCurrentVersion("tests/Dockerfile", "")
if err != nil {
log.Fatalf("Error getting current version: %v", err)
}
fmt.Printf("Current Go version: %s\n", currentVersion)
// Check if update is needed
if !service.IsNewer(latestVersion, currentVersion) {
fmt.Println("Already on the latest version. No update needed.")
return
}
// Download the latest Go version
err = service.DownloadGo(latestVersion, "", "", "")
if err != nil {
log.Fatalf("Error downloading Go: %v", err)
}
fmt.Println("Successfully downloaded new Go version")
// Commit and push changes
err = commitAndPush(latestVersion)
if err != nil {
log.Fatalf("Error committing and pushing changes: %v", err)
}
fmt.Println("Successfully committed and pushed new Go version to GitHub")
}
func commitAndPush(version string) error {
commands := []struct {
name string
args []string
}{
{"git", []string{"config", "--local", "user.name", "github-actions[bot]"}},
{"git", []string{"config", "--local", "user.email", "41898282+github-actions[bot]@users.noreply.github.com"}},
{"git", []string{"add", "."}},
{"git", []string{"commit", "-m", fmt.Sprintf("Update Go version to %s", version)}},
{"git", []string{"push"}},
}
for _, cmd := range commands {
if err := exec.Command(cmd.name, cmd.args...).Run(); err != nil {
return fmt.Errorf("error running '%s %v': %v", cmd.name, cmd.args, err)
}
}
return nil
}