main.go 3.1 KB

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