Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1ba4f865de | |||
acd9fda529 | |||
f63e04f7b0 | |||
ff2f37f718 |
123
.gitea/workflows/release.yml
Normal file
123
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,123 @@
|
||||
# Git(tea) Actions workflow: Build and publish standalone binaries **plus** bundled `static/` assets
|
||||
# ────────────────────────────────────────────────────────────────────
|
||||
# ✧ Builds the Go‑based WoL server for four targets **and** packt das Verzeichnis
|
||||
# `static` zusammen mit der Binary, sodass es relativ zur ausführbaren Datei
|
||||
# liegt (wichtig für die eingebauten Bootstrap‑Assets & favicon).
|
||||
#
|
||||
# • linux/amd64 → wol-server-linux-amd64.tar.gz
|
||||
# • linux/arm64 → wol-server-linux-arm64.tar.gz
|
||||
# • linux/arm/v7 → wol-server-linux-armv7.tar.gz
|
||||
# • windows/amd64 → wol-server-windows-amd64.zip
|
||||
#
|
||||
# ✧ Artefakte landen im Workflow und – bei Tag‑Push (vX.Y.Z) – als Release‑Assets.
|
||||
#
|
||||
# Secrets/variables:
|
||||
# GITEA_TOKEN – optional, falls default token keine Release‑Rechte hat.
|
||||
# ────────────────────────────────────────────────────────────────────
|
||||
|
||||
name: build-binaries
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
tags: [ "v*" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-fast
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- goos: linux
|
||||
goarch: amd64
|
||||
ext: ""
|
||||
- goos: linux
|
||||
goarch: arm64
|
||||
ext: ""
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: "7"
|
||||
ext: ""
|
||||
- goos: windows
|
||||
goarch: amd64
|
||||
ext: ".exe"
|
||||
|
||||
env:
|
||||
GO_VERSION: "1.24"
|
||||
BINARY_NAME: trading-server
|
||||
|
||||
steps:
|
||||
- name: Checkout source
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Go ${{ env.GO_VERSION }}
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
cache: true
|
||||
|
||||
- name: Build ${{ matrix.goos }}/${{ matrix.goarch }}${{ matrix.goarm && format('/v{0}', matrix.goarm) || '' }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
mkdir -p dist/package
|
||||
if [ -n "${{ matrix.goarm }}" ]; then export GOARM=${{ matrix.goarm }}; fi
|
||||
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -trimpath -ldflags "-s -w" \
|
||||
-o "dist/package/${BINARY_NAME}${{ matrix.ext }}" .
|
||||
# Assets: statisches Verzeichnis beilegen
|
||||
cp -r static dist/package/
|
||||
|
||||
- name: Package archive with static assets
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
cd dist
|
||||
if [ "${{ matrix.goos }}" == "windows" ]; then
|
||||
ZIP_NAME="${BINARY_NAME}-windows-amd64.zip"
|
||||
(cd package && zip -r "../$ZIP_NAME" .)
|
||||
else
|
||||
ARCH_SUFFIX="${{ matrix.goarch }}"
|
||||
if [ "${{ matrix.goarch }}" == "arm" ]; then ARCH_SUFFIX="armv${{ matrix.goarm }}"; fi
|
||||
TAR_NAME="${BINARY_NAME}-${{ matrix.goos }}-${ARCH_SUFFIX}.tar.gz"
|
||||
tar -czf "$TAR_NAME" -C package .
|
||||
fi
|
||||
|
||||
- name: Upload workflow artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
|
||||
path: dist/*.tar.gz
|
||||
if-no-files-found: ignore
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: windows-amd64
|
||||
path: dist/*.zip
|
||||
if-no-files-found: ignore
|
||||
|
||||
# Release Schritt für Tag‑Pushes
|
||||
release:
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
needs: build
|
||||
runs-on: ubuntu-fast
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: ./dist
|
||||
|
||||
- name: Create / Update release
|
||||
uses: softprops/action-gh-release@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
||||
with:
|
||||
name: "Release ${{ github.ref_name }}"
|
||||
tag_name: ${{ github.ref_name }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
files: |
|
||||
dist/**/${BINARY_NAME}-*.tar.gz
|
||||
dist/**/${BINARY_NAME}-*.zip
|
55
main.go
55
main.go
@@ -401,6 +401,7 @@ func main() {
|
||||
})
|
||||
|
||||
http.HandleFunc("/markaspaid", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Method", "/markaspaid", r.Method)
|
||||
if !isAuthenticated(r) {
|
||||
http.Error(w, "Nicht autorisiert", http.StatusUnauthorized)
|
||||
return
|
||||
@@ -419,6 +420,7 @@ func main() {
|
||||
})
|
||||
|
||||
http.HandleFunc("/unmarkaspaid", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Method", "/unmarkaspaid", r.Method)
|
||||
if !isAuthenticated(r) {
|
||||
http.Error(w, "Nicht autorisiert", http.StatusUnauthorized)
|
||||
return
|
||||
@@ -437,6 +439,7 @@ func main() {
|
||||
})
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Method", "/", r.Method)
|
||||
if r.Method == http.MethodPost {
|
||||
if !isAuthenticated(r) {
|
||||
http.Error(w, "Nicht autorisiert", http.StatusUnauthorized)
|
||||
@@ -455,6 +458,21 @@ func main() {
|
||||
wareStr := strings.Join(ware, ", ")
|
||||
zeitaufwand, _ := strconv.ParseFloat(r.FormValue("zeitaufwand"), 64)
|
||||
|
||||
e := Entry{
|
||||
Anfangsbestand: anfang,
|
||||
Endbestand: ende,
|
||||
Gesamtwert: diff,
|
||||
Prozentwert: prozent,
|
||||
Abgabe: abgabe,
|
||||
Startort: startort,
|
||||
Zielort: zielort,
|
||||
Schiff: schiff,
|
||||
Ware: wareStr,
|
||||
Zeitaufwand: zeitaufwand,
|
||||
}
|
||||
|
||||
go sendDiscordWebhook(e)
|
||||
|
||||
_, err := db.Exec(`INSERT INTO eintraege (anfangsbestand, endbestand, prozentwert, abgabe, created_at, startort, zielort, schiff, ware, zeitaufwand) VALUES (?, ?, ?, ?, datetime('now'), ?, ?, ?, ?, ?)`, anfang, ende, prozent, abgabe, startort, zielort, schiff, wareStr, zeitaufwand)
|
||||
if err != nil {
|
||||
http.Error(w, "Fehler beim Einfügen", http.StatusInternalServerError)
|
||||
@@ -474,6 +492,7 @@ func main() {
|
||||
cachedData := cache.Data
|
||||
cacheMutex.RUnlock()
|
||||
|
||||
fmt.Println("validCache:", validCache)
|
||||
if validCache {
|
||||
cachedData.LoggedIn = isAuthenticated(r)
|
||||
tmpl.Execute(w, cachedData)
|
||||
@@ -630,7 +649,7 @@ func main() {
|
||||
cache.Data = computed
|
||||
cache.LastComputed = time.Now()
|
||||
cacheMutex.Unlock()
|
||||
|
||||
computed.LoggedIn = isAuthenticated(r)
|
||||
tmpl.Execute(w, computed)
|
||||
|
||||
/*tmpl.Execute(w, struct {
|
||||
@@ -690,6 +709,40 @@ type CachedData struct {
|
||||
var cache CachedData
|
||||
var cacheMutex sync.RWMutex
|
||||
|
||||
var discordWebhook = GetENV("DISCORD_WEBHOOK_URL", "")
|
||||
|
||||
func sendDiscordWebhook(entry Entry) {
|
||||
if discordWebhook == "" {
|
||||
return
|
||||
}
|
||||
|
||||
message := fmt.Sprintf(
|
||||
"📦 **Neuer Abgabe-Eintrag**\n"+
|
||||
"**UEC:** %s → %s (%s UEC Profit)\n"+
|
||||
"**Abgabe:** %s UEC (%s%%)\n"+
|
||||
"**Route:** %s → %s mit %s\n"+
|
||||
"**Ware:** %s\n"+
|
||||
"**Dauer:** %.0f Minuten",
|
||||
formatNumber(entry.Anfangsbestand),
|
||||
formatNumber(entry.Endbestand),
|
||||
formatNumber(entry.Gesamtwert),
|
||||
formatNumber(entry.Abgabe),
|
||||
formatNumber(entry.Prozentwert),
|
||||
entry.Startort,
|
||||
entry.Zielort,
|
||||
entry.Schiff,
|
||||
entry.Ware,
|
||||
entry.Zeitaufwand,
|
||||
)
|
||||
|
||||
payload := map[string]string{
|
||||
"content": message,
|
||||
}
|
||||
jsonData, _ := json.Marshal(payload)
|
||||
|
||||
http.Post(discordWebhook, "application/json", strings.NewReader(string(jsonData)))
|
||||
}
|
||||
|
||||
func createTable(db *sql.DB) {
|
||||
_, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS eintraege (
|
||||
|
Reference in New Issue
Block a user