snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
45
scripts/build/main.go
Executable file
45
scripts/build/main.go
Executable file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
version := os.Getenv("VERSION")
|
||||
sha := os.Getenv("GITHUB_SHA")
|
||||
|
||||
if version == "" {
|
||||
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Println(strings.TrimSpace(string(out)))
|
||||
log.Fatal(err)
|
||||
}
|
||||
var date string
|
||||
parts := strings.Split(string(out), " ")
|
||||
date = strings.Replace(parts[0]+parts[1], "-", "", -1)
|
||||
date = strings.Replace(date, ":", "", -1)
|
||||
version = fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
|
||||
}
|
||||
|
||||
fmt.Printf("::set-output name=version::%s\n", version)
|
||||
|
||||
x := "-X github.com/sqlc-dev/sqlc/internal/cmd.version=" + version
|
||||
args := []string{
|
||||
"build",
|
||||
"-ldflags", x,
|
||||
"-o", "./sqlc",
|
||||
"./cmd/sqlc",
|
||||
}
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Env = os.Environ()
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Println(strings.TrimSpace(string(out)))
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
150
scripts/bump-version/main.go
Normal file
150
scripts/bump-version/main.go
Normal file
@@ -0,0 +1,150 @@
|
||||
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", ".md":
|
||||
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-version: "`+current,
|
||||
`sqlc-version: "`+next)
|
||||
new = strings.ReplaceAll(new,
|
||||
`sqlc-version: '`+current,
|
||||
`sqlc-version: '`+next)
|
||||
new = strings.ReplaceAll(new, "sqlc v"+current, "sqlc v"+next)
|
||||
new = strings.ReplaceAll(new, "SQLC_VERSION=v"+current, "SQLC_VERSION=v"+next)
|
||||
if err := write(path, old, new); err != nil {
|
||||
return 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
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
p := filepath.Join("docs")
|
||||
if err := filepath.Walk(p, walker); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
55
scripts/cleanup-test-dbs/main.go
Normal file
55
scripts/cleanup-test-dbs/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
const query = `
|
||||
SELECT datname
|
||||
FROM pg_database
|
||||
WHERE datname LIKE 'sqlc_test_%'
|
||||
`
|
||||
|
||||
func run() error {
|
||||
ctx := context.Background()
|
||||
dburi := os.Getenv("POSTGRESQL_SERVER_URI")
|
||||
if dburi == "" {
|
||||
return fmt.Errorf("POSTGRESQL_SERVER_URI is empty")
|
||||
}
|
||||
pool, err := pgxpool.New(ctx, dburi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rows, err := pool.Query(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
names, err := pgx.CollectRows(rows, pgx.RowTo[string])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
drop := fmt.Sprintf(`DROP DATABASE IF EXISTS "%s" WITH (FORCE)`, name)
|
||||
if _, err := pool.Exec(ctx, drop); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("dropping database", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
88
scripts/mirror-go-plugin/main.go
Normal file
88
scripts/mirror-go-plugin/main.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
// Assume it exists
|
||||
loc := flag.Arg(0)
|
||||
|
||||
dir := filepath.Join("internal", "codegen", "golang")
|
||||
err := filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newdir := filepath.Join(loc, "internal")
|
||||
newpath := strings.Replace(path, dir, newdir, 1)
|
||||
|
||||
os.MkdirAll(filepath.Dir(newpath), 0755)
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"`),
|
||||
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/opts"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/plugin"`),
|
||||
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/plugin"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/codegen/sdk"`),
|
||||
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/sdk"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/metadata"`),
|
||||
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/metadata"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/pattern"`),
|
||||
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/pattern"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/debug"`),
|
||||
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/debug"`))
|
||||
|
||||
contents = bytes.ReplaceAll(contents,
|
||||
[]byte(`"github.com/sqlc-dev/sqlc/internal/inflection"`),
|
||||
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/inflection"`))
|
||||
|
||||
if err := os.WriteFile(newpath, contents, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("error walking the path: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
path := filepath.Join("internal", "inflection", "singular.go")
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
newpath := filepath.Join(loc, "internal", "inflection", "singular.go")
|
||||
if err := os.WriteFile(newpath, contents, 0644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
59
scripts/release.go
Executable file
59
scripts/release.go
Executable file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
docker := flag.Bool("docker", false, "create a docker release")
|
||||
flag.Parse()
|
||||
|
||||
version := os.Getenv("VERSION")
|
||||
sha := os.Getenv("GITHUB_SHA")
|
||||
|
||||
if version == "" {
|
||||
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Println(strings.TrimSpace(string(out)))
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var date string
|
||||
parts := strings.Split(string(out), " ")
|
||||
date = strings.Replace(parts[0]+parts[1], "-", "", -1)
|
||||
date = strings.Replace(date, ":", "", -1)
|
||||
version = fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
|
||||
}
|
||||
|
||||
if *docker {
|
||||
x := "-extldflags \"-static\" -X github.com/sqlc-dev/sqlc/internal/cmd.version=" + version
|
||||
args := []string{
|
||||
"build",
|
||||
"-a",
|
||||
"-ldflags", x,
|
||||
"-o", "/workspace/sqlc",
|
||||
"./cmd/sqlc",
|
||||
}
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Env = os.Environ()
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Println(strings.TrimSpace(string(out)))
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
arch := flag.Arg(0)
|
||||
if arch == "" {
|
||||
log.Fatalf("missing platform_arch argument")
|
||||
}
|
||||
|
||||
log.Fatal("publishing to Equinox has been disabled")
|
||||
}
|
||||
17
scripts/report.sh
Executable file
17
scripts/report.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
curl \
|
||||
-X POST \
|
||||
--fail-with-body \
|
||||
-H "Authorization: Token token=\"$BUILDKITE_ANALYTICS_TOKEN\"" \
|
||||
-F "data=@junit.xml" \
|
||||
-F "format=junit" \
|
||||
-F "run_env[CI]=buildkite" \
|
||||
-F "run_env[key]=$GITHUB_RUN_ID" \
|
||||
-F "run_env[number]=$GITHUB_RUN_NUMBER-$GITHUB_RUN_ATTEMPT" \
|
||||
-F "run_env[job_id]=$GITHUB_RUN_ID" \
|
||||
-F "run_env[branch]=$GITHUB_REF" \
|
||||
-F "run_env[commit_sha]=$GITHUB_SHA" \
|
||||
-F "run_env[message]=Foo" \
|
||||
-F "run_env[url]=$GITHUB_SERVER_URL" \
|
||||
https://analytics-api.buildkite.com/v1/uploads
|
||||
39
scripts/test-json-process-plugin/main.go
Normal file
39
scripts/test-json-process-plugin/main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Out struct {
|
||||
Files []File `json:"files"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Name string `json:"name"`
|
||||
Contents []byte `json:"contents"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
in := make(map[string]any)
|
||||
decoder := json.NewDecoder(os.Stdin)
|
||||
err := decoder.Decode(&in)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error generating JSON: %s", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
queries := in["queries"].([]any)
|
||||
for _, q := range queries {
|
||||
text := q.(map[string]any)["text"].(string)
|
||||
buf.WriteString(text)
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
|
||||
e := json.NewEncoder(os.Stdout)
|
||||
e.SetIndent("", " ")
|
||||
e.Encode(&Out{Files: []File{{Name: "hello.txt", Contents: buf.Bytes()}}})
|
||||
}
|
||||
Reference in New Issue
Block a user