@@ -32,6 +32,17 @@ func copySchemas() error {
32
32
return fmt .Errorf ("copy FS: %w" , err )
33
33
}
34
34
35
+ err = copyLatestSchema ()
36
+ if err != nil {
37
+ return fmt .Errorf ("copy files: %w" , err )
38
+ }
39
+
40
+ return nil
41
+ }
42
+
43
+ func copyLatestSchema () error {
44
+ src := filepath .FromSlash ("jsonschema/golangci.jsonschema.json" )
45
+
35
46
latest , err := github .GetLatestVersion ()
36
47
if err != nil {
37
48
return fmt .Errorf ("get latest release version: %w" , err )
@@ -42,17 +53,11 @@ func copySchemas() error {
42
53
return fmt .Errorf ("parse version: %w" , err )
43
54
}
44
55
45
- versioned := fmt .Sprintf ("golangci.v%d.%d.jsonschema.json" , version .Segments ()[0 ], version .Segments ()[1 ])
46
-
47
- err = copyFile (filepath .FromSlash ("jsonschema/golangci.jsonschema.json" ), filepath .Join (dstDir , versioned ))
48
- if err != nil {
49
- return fmt .Errorf ("copy files: %w" , err )
56
+ files := []string {
57
+ fmt .Sprintf ("golangci.v%d.jsonschema.json" , version .Segments ()[0 ]),
58
+ fmt .Sprintf ("golangci.v%d.%d.jsonschema.json" , version .Segments ()[0 ], version .Segments ()[1 ]),
50
59
}
51
60
52
- return nil
53
- }
54
-
55
- func copyFile (src , dst string ) error {
56
61
source , err := os .Open (src )
57
62
if err != nil {
58
63
return fmt .Errorf ("open file %s: %w" , src , err )
@@ -65,6 +70,17 @@ func copyFile(src, dst string) error {
65
70
return fmt .Errorf ("file %s not found: %w" , src , err )
66
71
}
67
72
73
+ for _ , dst := range files {
74
+ err = copyFile (dst , source , info )
75
+ if err != nil {
76
+ return fmt .Errorf ("copy file %s to %s: %w" , src , dst , err )
77
+ }
78
+ }
79
+
80
+ return nil
81
+ }
82
+
83
+ func copyFile (dst string , source io.Reader , info os.FileInfo ) error {
68
84
destination , err := os .OpenFile (dst , os .O_RDWR | os .O_CREATE | os .O_TRUNC , info .Mode ())
69
85
if err != nil {
70
86
return fmt .Errorf ("create file %s: %w" , dst , err )
@@ -74,7 +90,7 @@ func copyFile(src, dst string) error {
74
90
75
91
_ , err = io .Copy (destination , source )
76
92
if err != nil {
77
- return fmt . Errorf ( "copy file %s to %s: %w" , src , dst , err )
93
+ return err
78
94
}
79
95
80
96
return nil
0 commit comments