Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/changed-projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: changed-projects

on:
workflow_call:
outputs:
projects:
description: Changed projects as JSON array
value: ${{ jobs.changes.outputs.projects }}

jobs:
changes:
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.projects.outputs.projects }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Detect changed projects
id: filter
uses: dorny/paths-filter@v3
with:
filters: |
plugin_insert_checker:
- 'src/plugin-insert-checker/**'
plugin_gen_ts:
- 'src/plugin-gen-ts/**'

- name: Build project matrix
id: projects
run: |
projects='[]'

if [ "${{ steps.filter.outputs.plugin_insert_checker }}" = "true" ]; then
projects=$(echo "$projects" | jq -c '. + ["plugin-insert-checker"]')
fi

if [ "${{ steps.filter.outputs.plugin_gen_ts }}" = "true" ]; then
projects=$(echo "$projects" | jq -c '. + ["plugin-gen-ts"]')
fi

echo "projects=$projects" >> "$GITHUB_OUTPUT"
31 changes: 27 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: release

on:
push:
tags:
Expand All @@ -8,17 +9,39 @@ jobs:
build:
runs-on: ubuntu-latest
container: golang:1.26

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.SQLC_RELEASE }}
fetch-depth: 0

- name: build
- name: Extract project from tag
id: project
shell: bash
run: |
tag="${GITHUB_REF_NAME}"

if [[ ! "$tag" =~ ^[a-zA-Z0-9._-]+-v[0-9].*$ ]]; then
echo "Unsupported release tag: $tag" >&2
exit 1
fi

project="${tag%-v*}"

if [ ! -d "src/$project" ]; then
echo "Project directory does not exist: src/$project" >&2
exit 1
fi

echo "name=$project" >> "$GITHUB_OUTPUT"
echo "wasm=src/$project/$project.wasm" >> "$GITHUB_OUTPUT"

- name: Build ${{ steps.project.outputs.name }}
run: |
cd src/pluging-insert-checker
GOOS=wasip1 GOARCH=wasm go build -buildvcs=false -o pluging-insert-checker.wasm
cd "src/${{ steps.project.outputs.name }}"
GOOS=wasip1 GOARCH=wasm go build -buildvcs=false -o "${{ steps.project.outputs.name }}.wasm"

- name: Release
uses: softprops/action-gh-release@v2
Expand All @@ -27,6 +50,6 @@ jobs:
name: "Release ${{ github.ref_name }}"
body: "Automated release for ${{ github.ref_name }}"
files: |
src/pluging-insert-checker/pluging-insert-checker.wasm
${{ steps.project.outputs.wasm }}
env:
GITHUB_TOKEN: ${{ secrets.SQLC_RELEASE }}
22 changes: 17 additions & 5 deletions .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
name: tag

on:
push:
branches: [main]

jobs:
changes:
uses: ./.github/workflows/changed-projects.yml

tag:
needs: changes
if: needs.changes.outputs.projects != '[]'
runs-on: ubuntu-latest
container: golang:1.26

strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.changes.outputs.projects) }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.SQLC_RELEASE }}
fetch-depth: 0

- name: build
- name: Build ${{ matrix.project }}
run: |
cd src/pluging-insert-checker
go build -buildvcs=false -o pluging-insert-checker
cd "src/${{ matrix.project }}"
go build -buildvcs=false -o "${{ matrix.project }}"

- name: tag
- name: Tag ${{ matrix.project }}
run: |
git config --global --add safe.directory /__w/sqlc/sqlc
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

git fetch --tags
./tag.sh pluging-insert-checker
./tag.sh "${{ matrix.project }}"
git push origin --tags
21 changes: 16 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
name: test

on:
pull_request:
branches: [main]

jobs:
changes:
uses: ./.github/workflows/changed-projects.yml

test:
needs: changes
if: needs.changes.outputs.projects != '[]'
runs-on: ubuntu-latest
container: golang:1.26

strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.changes.outputs.projects) }}

steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: build
- name: Build ${{ matrix.project }}
run: |
cd src/pluging-insert-checker
go build -buildvcs=false -o pluging-insert-checker
cd "src/${{ matrix.project }}"
go build -buildvcs=false -o "${{ matrix.project }}"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To create a new plugin:
3. Implement your plugin logic

```
package pluging-name
package plugin-name

func main() {
codegen.Run(generate)
Expand Down
15 changes: 15 additions & 0 deletions src/plugin-gen-ts/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module plugin-gen-ts

go 1.26.3

require github.com/sqlc-dev/plugin-sdk-go v1.23.0

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
File renamed without changes.
76 changes: 76 additions & 0 deletions src/plugin-gen-ts/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"

"github.com/sqlc-dev/plugin-sdk-go/codegen"
"github.com/sqlc-dev/plugin-sdk-go/plugin"
)

func main() {
codegen.Run(generate)
}

type Options struct {
TargetLang string `json:"target_lang"`
}

func generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) {
f, err := os.OpenFile("./sqlc-plugin.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
defer f.Close()

if len(req.PluginOptions) == 0 {
return nil, nil
}

var opts Options
if err := json.Unmarshal([]byte(req.PluginOptions), &opts); err != nil {
return nil, err
}

if opts.TargetLang != "ts" {
return &plugin.GenerateResponse{}, nil
}

files := make(map[string][]string)

for _, queries := range req.Queries {
fmt.Fprintf(f, "Processing queries for file: %s\n", queries.Filename)
fmt.Fprintf(f, "Name: %v\n", queries.Name)
fmt.Fprintf(f, "Cmd: %v\n", queries.Cmd)
for _, cols := range queries.Columns {
fmt.Fprintf(f, "Column: %v\n", cols.Name)
}
for _, params := range queries.Params {
fmt.Fprintf(f, "Param: %v\n", params.Column.Name)
}

if files[queries.Filename] == nil {
files[queries.Filename] = []string{}
}
query := fmt.Sprintf("export const %s = `%s`\n", queries.Name, queries.Text)
files[queries.Filename] = append(files[queries.Filename], query)
}

var filesGenerated []*plugin.File

for filename := range files {
contents := fmt.Sprintf("// This file is generated by sqlc plugin-gen-ts. DO NOT EDIT.\n\n%s", strings.Join(files[filename], "\n"))
filesGenerated = append(filesGenerated, &plugin.File{
Name: filename + ".ts",
Contents: []byte(contents),
})
fmt.Fprintf(f, "Generated file: %s\n", filename+".ts")
}

return &plugin.GenerateResponse{
Files: filesGenerated,
}, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module pluging-insert-checker
module plugin-insert-checker

go 1.26.1

Expand Down
23 changes: 23 additions & 0 deletions src/plugin-insert-checker/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/sqlc-dev/plugin-sdk-go v1.23.0 h1:iSeJhnXPlbDXlbzUEebw/DxsGzE9rdDJArl8Hvt0RMM=
github.com/sqlc-dev/plugin-sdk-go v1.23.0/go.mod h1:I1r4THOfyETD+LI2gogN2LX8wCjwUZrgy/NU4In3llA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
File renamed without changes.
Loading