From 0f168946c7bda24e9bfbe0b1fe86d4f0c88ed6b2 Mon Sep 17 00:00:00 2001 From: Berger Eugene Date: Sat, 24 Dec 2022 23:20:48 +0200 Subject: [PATCH 1/2] Added version command - prints process-compose version and build info --- .goreleaser.yaml | 6 +++++- Makefile | 13 ++++++++++--- default.nix | 20 ++++++++++++++------ flake.nix | 4 +++- src/cmd/version.go | 30 ++++++++++++++++++++++++++++++ src/config/config.go | 9 +++++++-- 6 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/cmd/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f50d755..0ad08ea 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -29,7 +29,11 @@ builds: goarch: arm dir: src ldflags: - - -X github.com/f1bonacc1/process-compose/src/config.Version={{.Tag}} -X github.com/f1bonacc1/process-compose/src/config.CheckForUpdates=true -s -w + - -X github.com/f1bonacc1/process-compose/src/config.Version={{.Tag}} + - -X github.com/f1bonacc1/process-compose/src/config.CheckForUpdates=true + - -X github.com/f1bonacc1/process-compose/src/config.Commit={{.ShortCommit}} + - -X github.com/f1bonacc1/process-compose/src/config.Date={{.Date}} + - -s -w archives: - replacements: darwin: Darwin diff --git a/Makefile b/Makefile index 64a98e0..4a1323f 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,16 @@ NAME=process-compose RM=rm VERSION = $(shell git describe --abbrev=0) +GIT_REV ?= $(shell git rev-parse --short HEAD) +DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") NUMVER = $(shell echo ${VERSION} | cut -d"v" -f 2) -PKG = github.com/f1bonacc1/process-compose +PKG = github.com/f1bonacc1/${NAME} SHELL := /bin/bash -LD_FLAGS := -ldflags="-X ${PKG}/src/config.Version=${VERSION} -X ${PKG}/src/config.CheckForUpdates=true -s -w" - +LD_FLAGS := -ldflags="-X ${PKG}/src/config.Version=${VERSION} \ + -X ${PKG}/src/config.CheckForUpdates=true \ + -X ${PKG}/src/config.Commit=${GIT_REV} \ + -X ${PKG}/src/config.Date=${DATE} \ + -s -w" ifeq ($(OS),Windows_NT) EXT=.exe RM = cmd /C del /Q /F @@ -58,3 +63,5 @@ clean: release: source exports goreleaser release --rm-dist --skip-validate +snapshot: + goreleaser release --snapshot --rm-dist diff --git a/default.nix b/default.nix index baadcad..2ae456b 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,18 @@ -{ buildGoModule, config, lib, pkgs, installShellFiles, version ? "latest" }: +{ buildGoModule, config, lib, pkgs, installShellFiles, date, commit }: -buildGoModule { +buildGoModule rec { pname = "process-compose"; - version = version; + version = "0.29.1"; + pkg = "github.com/f1bonacc1/process-compose/src/config"; + src = ./.; - ldflags = [ "-X github.com/f1bonacc1/process-compose/src/config.Version=v${version} -s -w" ]; + ldflags = [ + "-X ${pkg}.Version=v${version}" + "-X ${pkg}.Date=${date}" + "-X ${pkg}.Commit=${commit}" + "-s" + "-w" + ]; nativeBuildInputs = [ installShellFiles ]; @@ -21,9 +29,9 @@ buildGoModule { ''; meta = with lib; { - description = - "Process Compose is like docker-compose, but for orchestrating a suite of processes, not containers."; + description = "A simple and flexible scheduler and orchestrator to manage non-containerized applications"; homepage = "https://github.com/F1bonacc1/process-compose"; + changelog = "https://github.com/F1bonacc1/process-compose/releases/tag/v${version}"; license = licenses.asl20; mainProgram = "process-compose"; }; diff --git a/flake.nix b/flake.nix index aebd8b6..5f68924 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,9 @@ in { overlays.default = final: prev: { process-compose = final.callPackage ./default.nix { - version = self.shortRev or "dirty"; + #version = self.shortRev or "dirty"; + date = self.lastModifiedDate; + commit = self.shortRev or "dirty"; }; }; overlay = self.overlays.default; diff --git a/src/cmd/version.go b/src/cmd/version.go new file mode 100644 index 0000000..1b2ecf7 --- /dev/null +++ b/src/cmd/version.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "fmt" + "github.com/f1bonacc1/process-compose/src/config" + "github.com/spf13/cobra" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version and build info", + Run: func(cmd *cobra.Command, args []string) { + printVersion() + }, +} + +func printVersion() { + format := "%-15s %s\n" + fmt.Println("Process Compose") + fmt.Printf(format, "Version:", config.Version) + fmt.Printf(format, "Commit:", config.Commit) + fmt.Printf(format, "Date (UTC):", config.Date) + fmt.Printf(format, "License:", config.License) + fmt.Println("\nWritten by Eugene Berger") +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/src/config/config.go b/src/config/config.go index a53aba9..cf52d5c 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -9,8 +9,13 @@ import ( "path/filepath" ) -var Version = "undefined" -var CheckForUpdates = "false" +var ( + Version = "undefined" + Commit = "undefined" + Date = "undefined" + CheckForUpdates = "false" + License = "Apache-2.0" +) const ( pcConfigEnv = "PROC_COMP_CONFIG" From 89254f1dac4219e30127790cf424574df7de8fd0 Mon Sep 17 00:00:00 2001 From: Berger Eugene Date: Sun, 25 Dec 2022 22:00:50 +0200 Subject: [PATCH 2/2] Represent the last commit date instead of build date --- .goreleaser.yaml | 2 +- Makefile | 2 +- default.nix | 6 ++++-- flake.lock | 12 +++++++----- flake.nix | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 0ad08ea..ac716c4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -32,7 +32,7 @@ builds: - -X github.com/f1bonacc1/process-compose/src/config.Version={{.Tag}} - -X github.com/f1bonacc1/process-compose/src/config.CheckForUpdates=true - -X github.com/f1bonacc1/process-compose/src/config.Commit={{.ShortCommit}} - - -X github.com/f1bonacc1/process-compose/src/config.Date={{.Date}} + - -X github.com/f1bonacc1/process-compose/src/config.Date={{.CommitDate}} - -s -w archives: - replacements: diff --git a/Makefile b/Makefile index 4a1323f..80eb486 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME=process-compose RM=rm VERSION = $(shell git describe --abbrev=0) GIT_REV ?= $(shell git rev-parse --short HEAD) -DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +DATE ?= $(shell TZ=UTC0 git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd") NUMVER = $(shell echo ${VERSION} | cut -d"v" -f 2) PKG = github.com/f1bonacc1/${NAME} SHELL := /bin/bash diff --git a/default.nix b/default.nix index 2ae456b..288d08d 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,13 @@ { buildGoModule, config, lib, pkgs, installShellFiles, date, commit }: +let pkg = "github.com/f1bonacc1/process-compose/src/config"; +in buildGoModule rec { pname = "process-compose"; version = "0.29.1"; - pkg = "github.com/f1bonacc1/process-compose/src/config"; - src = ./.; + + src = lib.cleanSource ./.; ldflags = [ "-X ${pkg}.Version=v${version}" "-X ${pkg}.Date=${date}" diff --git a/flake.lock b/flake.lock index d7d454d..9111c10 100644 --- a/flake.lock +++ b/flake.lock @@ -17,16 +17,18 @@ }, "nixpkgs": { "locked": { - "lastModified": 1666837999, - "narHash": "sha256-hI7+s1UVDsJNqNn9UGV6xTBGqMC4dqOyVpeDf+su7JU=", + "lastModified": 1671971468, + "narHash": "sha256-dbToieyk3ym62lpO1ZZSPN+az/sBMmP05VAJcbb5PkM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1c6eb4876f71e8903ae9f73e6adf45fdbebc0292", + "rev": "266927206388a73cb3dcfdc9bce73a381e3e1faf", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "release-22.11", + "repo": "nixpkgs", + "type": "github" } }, "root": { diff --git a/flake.nix b/flake.nix index 5f68924..9754a4f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ "Process Compose is like docker-compose, but for orchestrating a suite of processes, not containers."; # Nixpkgs / NixOS version to use. - inputs.nixpkgs.url = "nixpkgs"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-22.11"; inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = { self, nixpkgs, flake-utils }: