Compare commits

...

10 commits

Author SHA1 Message Date
nomadics9
6ab1fabdd4
Changes to forgejo 2025-01-06 17:01:45 +03:00
nomadics9
fd41e9a7a8 index 2024-12-31 07:37:11 +03:00
nomadics9
3a8fa0772d frontend 2024-12-31 07:33:24 +03:00
nomadics9
258d8d3816 cors 2024-12-31 07:27:23 +03:00
nomadics9
d114d7d0f6 cors 2024-12-31 06:45:17 +03:00
nomadics9
191a681caa watch script robustness 2024-12-30 05:12:11 +03:00
nomadics9
4d458e27e8 wont bump if same version + notify on status 2024-12-30 05:02:53 +03:00
nomadics9
d7a1276f1f fixes 2024-12-30 03:28:36 +03:00
nomadics9
838438c67f added missing module 2024-12-24 02:25:54 +03:00
nomadics9
1ab21b76dc Webhook added for kubewatch notifcation 2024-12-24 02:22:50 +03:00
10 changed files with 280 additions and 52 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.env
.botenv
api-server
ssh

View file

@ -6,30 +6,37 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api-server .
FROM alpine:latest
RUN apk --no-cache add git ca-certificates jq curl
RUN apk --no-cache add git ca-certificates jq curl openssh
WORKDIR /app
COPY --from=builder /app/api-server .
COPY --from=builder --chown=1000:1000 /app/api-server .
RUN addgroup -g 1000 appuser && \
adduser -D -u 1000 -G appuser appuser
RUN printf '#!/bin/sh\n\n' > /entrypoint.sh && \
printf 'if [ -n "$GIT_USERNAME" ] && [ -n "$GITHUB_TOKEN" ]; then\n' >> /entrypoint.sh && \
printf ' git config --global user.name "$GIT_USERNAME"\n' >> /entrypoint.sh && \
printf ' git config --global user.email "${GIT_EMAIL:-no-reply@example.com}"\n' >> /entrypoint.sh && \
# printf 'if [ -n "$GIT_USERNAME" ] && [ -n "$FORGEJO_TOKEN" ]; then\n' >> /entrypoint.sh && \
printf ' git config --global user.name "AlaskarTV-Bot"\n' >> /entrypoint.sh && \
printf ' git config --global user.email "no-reply@askar.tv}"\n' >> /entrypoint.sh && \
printf ' git config --global credential.helper store\n' >> /entrypoint.sh && \
printf ' echo "https://${GIT_USERNAME}:${GITHUB_TOKEN}@github.com" > /root/.git-credentials\n' >> /entrypoint.sh && \
printf ' chmod 600 /root/.git-credentials\n' >> /entrypoint.sh && \
printf 'fi\n\n' >> /entrypoint.sh && \
# Add safe directories
printf 'git config --global --add safe.directory /data/alaskartv/docker-ci\n' >> /entrypoint.sh && \
printf 'git config --global --add safe.directory /data/alaskartv/androidtv-ci\n\n' >> /entrypoint.sh && \
# printf ' echo "https://${GIT_USERNAME}:${FORGEJO_TOKEN}@git.askar.tv" > /root/.git-credentials\n' >> /entrypoint.sh && \
# printf ' chmod 600 /root/.git-credentials\n' >> /entrypoint.sh && \
# printf 'fi\n\n' >> /entrypoint.sh && \
# # Add safe directories
printf 'git config --global --add safe.directory /data/alaskartv-forge/alaskartv-docker\n' >> /entrypoint.sh && \
printf 'git config --global --add safe.directory /data/alaskartv-forge/alaskartv-app\n\n' >> /entrypoint.sh && \
# Finally, run the main app
printf 'crond -b\n' >> /entrypoint.sh && \
printf 'exec /app/api-server\n' >> /entrypoint.sh && \
chmod +x /entrypoint.sh
COPY watchTV.sh /app/watchTV.sh
COPY frontend.html /app/index.html
COPY .botenv /app/.botenv
RUN chmod +x /app/watchTV.sh && \
echo "0 0 * * * /app/watchTV.sh" > /etc/crontabs/root
USER appuser
ENTRYPOINT ["/entrypoint.sh"]

2
README.md Normal file
View file

@ -0,0 +1,2 @@
Mount repos on /data/alaskartv-??/
Mount ssh key on appuser/.ssh

Binary file not shown.

View file

@ -1,14 +1,11 @@
services:
api-server:
image: nomadics/api-server:latest
image: nomadics/api-forge:latest
container_name: api-server
ports:
- "9090:8080"
environment:
- GIT_USERNAME=${GIT_USERNAME}
- GIT_EMAIL=${GIT_EMAIL}
- GITHUB_TOKEN=${GITHUB_TOKEN}
- "9999:8080"
volumes:
- ~/alaskartv:/data/alaskartv
- ~/alaskartv-forge:/data/alaskartv-forge
- ~/.ssh/:/home/appuser/.ssh
restart: unless-stopped
hostname: alaskar-api

