~artemis/cap

ae022ae9f80fa40311718bf716aff1c6a594682a — Artémis 9 months ago a39a33d
feat(build-version): added build version, command, and metric tag
5 files changed, 27 insertions(+), 3 deletions(-)

M README.md
M cap.go
A devnotes.gmi
M handler.go
M types.go
M README.md => README.md +6 -0
@@ 52,6 52,12 @@ What are the differences between both?

## Developer documentation

To compile Cap for a release, it is recommended to strip the debug symbols as well as append the build version.

```
$ go build -ldflags "-s -w -X main.BuildVersion=$(git describe --tags)" .
```

Right now, the tool's architecture, source-code, and internal decisions is underdocumented.

However, some features (the most recent ones) are talked in [the POC folder of the documentation area](docs/poc).

M cap.go => cap.go +4 -1
@@ 1,6 1,7 @@
package main

import (
	"fmt"
	"os"
	"runtime/pprof"



@@ 38,7 39,9 @@ func main() {
		defer pprof.StopCPUProfile()
	}

	if args.InitCmd != nil {
	if args.VersionCmd != nil {
		fmt.Printf("Cap (version %s) - capsule generator\n", BuildVersion)
	} else if args.InitCmd != nil {
		// InitCmd is the capsule initialization command, creating a new capsule based on the initiator's template.
		initiator := initiator.New(args.Path)
		if err := initiator.InitCapsule(); err != nil {

A devnotes.gmi => devnotes.gmi +6 -0
@@ 0,0 1,6 @@
# Development notes

The core goal here is to add support for a natively integrated embedded gemini server in the watch mode.
However, while trivial to do in its core, it would also be good to take this occasion to work on making the watch features more easy to toggle and choose.

=> https://git.sr.ht/~adnano/go-gemini the gemini server library i will probably use

M handler.go => handler.go +2 -2
@@ 367,8 367,8 @@ func (f *FsBuilder) HandleBuildMetadata() error {
	buildTime := time.Now().Unix()

	metricsText := strings.Join([]string{
		"# HELP last_build A placeholder value of 1, its timestamp marks the time at which this file was last built",
		fmt.Sprintf("last_build 1 %d", buildTime),
		"# HELP last_build A placeholder value of 1, its timestamp marks the time at which this file was last built, and its `version` tag marks the cap version which was used",
		fmt.Sprintf("last_build{version=\"%s\"} 1 %d", BuildVersion, buildTime),
		"",
		"# HELP files The count of files in the capsule",
		"# TYPE files counter",

M types.go => types.go +9 -0
@@ 17,6 17,14 @@ const (
	TemplatesFolder = ".templates"
)

var (
	// BuildVersion defines the version at which Cap was built. By default set to `unknown`,
	// and should be set to the release tag when compiling it for release.
	// The value can be generated using the command `git describe --tags`; it is expected for it
	// to have the commit hash suffix if you're not building an annotated tagged release.
	BuildVersion = "unknown"
)

// FsBuilder contains the state of the capsule builder objects.
type FsBuilder struct {
	InputPath     string


@@ 105,4 113,5 @@ type Args struct {
	InitCmd                  *struct{} `arg:"subcommand:init"`
	BuildCmd                 *struct{} `arg:"subcommand:build"`
	WatchCmd                 *WatchCMD `arg:"subcommand:watch"`
	VersionCmd               *struct{} `arg:"subcommand:version"`
}