diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 11b149c..76802da 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -58,6 +58,8 @@ jobs: working-directory: services run: | go run cmd/docgen/main.go . + env: + MICRO_ADMIN_TOKEN: ${{ secrets.MICRO_ADMIN_TOKEN }} - name: Deploy if: github.ref == 'refs/heads/master' diff --git a/cmd/docgen/main.go b/cmd/docgen/main.go index 5f3a847..4ee0b35 100644 --- a/cmd/docgen/main.go +++ b/cmd/docgen/main.go @@ -1,11 +1,13 @@ package main import ( + "bytes" "encoding/json" "fmt" "io" "io/ioutil" "log" + "net/http" "os" "os/exec" "path/filepath" @@ -16,6 +18,33 @@ import ( "github.com/stoewer/go-strcase" ) +func saveMeta(service, readme, openapijson string) error { + client := &http.Client{} + + //Encode the data + postBody, _ := json.Marshal(map[string]string{ + "serviceName": service, + "readme": readme, + "openAPIJSON": openapijson, + }) + rbody := bytes.NewBuffer(postBody) + + //Leverage Go's HTTP Post function to make request + req, err := http.NewRequest("POST", "https://api.m3o.com/explore/SaveMeta", rbody) + + // Add auth headers here if needed + req.Header.Add("Authorization", `Bearer `+os.Getenv("MICRO_ADMIN_TOKEN")) + resp, err := client.Do(req) + + if err != nil { + return err + } + defer resp.Body.Close() + io.Copy(ioutil.Discard, resp.Body) + + return nil +} + const ( postContentPath = "docs/hugo-tania/site/content/post" docsURL = "services.m3o.com" @@ -92,6 +121,13 @@ func main() { fmt.Println("Failed to unmarshal", err) os.Exit(1) } + + err = saveMeta(serviceName, string(dat), string(js)) + if err != nil { + fmt.Println("Failed to save meta to explore service", err) + os.Exit(1) + } + err = saveSpec(dat, contentDir, serviceName, spec) if err != nil { fmt.Println("Failed to save to spec file", err)