120
frontend.html Normal file
View file

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html lang="en">
<script>
async function makeRequest(endpoint) {
const responseDiv = document.getElementById('response');
responseDiv.innerHTML = '';
try {
const response = await fetch(endpoint, {
method: 'POST'
});
if (!response.ok) {
const errorData = await response.json();
displayResponse(errorData);
} else {
const data = await response.json();
displayResponse(data);
}
} catch (error) {
responseDiv.textContent = `Error: ${error.message}`;
}
}
function displayResponse(data) {
const responseDiv = document.getElementById('response');
responseDiv.innerHTML = `
<div class="response-item">
<strong>Service:</strong> ${data.service}
</div>
<div class="response-item">
<strong>Message:</strong> ${data.message}
</div>
<div class="response-item">
<strong>Status:</strong> ${data.status}
</div>
<div class="response-item">
<strong>Version:</strong> ${data.version}
</div>
`;
}
function callEndpoint1() {
makeRequest('http://192.168.0.200:9090/api/alaskarfin');
}
function callEndpoint2() {
makeRequest('http://192.168.0.200:9090/api/alaskarseer');
}
function callEndpoint3() {
makeRequest('http://192.168.0.200:9090/api/alaskartv');
}
</script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alaskar Bump'n'Deploy</title>
</head>
<body>
<div class="container">
<h1>Alaskar Bump'n'Deploy</h1>
<div>
<button onclick="callEndpoint1()">AlaskarFin</button>
<button onclick="callEndpoint2()">AlaskarSeer</button>
<button onclick="callEndpoint3()">AlaskarTV</button>
</div>
<div id="response">
</div>
</div>
</body>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #0B192C;
}
.container {
text-align: center;
color: white;
background-color: #1E3E62;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #FF6500;
color: white;
border: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #FB773C;
}
#response {
margin-top: 20px;
padding: 10px;
background-color: #0B192C;
border-radius: 5px;
min-height: 50px;
text-align: left;
}
</style>
</html>

4
go.mod
View file

