Skip to content

Commit

Permalink
Merge pull request #36 from F1bonacc1/version_info
Browse files Browse the repository at this point in the history
Added version command - prints process-compose version and build info
  • Loading branch information
F1bonacc1 authored Dec 26, 2022
2 parents 00a3211 + 89254f1 commit bed65c1
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 20 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={{.CommitDate}}
- -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 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/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
24 changes: 17 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{ buildGoModule, config, lib, pkgs, installShellFiles, version ? "latest" }:
{ buildGoModule, config, lib, pkgs, installShellFiles, date, commit }:

buildGoModule {
let pkg = "github.com/f1bonacc1/process-compose/src/config";
in
buildGoModule rec {
pname = "process-compose";
version = version;
src = ./.;
ldflags = [ "-X github.com/f1bonacc1/process-compose/src/config.Version=v${version} -s -w" ];
version = "0.29.1";


src = lib.cleanSource ./.;
ldflags = [
"-X ${pkg}.Version=v${version}"
"-X ${pkg}.Date=${date}"
"-X ${pkg}.Commit=${commit}"
"-s"
"-w"
];

nativeBuildInputs = [ installShellFiles ];

Expand All @@ -21,9 +31,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
12 changes: 7 additions & 5 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 }:
Expand All @@ -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 bed65c1

Please sign in to comment.