-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmain.go
More file actions
138 lines (126 loc) · 2.83 KB
/
main.go
File metadata and controls
138 lines (126 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
"github.com/google/go-cmp/cmp"
)
func main() {
curr := flag.String("c", "", "current version")
next := flag.String("n", "", "next version")
write := flag.Bool("w", false, "write out changes")
flag.Parse()
if err := run(*curr, *next, *write); err != nil {
log.Fatal(err)
}
}
func run(current, next string, realmode bool) error {
write := func(path, old, new string) error {
if realmode {
if err := os.WriteFile(path, []byte(new), 0644); err != nil {
return fmt.Errorf("write error: %s: %w", path, err)
}
} else {
if diff := cmp.Diff(old, new); diff != "" {
log.Printf("%s: %s\n", path, diff)
}
}
return nil
}
{
path := filepath.Join(".github", "ISSUE_TEMPLATE", "BUG_REPORT.yml")
c, err := os.ReadFile(path)
if err != nil {
return err
}
old := string(c)
if !strings.Contains(old, "- "+next) {
item := "- " + current
new := strings.ReplaceAll(old, item, "- "+next+"\n "+item)
if err := write(path, old, new); err != nil {
return err
}
}
}
{
path := filepath.Join("docs", "overview", "install.md")
c, err := os.ReadFile(path)
if err != nil {
return err
}
old := string(c)
new := strings.ReplaceAll(old, "v"+current, "v"+next)
new = strings.ReplaceAll(new, "sqlc_"+current, "sqlc_"+next)
if err := write(path, old, new); err != nil {
return err
}
}
{
path := filepath.Join("internal", "info", "facts.go")
c, err := os.ReadFile(path)
if err != nil {
return err
}
old := string(c)
new := strings.ReplaceAll(old, "v"+current, "v"+next)
if err := write(path, old, new); err != nil {
return err
}
}
{
path := filepath.Join("docs", "conf.py")
c, err := os.ReadFile(path)
if err != nil {
return err
}
old := string(c)
new := strings.ReplaceAll(old, "release = '"+current, "release = '"+next)
if err := write(path, old, new); err != nil {
return err
}
}
walker := func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
switch filepath.Ext(path) {
case ".go", ".kt", ".py", ".json":
c, err := os.ReadFile(path)
if err != nil {
return err
}
old := string(c)
new := strings.ReplaceAll(old,
`"sqlc_version": "v`+current,
`"sqlc_version": "v`+next)
new = strings.ReplaceAll(new, "sqlc v"+current, "sqlc v"+next)
if realmode {
if err := os.WriteFile(path, []byte(new), 0644); err != nil {
return fmt.Errorf("write error: %s: %w", path, err)
}
}
default:
}
return nil
}
{
p := filepath.Join("internal", "endtoend", "testdata")
if err := filepath.Walk(p, walker); err != nil {
return err
}
}
{
p := filepath.Join("examples")
if err := filepath.Walk(p, walker); err != nil {
return err
}
}
return nil
}