From c70745f106a597efbe1d3b6daebc40e6b94e1718 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Tue, 6 May 2025 17:15:49 -0400 Subject: [PATCH] Add the ability to automatically emit the CI file --- Makefile | 7 +++++-- cmd/github-site-gen/main.go | 19 +++++++++++++++++++ pkg/templates/template.go | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8e18ca8..8d5e654 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ -fmt: - find . -name '*.go' -exec gofumpt -w -s -extra {} \; \ No newline at end of file +fmt: cp + find . -name '*.go' -exec gofumpt -w -s -extra {} \; + +cp: + cp -v ./.github/workflows/page.yml pkg/templates/page.yml \ No newline at end of file diff --git a/cmd/github-site-gen/main.go b/cmd/github-site-gen/main.go index 95ae08c..984b1b7 100644 --- a/cmd/github-site-gen/main.go +++ b/cmd/github-site-gen/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "os/exec" "path/filepath" "strings" "time" @@ -24,9 +25,27 @@ func main() { mainTemplateOverride := flag.String("main-template", "", "Path to custom main template") docTemplateOverride := flag.String("doc-template", "", "Path to custom documentation template") styleTemplateOverride := flag.String("style-template", "", "Path to custom style template") + setupYaml := flag.Bool("page-yaml", false, "Generate .github/workflows/page.yaml file") flag.Parse() + if *setupYaml { + if err := os.MkdirAll(".github/workflows", 0o755); err != nil { + log.Fatalf("Failed to create .github/workflows directory: %v", err) + } + // Generate the page.yaml file + if err := os.WriteFile(".github/workflows/page.yml", []byte(templates.CITemplate), 0o644); err != nil { + log.Fatalf("Failed to generate page.yml: %v", err) + } + fmt.Printf("Generated .github/workflows/page.yaml in %s\n", *outputFlag) + if err := exec.Command("git", "add", ".github/workflows/page.yml").Run(); err != nil { + log.Fatalf("Failed to add page.yml to git: %v", err) + } + fmt.Println("Added .github/workflows/page.yml to git staging area.") + fmt.Println("You can now commit and push this file to your repository.") + os.Exit(0) + } + // Validate repository flag if *repoFlag == "" { fmt.Println("Error: -repo flag is required (format: owner/repo-name)") diff --git a/pkg/templates/template.go b/pkg/templates/template.go index db1f89f..fd2644e 100644 --- a/pkg/templates/template.go +++ b/pkg/templates/template.go @@ -10,3 +10,6 @@ var DocTemplate string //go:embed style.css var StyleTemplate string + +//go:embed page.yml +var CITemplate string