alaskartv-api/main.go

73 lines
1.8 KiB
Go
Raw Normal View History

2024-12-19 19:42:51 +00:00
package main
import (
"fmt"
"net/http"
"os"
"os/exec"
"github.com/gin-gonic/gin"
)
func updateVersion(repoPath string, serviceName string) error {
2024-12-19 19:56:29 +00:00
versionPath := fmt.Sprintf("%s/version.txt", repoPath)
versionFile := "version.txt"
2024-12-19 19:42:51 +00:00
newVersion := getVersion(serviceName)
if repoPath == "/data/alaskartv/androidtv-ci" {
2024-12-19 19:56:29 +00:00
versionPath = fmt.Sprintf("%s/release.txt", repoPath)
versionFile = "release.txt"
2024-12-19 19:42:51 +00:00
}
2024-12-19 19:56:29 +00:00
os.WriteFile(versionPath, []byte(newVersion), 0644)
2024-12-19 19:42:51 +00:00
cmds := [][]string{
2024-12-19 19:56:29 +00:00
{"git", "-C", repoPath, "add", versionFile},
2024-12-19 19:42:51 +00:00
{"git", "-C", repoPath, "commit", "-m", fmt.Sprintf("Bump version to %s", newVersion)},
{"git", "-C", repoPath, "push"},
}
for _, cmd := range cmds {
err := exec.Command(cmd[0], cmd[1:]...).Run()
if err != nil {
return fmt.Errorf("failed to execute command %v: %w", cmd, err)
}
}
return nil
}
func main() {
router := gin.Default()
router.POST("/api/alaskarfin", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/docker-ci/alaskarfin", "alaskarfin")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
return
}
c.String(http.StatusOK, "Bumped Alaskarfin!")
})
router.POST("/api/alaskarseer", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/docker-ci/alaskarseer", "alaskarseer")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
return
}
c.String(http.StatusOK, "Bumped Alaskarseer!")
})
router.POST("/api/alaskartv", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/androidtv-ci", "alaskartv")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
return
}
c.String(http.StatusOK, "Bumped AlaskarTV!")
})
fmt.Println("Webhook server running on port 8080")
router.Run(":8080")
}