watcher for android app + telegram notification on api call
This commit is contained in:
parent
47d5112e7b
commit
7b6ec9b197
7 changed files with 38 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.env
|
||||
.botenv
|
||||
|
|
|
@ -6,7 +6,7 @@ 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
|
||||
RUN apk --no-cache add git ca-certificates jq
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/api-server .
|
||||
|
@ -26,5 +26,10 @@ RUN printf '#!/bin/sh\n\n' > /entrypoint.sh && \
|
|||
printf 'exec /app/api-server\n' >> /entrypoint.sh && \
|
||||
chmod +x /entrypoint.sh
|
||||
|
||||
COPY watchTV.sh /app/watchTV.sh
|
||||
COPY .botenv /app/.botenv
|
||||
RUN chmod +x /app/watchTV.sh && \
|
||||
echo "0 0 * * * /app/watchTV.sh" > /etc/crontabs/root
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
|
|
BIN
api-server
BIN
api-server
Binary file not shown.
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.23.3
|
|||
require (
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/go-resty/resty/v2 v2.16.2
|
||||
github.com/joho/godotenv v1.5.1
|
||||
golang.org/x/mod v0.17.0
|
||||
)
|
||||
|
||||
|
|
2
go.sum
2
go.sum
|
@ -31,6 +31,8 @@ github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
|
|||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
|
|
11
main.go
11
main.go
|
@ -10,12 +10,17 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func updateVersion(repoPath string, serviceName string) error {
|
||||
versionPath := fmt.Sprintf("%s/version.txt", repoPath)
|
||||
newVersion := getVersion(serviceName)
|
||||
|
||||
godotenv.Load(".env")
|
||||
botToken := os.Getenv("BOT_TOKEN")
|
||||
chatid := os.Getenv("CHAT_ID")
|
||||
|
||||
if serviceName == "alaskartv" {
|
||||
versionPath = fmt.Sprintf("%s/release.txt", repoPath)
|
||||
bumpVersionTv(repoPath)
|
||||
|
@ -26,6 +31,12 @@ func updateVersion(repoPath string, serviceName string) error {
|
|||
{"git", "-C", repoPath, "add", "."},
|
||||
{"git", "-C", repoPath, "commit", "-m", fmt.Sprintf("Bump version to %s", newVersion)},
|
||||
{"git", "-C", repoPath, "push"},
|
||||
{
|
||||
"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),
|
||||
},
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
|
|
17
watchTV.sh
Executable file
17
watchTV.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [ -f .env ]; 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')
|
||||
|
||||
if [ "$latest_release" != "$(cat $LAST_RELEASE_FILE 2>/dev/null)" ]; 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://localhost:9090/alaskartv"
|
||||
fi
|
Loading…
Reference in a new issue