better versioning
This commit is contained in:
1 parent
7f58254dbc
commit
092ef6185f
3 files changed
+18
-1
No files matched your search
@@ -7,6 +7,10 @@ Rules for anyone, human or AI, changing this repo. Read [ARCHITECTURE.md](ARCHIT
|
|||||||
- `nix develop` (or direnv with `.envrc`) gives Go, gopls, staticcheck, delve and btrfs-progs. Use it rather than system tools.
|
- `nix develop` (or direnv with `.envrc`) gives Go, gopls, staticcheck, delve and btrfs-progs. Use it rather than system tools.
|
||||||
- Go code lives in `slackerbot/`, and that's where `go` commands run. Nix files and docs live at the repo root.
|
- Go code lives in `slackerbot/`, and that's where `go` commands run. Nix files and docs live at the repo root.
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
Versions look like `YYYY.MM.DD-<commit-sha>`. `flake.nix` builds the string from the commit date and short rev (with `-dirty` for uncommitted trees) and passes it to the binary with `-X main.version`. Don't hardcode a version anywhere. `slackerbot -version` prints it, and a plain `go build` reports `dev`.
|
||||||
|
|
||||||
## Checks before you finish
|
## Checks before you finish
|
||||||
|
|
||||||
Run from `slackerbot/`, and all must pass:
|
Run from `slackerbot/`, and all must pass:
|
||||||
|
|||||||
@@ -8,13 +8,16 @@
|
|||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
agent = self.nixosConfigurations.agent.config.system.build.toplevel;
|
agent = self.nixosConfigurations.agent.config.system.build.toplevel;
|
||||||
|
date = self.lastModifiedDate;
|
||||||
|
version = "${builtins.substring 0 4 date}.${builtins.substring 4 2 date}.${builtins.substring 6 2 date}-${self.shortRev or self.dirtyShortRev or "dirty"}";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.${system} = {
|
packages.${system} = {
|
||||||
slackerbot = pkgs.buildGoModule {
|
slackerbot = pkgs.buildGoModule {
|
||||||
pname = "slackerbot";
|
pname = "slackerbot";
|
||||||
version = "0.1.0";
|
inherit version;
|
||||||
src = ./slackerbot;
|
src = ./slackerbot;
|
||||||
|
ldflags = [ "-X main.version=${version}" ];
|
||||||
vendorHash = "sha256-DFNUnPMsfcUHDlIxcxsDvuqjoHcp9EDTXWVy5t/oxEk=";
|
vendorHash = "sha256-DFNUnPMsfcUHDlIxcxsDvuqjoHcp9EDTXWVy5t/oxEk=";
|
||||||
# tests need network ports and ../config.example.toml
|
# tests need network ports and ../config.example.toml
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -16,11 +17,20 @@ import (
|
|||||||
"slackerbot/internal/state"
|
"slackerbot/internal/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var version = "dev"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfgPath := flag.String("config", "/etc/slackerbot/config.toml", "path to the config file")
|
cfgPath := flag.String("config", "/etc/slackerbot/config.toml", "path to the config file")
|
||||||
mode := flag.String("mode", config.ModeMaster, "master (runs the Slack bot) or slave (runs containers for a master)")
|
mode := flag.String("mode", config.ModeMaster, "master (runs the Slack bot) or slave (runs containers for a master)")
|
||||||
|
showVersion := flag.Bool("version", false, "print the version and exit")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Println(version)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("slackerbot %s", version)
|
||||||
|
|
||||||
cfg, err := config.LoadConfig(*cfgPath, *mode)
|
cfg, err := config.LoadConfig(*cfgPath, *mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
Reference in new issue
Block a user