@ -3,6 +3,7 @@ module api-server
go 1.23.3
require (
github.com/gin-contrib/cors v1.7.3
github.com/gin-gonic/gin v1.10.0
github.com/go-resty/resty/v2 v2.16.2
github.com/joho/godotenv v1.5.1
@ -22,6 +23,7 @@ require (
github.com/goccy/go-json v0.10.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@ -34,6 +36,6 @@ require (
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

16
go.sum
View file

@ -7,11 +7,14 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
github.com/gin-contrib/cors v1.7.3 h1:hV+a5xp8hwJoTw7OY+a70FsL8JkVVFTXw9EcfrYUdns=
github.com/gin-contrib/cors v1.7.3/go.mod h1:M3bcKZhxzsvI+rlRSkkxHyljJt1ESd93COUvemZ79j4=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
@ -39,6 +42,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
@ -52,6 +59,8 @@ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNH
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -83,10 +92,11 @@ golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

128
main.go
View file

@ -2,18 +2,21 @@ package main
import (
"bufio"
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
"strconv"
"strings"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func updateVersion(repoPath string, serviceName string) error {
func updateVersion(repoPath string, serviceName string) (string, error) {
versionPath := fmt.Sprintf("%s/version.txt", repoPath)
newVersion := getVersion(serviceName)
@ -26,6 +29,27 @@ func updateVersion(repoPath string, serviceName string) error {
bumpVersionTv(repoPath)
}
currentVersion, err := os.ReadFile(versionPath)
if err != nil {
return "", fmt.Errorf("failed to read version file: %w", err)
}
// Compare versions
if strings.TrimSpace(string(currentVersion)) == strings.TrimSpace(newVersion) {
message := map[string]interface{}{
"status": "unchanged",
"message": fmt.Sprintf("Version is already at %s", newVersion),
"service": serviceName,
"version": newVersion,
}
jsonResponse, err := json.Marshal(message)
if err != nil {
return "", fmt.Errorf("failed to marshal JSON: %w", err)
}
return string(jsonResponse), nil
}
os.WriteFile(versionPath, []byte(newVersion), 0644)
cmds := [][]string{
{"git", "-C", repoPath, "add", "."},
@ -35,18 +59,30 @@ func updateVersion(repoPath string, serviceName string) error {
"curl", "-X", "POST",
fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", botToken),
"-d", fmt.Sprintf("chat_id=%s", chatid),
"-d", fmt.Sprintf("text=GO-SERVER: %s updated to %s", serviceName, newVersion),
"-d", fmt.Sprintf("text=<b>Alaskar-api</b>: <b>%s</b> updated to <b>%s</b>", serviceName, newVersion),
"-d", fmt.Sprintf("parse_mode=HTML"),
},
}
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 "", fmt.Errorf("failed to execute command %v: %w", cmd, err)
}
}
return nil
message := map[string]interface{}{
"status": "updated",
"message": fmt.Sprintf("Successfully updated from %s to %s", string(currentVersion), newVersion),
"service": serviceName,
"version": newVersion,
}
jsonResponse, err := json.Marshal(message)
if err != nil {
return "", fmt.Errorf("failed to marshal JSON: %w", err)
}
return string(jsonResponse), nil
}
func bumpVersionTv(repoPath string) {
@ -90,8 +126,8 @@ func bumpVersionTv(repoPath string) {
func notifyHandler(c *gin.Context) {
var data struct {
Name string `json:"name"`
Image string `json:"image"`
Name string `json:"name"`
Message string `json:"message"`
}
if err := c.ShouldBindJSON(&data); err != nil {
@ -102,22 +138,21 @@ func notifyHandler(c *gin.Context) {
if data.Name == "" {
data.Name = "unknown"
}
if data.Image == "" {
data.Image = "unknown"
if data.Message == "" {
data.Message = "unknown"
}
godotenv.Load(".botenv")
botToken := os.Getenv("BOT_TOKEN")
chatid := os.Getenv("CHAT_ID")
telegramToken := botToken
chatID := chatid
message := fmt.Sprintf("Service '%s' was updated to image '%s'", data.Name, data.Image)
message := fmt.Sprintf("<b>Alaskar-api</b>: <b>%s</b> \n \n %s", data.Name, data.Message)
telegramAPI := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", telegramToken)
telegramAPI := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", botToken)
resp, err := http.PostForm(telegramAPI, url.Values{
"chat_id": {chatID},
"text": {message},
"chat_id": {chatid},
"text": {message},
"parse_mode": {"HTML"},
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to send Telegram message"})
@ -128,37 +163,84 @@ func notifyHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Notification sent"})
}
func notify(jsonResponse string) {
var data struct {
Status string `json:"status"`
Message string `json:"message"`
Service string `json:"service"`
Version string `json:"version"`
}
godotenv.Load(".botenv")
botToken := os.Getenv("BOT_TOKEN")
chatid := os.Getenv("CHAT_ID")
json.Unmarshal([]byte(jsonResponse), &data)
message := fmt.Sprintf("<b>Alaskar-api</b>: <b>%s %s</b> \n \n %s", data.Service, data.Status, data.Message)
telegramAPI := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", botToken)
resp, _ := http.PostForm(telegramAPI, url.Values{
"chat_id": {chatid},
"text": {message},
"parse_mode": {"HTML"},
})
defer resp.Body.Close()
}
func main() {
router := gin.Default()
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"POST", "GET", "OPTIONS"},
AllowHeaders: []string{"Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
router.POST("/api/alaskarfin", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/docker-ci/alaskarfin", "alaskarfin")
jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-docker/alaskarfin", "alaskarfin")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
c.String(http.StatusOK, "Bumped Alaskarfin!")
c.Header("Content-Type", "application/json")
c.String(http.StatusOK, jsonResponse)
notify(jsonResponse)
})
router.POST("/api/alaskarseer", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/docker-ci/alaskarseer", "alaskarseer")
jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-docker/alaskarseer", "alaskarseer")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
c.String(http.StatusOK, "Bumped Alaskarseer!")
c.Header("Content-Type", "application/json")
c.String(http.StatusOK, jsonResponse)
notify(jsonResponse)
})
router.POST("/api/alaskartv", func(c *gin.Context) {
err := updateVersion("/data/alaskartv/androidtv-ci", "alaskartv")
jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-app", "alaskartv")
if err != nil {
c.String(http.StatusInternalServerError, "Something went wrong: %s", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
c.String(http.StatusOK, "Bumped AlaskarTV!")
c.Header("Content-Type", "application/json")
c.String(http.StatusOK, jsonResponse)
notify(jsonResponse)
})
router.POST("/notify", notifyHandler)
router.GET("/", func(c *gin.Context) {
c.File("index.html")
})
fmt.Println("Webhook server running on port 8080")
router.Run(":8080")

View file

@ -1,21 +1,28 @@
#!/bin/sh
if [ -f .botenv ]; then
export $(grep -v '^#' .botenv | xargs)
fi
LAST_RELEASE_FILE=/data/alaskartv/androidtv-ci/release.txt
latest_release=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" | jq -r '.tag_name')
echo "Latest Release: '$latest_release'"
if [ -f "$LAST_RELEASE_FILE" ]; then
read -r version < "$LAST_RELEASE_FILE"
else
version=""
fi
echo "Current Version: '$version'"
echo "Comparison result: $latest_release != $version"
if [ "$latest_release" != "$version" ]; then
# echo "$latest_release" > "$LAST_RELEASE_FILE"
curl -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="🚀 New Release Detected: $latest_release on $REPO_OWNER/$REPO_NAME"
curl -X POST "http://alaskar-api:8080/api/alaskartv"
echo "Versions are different, updating..."
curl -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="🚀 New Release Detected: $latest_release on $REPO_OWNER/$REPO_NAME"
curl -X POST "http://api-server:9090/api/alaskartv"
else
echo "Versions are the same, no update needed"
fi