Files
gbr-games/cmd/gbrgames/export.go
T
gregandClaude Opus 5.5 5fb7736be2
Validate game templates / validate (push) Successful in 9m31s
ci: publish templates to the control panel on main
Adds `gbrgames export`, which builds the games_published payload from
every game.yaml, and a CI step that posts it to the panel webhook after
validation on main. Unlike the node-agent notify, a failed publish fails
the run so stale templates in the panel never go unnoticed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 17:12:50 -04:00

59 lines
1.4 KiB
Go

package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"os"
"path/filepath"
)
// runExport writes the games_published webhook payload: every game.yaml as JSON, ready for the panel.
func runExport(args []string) error {
fs := flag.NewFlagSet("export", flag.ExitOnError)
gamesDir := fs.String("games", "games", "directory holding one folder per game")
repo := fs.String("repo", "", "repository full name, e.g. gbreed-public/gbr-games")
commit := fs.String("commit", "", "commit SHA the templates come from")
out := fs.String("out", "", "file to write (default stdout)")
fs.Parse(args)
entries, err := os.ReadDir(*gamesDir)
if err != nil {
return err
}
games := []any{}
for _, e := range entries {
if !e.IsDir() {
continue
}
raw, err := os.ReadFile(filepath.Join(*gamesDir, e.Name(), "game.yaml"))
if err != nil {
return fmt.Errorf("%s: %w", e.Name(), err)
}
game, err := loadYAML(raw)
if err != nil {
return fmt.Errorf("%s/game.yaml: %w", e.Name(), err)
}
games = append(games, game)
}
if len(games) == 0 {
return errors.New("no games to export")
}
payload := map[string]any{
"repository": map[string]any{"full_name": *repo},
"after": *commit,
"games": games,
}
b, err := json.Marshal(payload)
if err != nil {
return err
}
if *out == "" {
_, err = os.Stdout.Write(b)
return err
}
return os.WriteFile(*out, b, 0o644)
}