Skip to content

Commit

Permalink
chore: use os.CopyFS when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 2, 2025
1 parent 891fc65 commit 1a26515
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions scripts/website/copy_jsonschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"
"path/filepath"
"strings"

hcversion "github.com/hashicorp/go-version"

Expand All @@ -28,24 +27,9 @@ func copySchemas() error {
return fmt.Errorf("remove dir: %w", err)
}

err = os.MkdirAll(dstDir, os.ModePerm)
err = os.CopyFS(dstDir, os.DirFS("jsonschema"))
if err != nil {
return fmt.Errorf("make dir: %w", err)
}

// The key is the destination file.
// The value is the source file.
files := map[string]string{}

entries, err := os.ReadDir("jsonschema")
if err != nil {
return fmt.Errorf("read dir: %w", err)
}

for _, entry := range entries {
if strings.HasSuffix(entry.Name(), ".jsonschema.json") {
files[entry.Name()] = entry.Name()
}
return fmt.Errorf("copy FS: %w", err)
}

latest, err := github.GetLatestVersion()
Expand All @@ -59,13 +43,10 @@ func copySchemas() error {
}

versioned := fmt.Sprintf("golangci.v%d.%d.jsonschema.json", version.Segments()[0], version.Segments()[1])
files[versioned] = "golangci.jsonschema.json"

for dst, src := range files {
err := copyFile(filepath.Join("jsonschema", src), filepath.Join(dstDir, dst))
if err != nil {
return fmt.Errorf("copy files: %w", err)
}
err = copyFile(filepath.FromSlash("jsonschema/golangci.jsonschema.json"), filepath.Join(dstDir, versioned))
if err != nil {
return fmt.Errorf("copy files: %w", err)
}

return nil
Expand Down

0 comments on commit 1a26515

Please sign in to comment.