From 6dedc317b068a88b7b27d4501d0acfa4653dff13 Mon Sep 17 00:00:00 2001 From: "A. Ottr" Date: Sat, 24 Jan 2026 01:04:43 +0100 Subject: [PATCH] fix: streamline release process Signed-off-by: A. Ottr --- .goreleaser.yml | 40 ++++++++++++ .nox.yaml | 44 ++++++------- Makefile | 60 ++++++++++++++++-- cmd/nox/main.go | 119 +++++++++++++++++++----------------- internal/version/version.go | 8 +++ 5 files changed, 186 insertions(+), 85 deletions(-) create mode 100644 .goreleaser.yml create mode 100644 internal/version/version.go diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..a89d672 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,40 @@ +version: 2 + +project_name: nox + +builds: + - id: nox + main: ./cmd/nox + binary: nox + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + env: + - CGO_ENABLED=0 + ldflags: + - -s -w + - -X github.com/aottr/nox/internal/version.Version={{.Version}} + - -X github.com/aottr/nox/internal/version.Commit={{.Commit}} + - -X github.com/aottr/nox/internal/version.BuildDate={{.Date}} + +archives: + - id: default + files: + - README.md + - LICENSE + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + github: + owner: aottr + name: nox + diff --git a/.nox.yaml b/.nox.yaml index a74eb57..8e89e81 100644 --- a/.nox.yaml +++ b/.nox.yaml @@ -1,24 +1,24 @@ -interval: "10m" -age: - identity: "keys/key.txt" - recipients: - - "age1qq5sazxv755u2vs5ulyl486jxhlg7ztrvm27nya47aln668xldkqsm4kn5" -statePath: ".nox-state.json" +interval: 10m +age: + identity: keys/key.txt + identities: [] + recipients: + - age1qq5sazxv755u2vs5ulyl486jxhlg7ztrvm27nya47aln668xldkqsm4kn5 +statePath: .nox-state.json git: - repo: git@github.com:ShorkBytes/nox-secrets.git - branch: main -apps: - debug: - git: - repo: git@github.com:ShorkBytes/nox-secrets.git - branch: main - files: - - path: debug/debug.age - output: ./secrets/.env - - debug2: - branch: main repo: git@github.com:ShorkBytes/nox-secrets.git - files: - - path: debug/debug.age - output: ./secrets/debug2.env \ No newline at end of file + branch: main +apps: + debug: + git: + repo: git@github.com:ShorkBytes/nox-secrets.git + branch: main + files: + - path: debug/debug.age + output: ./secrets/.env + debug2: + files: + - path: debug/debug.age + output: ./secrets/debug2.env + testApp: + files: [] diff --git a/Makefile b/Makefile index 50991d6..99cf657 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,56 @@ -.PHONY: build +.PHONY: major minor patch -build: - @go build -o bin/nox ./cmd/nox/main.go +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") +BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) -.PHONY: run -run: build - @./bin/nox \ No newline at end of file +LDFLAGS = -s -w \ + -X github.com/aottr/nox/internal/version.Version=$(VERSION) \ + -X github.com/aottr/nox/internal/version.Commit=$(COMMIT) \ + -X github.com/aottr/nox/internal/version.BuildDate=$(BUILD_DATE) + +# Get current version tag (removes 'v' prefix if present, defaults to 0.0.0) +CURRENT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0") +CURRENT_MAJOR := $(shell echo "$(CURRENT_TAG)" | awk -F. '{print $$1}' | grep -E '^[0-9]+$$' || echo "0") +CURRENT_MINOR := $(shell echo "$(CURRENT_TAG)" | awk -F. '{print $$2}' | grep -E '^[0-9]+$$' || echo "0") +CURRENT_PATCH := $(shell echo "$(CURRENT_TAG)" | awk -F. '{print $$3}' | grep -E '^[0-9]+$$' || echo "0") + + +major: + @CURRENT="$(CURRENT_TAG)"; \ + if [ -z "$$CURRENT" ] || [ "$$CURRENT" = "0.0.0" ]; then \ + NEW_VERSION="1.0.0"; \ + else \ + MAJOR=$$(echo "$$CURRENT" | awk -F. '{print $$1}'); \ + NEW_VERSION="$$(($$MAJOR + 1)).0.0"; \ + fi; \ + echo "Bumping major version: $$CURRENT -> $$NEW_VERSION"; \ + git tag -s "v$$NEW_VERSION" -m "Release v$$NEW_VERSION"; \ + echo "Created signed tag v$$NEW_VERSION. Push with: git push origin v$$NEW_VERSION" + +minor: + @CURRENT="$(CURRENT_TAG)"; \ + if [ -z "$$CURRENT" ] || [ "$$CURRENT" = "0.0.0" ]; then \ + NEW_VERSION="0.1.0"; \ + else \ + MAJOR=$$(echo "$$CURRENT" | awk -F. '{print $$1}'); \ + MINOR=$$(echo "$$CURRENT" | awk -F. '{print $$2}'); \ + NEW_VERSION="$$MAJOR.$$(($$MINOR + 1)).0"; \ + fi; \ + echo "Bumping minor version: $$CURRENT -> $$NEW_VERSION"; \ + git tag -s "v$$NEW_VERSION" -m "Release v$$NEW_VERSION"; \ + echo "Created signed tag v$$NEW_VERSION. Push with: git push origin v$$NEW_VERSION" + +patch: + @CURRENT="$(CURRENT_TAG)"; \ + if [ -z "$$CURRENT" ] || [ "$$CURRENT" = "0.0.0" ]; then \ + NEW_VERSION="0.0.1"; \ + else \ + MAJOR=$$(echo "$$CURRENT" | awk -F. '{print $$1}'); \ + MINOR=$$(echo "$$CURRENT" | awk -F. '{print $$2}'); \ + PATCH=$$(echo "$$CURRENT" | awk -F. '{print $$3}'); \ + NEW_VERSION="$$MAJOR.$$MINOR.$$(($$PATCH + 1))"; \ + fi; \ + echo "Bumping patch version: $$CURRENT -> $$NEW_VERSION"; \ + git tag -s "v$$NEW_VERSION" -m "Release v$$NEW_VERSION"; \ + echo "Created signed tag v$$NEW_VERSION. Push with: git push origin v$$NEW_VERSION" diff --git a/cmd/nox/main.go b/cmd/nox/main.go index d781108..1b47e2f 100644 --- a/cmd/nox/main.go +++ b/cmd/nox/main.go @@ -128,33 +128,70 @@ func main() { }, { Name: "generate", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "output", - Usage: "path to output file", - Aliases: []string{"o"}, - Value: constants.StandardOutput, - Destination: &outputPath, - }, - }, - Action: func(ctx context.Context, cmd *cli.Command) error { + Commands: []*cli.Command{ + { + Name: "key", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "output", + Usage: "path to output file", + Aliases: []string{"o"}, + Value: constants.StandardOutput, + Destination: &outputPath, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { - output := cmd.String("output") - switch output { - case constants.StandardOutput: - priv, pub, err := crypto.GenerateIdentity("") - if err != nil { - return err - } - fmt.Println("Public key:\n", pub, "\nPrivate Key:\n", priv) - default: - _, _, err := crypto.GenerateIdentity(cmd.String("output")) - if err != nil { - return err - } - } + output := cmd.String("output") + switch output { + case constants.StandardOutput: + priv, pub, err := crypto.GenerateIdentity("") + if err != nil { + return err + } + fmt.Println("Public key:\n", pub, "\nPrivate Key:\n", priv) + default: + _, _, err := crypto.GenerateIdentity(cmd.String("output")) + if err != nil { + return err + } + } - return nil + return nil + }, + }, + { + Name: "config", + Usage: "Initialize a new config or app", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "app", + Usage: "name of the app", + }, + &cli.StringFlag{ + Name: "repo", + Usage: "git repository url", + }, + &cli.StringFlag{ + Name: "branch", + Value: "main", + Usage: "git branch", + }, + &cli.StringFlag{ + Name: "key", + Usage: "path to age key", + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { + return config.InitConfig( + configPath, + cmd.String("app"), + cmd.String("repo"), + cmd.String("branch"), + cmd.String("key"), + ) + }, + }, }, }, { @@ -217,38 +254,6 @@ func main() { return processor.ValidateConfig(rtx.Config) }, }, - { - Name: "init", - Usage: "Initialize a new config or app", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "app", - Usage: "name of the app", - }, - &cli.StringFlag{ - Name: "repo", - Usage: "git repository url", - }, - &cli.StringFlag{ - Name: "branch", - Value: "main", - Usage: "git branch", - }, - &cli.StringFlag{ - Name: "key", - Usage: "path to age key", - }, - }, - Action: func(ctx context.Context, cmd *cli.Command) error { - return config.InitConfig( - configPath, - cmd.String("app"), - cmd.String("repo"), - cmd.String("branch"), - cmd.String("key"), - ) - }, - }, { Name: "watch", Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..0883e88 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,8 @@ +package version + +var ( + Version = "dev" + Commit = "unknown" + BuildDate = "unknown" +) + -- 2.51.2