Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: regenerate scripts skips dirs that contains diff exec command #1987

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions scripts/regenerate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
Expand All @@ -9,6 +10,27 @@ import (
"strings"
)

func parseExecCommand(path string) (string, error) {
var exec = struct {
Command string `json:"command"`
}{
Command: "generate",
}

execJsonPath := filepath.Join(path, "exec.json")
if _, err := os.Stat(execJsonPath); !os.IsNotExist(err) {
blob, err := os.ReadFile(execJsonPath)
if err != nil {
return "", err
}
if err := json.Unmarshal(blob, &exec); err != nil {
return "", err
}
}

return exec.Command, nil
}

func regenerate(dir string) error {
return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand All @@ -19,6 +41,15 @@ func regenerate(dir string) error {
}
if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") {
cwd := filepath.Dir(path)
command, err := parseExecCommand(cwd)
if err != nil {
return fmt.Errorf("failed to parse exec.json: %w", err)
}

if command != "generate" {
return nil
}

cmd := exec.Command("sqlc-dev", "generate", "--experimental")
cmd.Dir = cwd
out, failed := cmd.CombinedOutput()
Expand Down