Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments
  (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins).
  External dep kept: formancehq/go-libs.
- plugins: each ce/plugins/* consumed a *published* pkg/domain; added local
  'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every
  standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too.
- branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added),
  goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage),
  proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl.
- CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml +
  cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet).
- kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type
  client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image.
- verified: go build ./... (default + -tags ee) + all 20 nested modules green.
2026-07-05 13:08:55 -07:00

147 lines
4.0 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"golang.org/x/mod/modfile"
)
const repoModule = "github.com/hanzo-fi/payments"
func main() {
connectorDirPath := flag.String("connector-dir-path", "", "Path to the plugins directory (e.g. ce/plugins or ee/plugins)")
flag.Parse()
if *connectorDirPath == "" {
log.Fatal("connector-dir-path flag is required")
}
pluginsDir, err := filepath.Abs(*connectorDirPath)
if err != nil {
log.Fatal(err)
}
// connector-dir-path is always <repo-root>/{ce,ee}/plugins, so repo root is two levels up.
repoRoot := filepath.Dir(filepath.Dir(pluginsDir))
relPluginsDir, err := filepath.Rel(repoRoot, pluginsDir)
if err != nil {
log.Fatalf("computing plugins dir relative path: %v", err)
}
pluginsPrefix := repoModule + "/" + filepath.ToSlash(relPluginsDir) + "/"
rootModPath := filepath.Join(repoRoot, "go.mod")
rootModData, err := os.ReadFile(rootModPath)
if err != nil {
log.Fatalf("reading root go.mod: %v", err)
}
rootMod, err := modfile.Parse(rootModPath, rootModData, nil)
if err != nil {
log.Fatalf("parsing root go.mod: %v", err)
}
// Collect live plugins: module path -> relative dir (e.g. "ce/plugins/adyen")
live := map[string]string{}
entries, err := os.ReadDir(pluginsDir)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("reading %s: %v", pluginsDir, err)
}
for _, e := range entries {
if !e.IsDir() {
continue
}
modPath := filepath.Join(pluginsDir, e.Name(), "go.mod")
data, err := os.ReadFile(modPath)
if err != nil {
continue // no go.mod yet, skip
}
f, err := modfile.Parse(modPath, data, nil)
if err != nil {
log.Printf("warning: parsing %s: %v", modPath, err)
continue
}
if strings.HasPrefix(f.Module.Mod.Path, pluginsPrefix) {
rel, err := filepath.Rel(repoRoot, filepath.Join(pluginsDir, e.Name()))
if err != nil {
log.Fatalf("computing relative path: %v", err)
}
live[f.Module.Mod.Path] = filepath.ToSlash(rel)
}
}
changed := false
// Drop stale replace/require entries for ce/plugins that no longer exist.
// Iterate over copies since we modify the slices.
for _, r := range append([]*modfile.Replace(nil), rootMod.Replace...) {
if !strings.HasPrefix(r.Old.Path, pluginsPrefix) {
continue
}
if _, ok := live[r.Old.Path]; !ok {
fmt.Printf("dropping stale replace: %s\n", r.Old.Path)
if err := rootMod.DropReplace(r.Old.Path, r.Old.Version); err != nil {
log.Fatalf("drop replace %s: %v", r.Old.Path, err)
}
changed = true
}
}
for _, r := range append([]*modfile.Require(nil), rootMod.Require...) {
if !strings.HasPrefix(r.Mod.Path, pluginsPrefix) {
continue
}
if _, ok := live[r.Mod.Path]; !ok {
fmt.Printf("dropping stale require: %s\n", r.Mod.Path)
if err := rootMod.DropRequire(r.Mod.Path); err != nil {
log.Fatalf("drop require %s: %v", r.Mod.Path, err)
}
changed = true
}
}
// Index existing directives for O(1) lookup.
existingReplaces := map[string]bool{}
for _, r := range rootMod.Replace {
existingReplaces[r.Old.Path] = true
}
existingRequires := map[string]bool{}
for _, r := range rootMod.Require {
existingRequires[r.Mod.Path] = true
}
// Add missing replace and require entries.
for modPath, relDir := range live {
if !existingReplaces[modPath] {
fmt.Printf("adding replace: %s => ./%s\n", modPath, relDir)
if err := rootMod.AddReplace(modPath, "", "./"+relDir, ""); err != nil {
log.Fatalf("add replace %s: %v", modPath, err)
}
changed = true
}
if !existingRequires[modPath] {
fmt.Printf("adding require: %s\n", modPath)
if err := rootMod.AddRequire(modPath, "v0.0.0-00010101000000-000000000000"); err != nil {
log.Fatalf("add require %s: %v", modPath, err)
}
changed = true
}
}
if !changed {
return
}
rootMod.Cleanup()
out, err := rootMod.Format()
if err != nil {
log.Fatalf("formatting go.mod: %v", err)
}
if err := os.WriteFile(rootModPath, out, 0644); err != nil {
log.Fatalf("writing go.mod: %v", err)
}
fmt.Println("go.mod updated")
}