Skip to content

Commit 2ae8c13

Browse files
committed
chore(devtools): introduce dev utility script, gonyx
1 parent 4e4bf19 commit 2ae8c13

File tree

10 files changed

+242
-0
lines changed

10 files changed

+242
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "gonyx/v*.*.*"
7+
8+
jobs:
9+
pypi:
10+
runs-on: ubuntu-latest
11+
environment:
12+
name: release
13+
permissions:
14+
id-token: write
15+
strategy:
16+
matrix:
17+
os-arch:
18+
- {goos: "linux", goarch: "amd64"}
19+
- {goos: "linux", goarch: "arm64"}
20+
- {goos: "windows", goarch: "amd64"}
21+
- {goos: "windows", goarch: "arm64"}
22+
- {goos: "darwin", goarch: "amd64"}
23+
- {goos: "darwin", goarch: "arm64"}
24+
- {goos: "", goarch: ""}
25+
steps:
26+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # ratchet:actions/checkout@v6
27+
with:
28+
persist-credentials: false
29+
fetch-depth: 0
30+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # ratchet:astral-sh/setup-uv@v7
31+
with:
32+
enable-cache: false
33+
- run: |
34+
GOOS="${{ matrix.os-arch.goos }}" \
35+
GOARCH="${{ matrix.os-arch.goarch }}" \
36+
uv build --wheel
37+
- run: uv publish

tools/gonyx/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gonyx
2+
__pycache__

tools/gonyx/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `gonyx`
2+
3+
`gonyx` is [onyx.app](https://github.com/onyx-dot-app/onyx)'s devtools utility script.

tools/gonyx/cmd/cherry-pick.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cmd
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
// NewListCommand creates a new list command
9+
func NewCherryPickCommand() *cobra.Command {
10+
cmd := &cobra.Command{
11+
Use: "cherry-pick",
12+
Short: "Cherry-pick a commit to a release branch",
13+
Run: runCherryPick,
14+
}
15+
16+
return cmd
17+
}
18+
19+
func runCherryPick(cmd *cobra.Command, opts []string) {
20+
log.Debug("Debug log in runCherryPick")
21+
}

tools/gonyx/cmd/root.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
log "github.com/sirupsen/logrus"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var (
11+
Version string
12+
Commit string
13+
)
14+
15+
// RootOptions holds options for the root command
16+
type RootOptions struct {
17+
Debug bool
18+
}
19+
20+
// NewRootCommand creates the root command
21+
func NewRootCommand() *cobra.Command {
22+
opts := &RootOptions{}
23+
24+
cmd := &cobra.Command{
25+
Use: "gonyx ",
26+
Short: "Developer utilities for working on onyx.app",
27+
Run: rootCmd,
28+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
29+
if opts.Debug {
30+
log.SetLevel(log.DebugLevel)
31+
} else {
32+
log.SetLevel(log.InfoLevel)
33+
}
34+
},
35+
Version: fmt.Sprintf("%s\ncommit %s", Version, Commit),
36+
}
37+
38+
cmd.PersistentFlags().BoolVar(&opts.Debug, "debug", false, "run in debug mode")
39+
40+
// Add subcommands
41+
cmd.AddCommand(NewCherryPickCommand())
42+
43+
return cmd
44+
}
45+
46+
func rootCmd(cmd *cobra.Command, args []string) {
47+
log.Debug("Debug log in rootCmd")
48+
}

tools/gonyx/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/onyx-dot-app/onyx/tools/gonyx
2+
3+
go 1.25.4
4+
5+
require (
6+
github.com/sirupsen/logrus v1.9.3
7+
github.com/spf13/cobra v1.10.1
8+
)
9+
10+
require (
11+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
12+
github.com/spf13/pflag v1.0.9 // indirect
13+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
14+
)

tools/gonyx/go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
6+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
10+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
11+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
12+
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
13+
github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0=
14+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
15+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
16+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
17+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
18+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
20+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
24+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

tools/gonyx/hatch_build.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import subprocess
5+
6+
import manygo
7+
from hatchling.builders.hooks.plugin import interface
8+
9+
10+
class GoBinaryBuildHook(interface.BuildHookInterface):
11+
def initialize(self, version, build_data) -> None: # noqa: ANN001, ARG002
12+
build_data["pure_python"] = False
13+
goos = os.getenv("GOOS")
14+
goarch = os.getenv("GOARCH")
15+
if goos and goarch:
16+
build_data["tag"] = "py3-none-" + manygo.get_platform_tag(goos=goos, goarch=goarch) # type: ignore[invalid-argument-type]
17+
binary_name = self.config["binary_name"]
18+
tag = os.getenv("GITHUB_REF_NAME", "dev").lstrip("gonyx/")
19+
commit = os.getenv("GITHUB_SHA", "none")
20+
21+
if not os.path.exists(binary_name):
22+
print(f"Building Go binary '{binary_name}'...")
23+
subprocess.check_call( # noqa: S603
24+
[
25+
"go",
26+
"build",
27+
f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w",
28+
"-o",
29+
binary_name,
30+
],
31+
)
32+
33+
build_data["shared_scripts"] = {binary_name: binary_name}

tools/gonyx/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/onyx-dot-app/onyx/tools/gonyx/cmd"
8+
)
9+
10+
var (
11+
version = "dev"
12+
commit = "none"
13+
)
14+
15+
func main() {
16+
// Set the version in the cmd package
17+
cmd.Version = version
18+
cmd.Commit = commit
19+
20+
rootCmd := cmd.NewRootCommand()
21+
22+
if err := rootCmd.Execute(); err != nil {
23+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
24+
os.Exit(2)
25+
}
26+
}

tools/gonyx/pyproject.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[build-system]
2+
requires = ["hatchling", "hatch-vcs", "go-bin~=1.24", "manygo"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "onyx-devtools"
7+
description = "Developer utilities for working on onyx.app"
8+
license = {file = "../../LICENSE"}
9+
authors = [{ name = "Onyx AI", email = "founders@onyx.app" }]
10+
readme = "README.md"
11+
requires-python = ">=3.9"
12+
keywords = [
13+
"onyx", "cli", "devtools", "tools", "tooling",
14+
]
15+
classifiers = [
16+
"Programming Language :: Go",
17+
"License :: OSI Approved :: MIT License",
18+
"Operating System :: OS Independent",
19+
]
20+
dynamic = ["version"]
21+
22+
23+
[project.urls]
24+
Repository = "https://github.com/onyx-dot-app/onyx"
25+
26+
[tool.hatch.build]
27+
include = ["go.mod", "go.sum", "main.go"]
28+
29+
[tool.hatch.version]
30+
source = "vcs"
31+
tag-pattern = "gonyx/v(?P<version>\\d+\\.\\d+\\.\\d+)"
32+
33+
[tool.hatch.build.hooks.custom]
34+
binary_name = "gonyx"

0 commit comments

Comments
 (0)