diff --git a/Makefile b/Makefile index bef5b21..ac3c104 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,18 @@ -BINARY := ./bin/photoscli -MODULE := gitea.k3s.k0.nu/tools/photocli +BINARY := ./bin/photoscli +MODULE := gitea.k3s.k0.nu/tools/photocli +VERSION := 0.1.0 BRIDGE_DIR := bridge -OBJ := $(BRIDGE_DIR)/photokit_bridge.o -LIB := $(BRIDGE_DIR)/libphotokit_bridge.a -STUB_OBJ := $(BRIDGE_DIR)/photokit_bridge_stub.o -STUB_LIB := $(BRIDGE_DIR)/libphotokit_bridge_stub.a +LDFLAGS := -X main.version=$(VERSION) +OBJ := $(BRIDGE_DIR)/photokit_bridge.o +LIB := $(BRIDGE_DIR)/libphotokit_bridge.a +STUB_OBJ := $(BRIDGE_DIR)/photokit_bridge_stub.o +STUB_LIB := $(BRIDGE_DIR)/libphotokit_bridge_stub.a +GITEA_HOST := gitea-1.tail82444.ts.net +GITEA_REPO := tools/photocli -.PHONY: build clean test coverage +.PHONY: all build clean test coverage tag release + +all: build $(LIB): $(OBJ) ar rcs $@ $< @@ -21,7 +27,7 @@ $(STUB_OBJ): $(BRIDGE_DIR)/photokit_bridge_stub.c $(BRIDGE_DIR)/photokit_bridge. cc -c -o $@ $< build: $(LIB) - go build -o $(BINARY) $(MODULE)/cmd/photoscli + go build -ldflags "$(LDFLAGS)" -o $(BINARY) $(MODULE)/cmd/photoscli test: $(STUB_LIB) go test -tags=test -coverprofile=coverage.out -covermode=atomic -coverpkg=./... ./... @@ -36,4 +42,23 @@ coverage: $(STUB_LIB) go tool cover -func=coverage.out clean: - rm -f $(BINARY) $(OBJ) $(LIB) $(STUB_OBJ) $(STUB_LIB) coverage.out \ No newline at end of file + rm -f $(BINARY) $(OBJ) $(LIB) $(STUB_OBJ) $(STUB_LIB) coverage.out + +tag: + git tag v$(VERSION) + git push origin v$(VERSION) + +release: build tag +ifndef GITEA_TOKEN + $(error GITEA_TOKEN is required. Set it with: export GITEA_TOKEN=your-token) +endif + curl -sf -X POST "https://$(GITEA_HOST)/api/v1/repos/$(GITEA_REPO)/releases" \ + -H "Authorization: token $(GITEA_TOKEN)" \ + -H "Content-Type: application/json" \ + -d '{"tag_name":"v$(VERSION)","name":"v$(VERSION)","body":"photoscli v$(VERSION)"}' | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['id'])" > /tmp/_photoscli_release_id + @echo "created release v$(VERSION)" + curl -sf -X POST "https://$(GITEA_HOST)/api/v1/repos/$(GITEA_REPO)/releases/$$(cat /tmp/_photoscli_release_id)/assets?name=photoscli" \ + -H "Authorization: token $(GITEA_TOKEN)" \ + -F "attachment=@$(BINARY)" + @echo "uploaded $(BINARY) to release v$(VERSION)" + @rm -f /tmp/_photoscli_release_id \ No newline at end of file diff --git a/cmd/photoscli/main.go b/cmd/photoscli/main.go index 41a038d..07ef624 100644 --- a/cmd/photoscli/main.go +++ b/cmd/photoscli/main.go @@ -26,6 +26,9 @@ func run(args []string, stdout, stderr io.Writer, bridge photos.Bridge) int { return cmdBackupAll(args[1:], stdout, stderr, bridge) case "export": return cmdExport(args[1:], stdout, stderr, bridge) + case "version", "--version", "-v": + fmt.Fprintln(stdout, version) + return 0 case "help", "--help", "-h": usage(stderr) return 0 @@ -45,6 +48,7 @@ Usage: photoscli tree photoscli backup-all --out [--size ] [--originals] photoscli export --album-id --out [--size ] [--originals] + photoscli version Commands: albums List user-created albums @@ -52,6 +56,7 @@ Commands: tree Show folder and album hierarchy backup-all Export all albums into the Photos folder tree export Export optimized JPEG previews or original files + version Print version Flags: --album-id Album local identifier or title (required for photos/export) diff --git a/cmd/photoscli/main_main.go b/cmd/photoscli/main_main.go index b13f8d2..283f162 100644 --- a/cmd/photoscli/main_main.go +++ b/cmd/photoscli/main_main.go @@ -8,6 +8,8 @@ import ( "gitea.k3s.k0.nu/tools/photocli/internal/photos" ) +var version = "dev" + func main() { sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) diff --git a/cmd/photoscli/main_test.go b/cmd/photoscli/main_test.go index 954248f..7c1d809 100644 --- a/cmd/photoscli/main_test.go +++ b/cmd/photoscli/main_test.go @@ -106,6 +106,18 @@ func TestRunHelp(t *testing.T) { } } +func TestRunVersion(t *testing.T) { + for _, cmd := range []string{"version", "--version", "-v"} { + out, _, rc := runWith([]string{cmd}, &mockBridge{}) + if rc != 0 { + t.Errorf("%s: rc = %d, want 0", cmd, rc) + } + if out == "" { + t.Errorf("%s: output is empty", cmd) + } + } +} + func TestRunUnknownCommand(t *testing.T) { _, stderr, rc := runWith([]string{"foo"}, &mockBridge{}) if rc != 1 {