Skip to content

Commit

Permalink
Added version command - prints process-compose version and build info
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Dec 24, 2022
1 parent 00a3211 commit 0f16894
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,3 +63,5 @@ clean:
release:
source exports
goreleaser release --rm-dist --skip-validate
snapshot:
goreleaser release --snapshot --rm-dist
20 changes: 14 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 ];

Expand All @@ -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";
};
Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 7 additions & 2 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0f16894

Please sign in to comment.