Skip to content

Commit

Permalink
fix: confix command
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
  • Loading branch information
bluebrown committed Jan 20, 2024
1 parent 1334311 commit 5108830
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 93 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@ on:
push:
branches:
- main

permissions:
contents: read
pull-requests: read

jobs:
check:
name: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: '1.21.5'
cache: false

- name: install deps
run: go mod download

- name: run checks
run: make check

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
name: image

on:
workflow_dispatch: {}
push:
branches:
- refactor/rewrite

jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Login to the container registry
run: docker login --username bluebrown --password ${{secrets.DOCKERHUB_TOKEN}}

- name: build image
run: make image
env:
DOCKER_BUILDKIT: "1"

- name: publish image
run: docker push docker.io/bluebrown/kobold --all-tags
6 changes: 0 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: release

on:
workflow_dispatch: {}
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -19,15 +16,12 @@ jobs:
with:
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json

- if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3

- if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-go@v4
with:
go-version: '1.21.5'

- if: ${{ steps.release.outputs.release_created }}
env:
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
Expand Down
2 changes: 1 addition & 1 deletion .yamlfmt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ formatter:
type: basic
indent: 2
scan_folded_as_literal: true
retain_line_breaks: true
retain_line_breaks: false
indentless_arrays: true
97 changes: 45 additions & 52 deletions build/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,47 @@
version: "2"
sql:
- engine: sqlite
queries: ../store/schema/*.query.sql
schema: ../store/schema/*.schema.sql
gen:
go:
package: model
out: ../store/model/
emit_json_tags: true
emit_empty_slices: true
emit_sql_as_comment: true

overrides:
- db_type: text
nullable: true
go_type:
import: github.com/volatiletech/null/v8
package: "null"
type: String

- column: "*.repo_uri"
go_type:
import: github.com/bluebrown/kobold/git
package: git
type: PackageURI

- column: "*.msgs"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText

- column: "*.warnings"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText

- column: "*.task_ids"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText

- column: "*.fingerprint"
go_type:
type: string

- column: "*.channels"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: JsonArray
- engine: sqlite
queries: ../store/schema/*.query.sql
schema: ../store/schema/*.schema.sql
gen:
go:
package: model
out: ../store/model/
emit_json_tags: true
emit_empty_slices: true
emit_sql_as_comment: true
overrides:
- db_type: text
nullable: true
go_type:
import: github.com/volatiletech/null/v8
package: "null"
type: String
- column: "*.repo_uri"
go_type:
import: github.com/bluebrown/kobold/git
package: git
type: PackageURI
- column: "*.msgs"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText
- column: "*.warnings"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText
- column: "*.task_ids"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: SliceText
- column: "*.fingerprint"
go_type:
type: string
- column: "*.channels"
go_type:
import: github.com/bluebrown/kobold/store
package: store
type: JsonArray
4 changes: 2 additions & 2 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func run(ctx context.Context, args []string, env []string, input io.Reader) erro
return fmt.Errorf("parse args: %w", err)
}

model, err := config.Configure(ctx, *opts, schema.TaskSchema)
query, err := config.Configure(ctx, *opts, schema.TaskSchema)
if err != nil {
return fmt.Errorf("configure: %w", err)
}

pool := task.NewPool(ctx, maxprocs, model)
pool := task.NewPool(ctx, maxprocs, query)
pool.SetHandler(handler)

if input != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func run(ctx context.Context, args []string, env []string) error {
return fmt.Errorf("parse args: %w", err)
}

model, err := config.Configure(ctx, *opts, schema.TaskSchema)
query, err := config.Configure(ctx, *opts, schema.TaskSchema)
if err != nil {
return fmt.Errorf("configure: %w", err)
}

g, ctx := errgroup.WithContext(ctx)
sched := task.NewScheduler(ctx, model, maxprocs, 5*time.Second)
sched := task.NewScheduler(ctx, query, maxprocs, 5*time.Second)

g.Go(func() error {
sched.SetHandler(handler)
Expand All @@ -79,7 +79,7 @@ func run(ctx context.Context, args []string, env []string) error {

g.Go(func() error {
apmux := http.NewServeMux()
apmux.Handle(prefix+"/api/", http.StripPrefix(prefix+"/api", api.New(prefix+"/api", model)))
apmux.Handle(prefix+"/api/", http.StripPrefix(prefix+"/api", api.New(prefix+"/api", query)))
apmux.Handle(prefix+"/metrics", promhttp.Handler())
return listenAndServeContext(ctx, "api", apiAddr, apmux)
})
Expand Down
37 changes: 35 additions & 2 deletions config/confix/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,41 @@ func MakeConfig(v1 *old.NormalizedConfig) (*config.Config, error) {
func MakeGitCredentials(v1 *old.NormalizedConfig) (string, error) {
var buf bytes.Buffer

seen := map[string]struct{}{}

for _, repo := range v1.Repositories {
if repo.Username == "" || repo.Password == "" {
continue
}

u, err := url.Parse(repo.URL)
if err != nil {
fmt.Printf("[WARN] invalid url %q: %v\n", repo.URL, err)
warn("nvalid url %q: %v\n", repo.URL, err)
continue
}
fmt.Fprintf(&buf, "%s://%s:%s@%s\n", u.Scheme, repo.Username, repo.Password, repo.URL[7:])

pw := repo.Password
us := repo.Username

if v := u.User.Username(); v != "" {
warn("repo=%q: username already set to %s\n", repo.Name, v)
us = v
}

if v, ok := u.User.Password(); ok {
warn("repo=%q: password already set\n", repo.Name)
pw = v
}

u.User = url.UserPassword(us, pw)
u.Path = ""
key := u.String()

if _, ok := seen[key]; !ok {
seen[key] = struct{}{}
fmt.Fprintf(&buf, "%s\n", key)
}

}

return buf.String(), nil
Expand All @@ -129,3 +153,12 @@ func tern[T any](cond bool, yes, no T) T {
}
return no
}

var seenw = map[string]struct{}{}

func warn(msg string, args ...interface{}) {
if _, ok := seenw[msg]; !ok {
fmt.Printf("[WARNING] "+msg+"\n", args...)
seenw[msg] = struct{}{}
}
}
37 changes: 31 additions & 6 deletions config/confix/testdata/give.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: v1

endpoints:
- name: acr
type: acr
Expand All @@ -13,13 +12,23 @@ endpoints:
- name: generic
type: generic
path: /events/generic

repositories:
- name: kobold-test
url: http://gitea.local:3000/kobold/kobold-test.git
username: ${GITEA_USER}
password: ${GITEA_PASS}

username: dev
password: dev123
- name: kobold-other
url: http://gitea.local:3000/kobold/kobold-other.git
username: dev
password: dev123
- name: azure1
url: https://myorg@dev.azure.com/myorg/myproject/_git/myrepo
username: email.com
password: password.secret
- name: azure2
url: https://myorg@dev.azure.com/myorg/myproject/_git/myrepo2
username: email.com
password: password.secret
subscriptions:
- name: e2e
endpointRefs:
Expand All @@ -32,7 +41,6 @@ subscriptions:
branch: main
strategy: commit
scopes: []

- name: pr
endpointRefs:
- name: acr
Expand All @@ -44,3 +52,20 @@ subscriptions:
- /test
- /prod
- "!/dev"
- name: azure
endpointRefs:
- name: distribution
repositoryRef:
name: azure1
branch: main
strategy: commit
scopes: []
- name: azure2
endpointRefs:
- name: acr
- name: generic
repositoryRef:
name: azure2
branch: main
strategy: pull-request
scopes: []
18 changes: 18 additions & 0 deletions config/confix/testdata/want.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,34 @@ decoder = "builtin.lines@v1"
[[pipeline]]
name = "e2e"
repo_uri = "http://gitea.local:3000/kobold/kobold-test.git@main"
dest_branch = ""
channels = ["acr", "dockerhub", "distribution", "generic"]
post_hook = ""

[[pipeline]]
name = "pr-test"
repo_uri = "http://gitea.local:3000/kobold/kobold-test.git@master/test"
dest_branch = "kobold"
channels = ["acr"]
post_hook = ""

[[pipeline]]
name = "pr-prod"
repo_uri = "http://gitea.local:3000/kobold/kobold-test.git@master/prod"
dest_branch = "kobold"
channels = ["acr"]
post_hook = ""

[[pipeline]]
name = "azure"
repo_uri = "https://myorg@dev.azure.com/myorg/myproject/_git/myrepo.git@main"
dest_branch = ""
channels = ["distribution"]
post_hook = ""

[[pipeline]]
name = "azure2"
repo_uri = "https://myorg@dev.azure.com/myorg/myproject/_git/myrepo2.git@main"
dest_branch = "kobold"
channels = ["acr", "generic"]
post_hook = "builtin.ado-pr@v1"
Loading

0 comments on commit 5108830

Please sign in to comment.