From dcb71d3b1dad761a022b2c62efccb26542fb2170 Mon Sep 17 00:00:00 2001 From: j3ssie Date: Mon, 26 Jan 2026 02:11:26 +0800 Subject: [PATCH] feat: add build time and commit hash to server info and improve nightly release workflow - Expose BuildTime and CommitHash in core constants and health endpoints (/api/info) - Refactor nightly release workflow to delete only assets instead of the entire release tag - Rename github-action make target to run-github-action for clarity and consistency --- .github/workflows/nightly-release.yaml | 17 ++++++----------- Makefile | 6 +++--- cmd/osmedeus/main.go | 3 +++ internal/core/constants.go | 3 +++ pkg/server/handlers/health.go | 6 ++++++ pkg/server/server.go | 6 ++++++ 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.github/workflows/nightly-release.yaml b/.github/workflows/nightly-release.yaml index 49651e2..c000cf2 100644 --- a/.github/workflows/nightly-release.yaml +++ b/.github/workflows/nightly-release.yaml @@ -24,20 +24,15 @@ jobs: with: go-version: '1.25' - - name: Delete existing nightly release + - name: Delete existing nightly release assets env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Delete release if exists (tag will be force-updated) - gh release delete v0.0.0-nightly --yes || true - - - name: Create or update nightly tag - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - # Use semver-compliant tag for GoReleaser v2 - git tag -fa v0.0.0-nightly -m "Nightly build $(date -u +%Y-%m-%d)" - git push origin v0.0.0-nightly --force + TAG="v0.0.0-nightly" + gh release view "$TAG" --json assets -q '.assets[].name' | while read -r asset; do + echo "Deleting asset: $asset" + gh release delete-asset "$TAG" "$asset" --yes + done - name: Create release notes run: | diff --git a/Makefile b/Makefile index f5d1a8c..d73e9a7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build run test test-unit test-integration test-workflow-integration test-e2e test-e2e-verbose test-e2e-ssh test-e2e-api test-e2e-nix test-e2e-install test-docker test-ssh test-distributed test-all test-summary test-ci clean install install-gotestsum lint fmt db-seed db-clean db-migrate run-server-debug swagger update-ui snapshot-release github-release github-action docker-toolbox docker-toolbox-run docker-toolbox-shell docker-publish +.PHONY: build run test test-unit test-integration test-workflow-integration test-e2e test-e2e-verbose test-e2e-ssh test-e2e-api test-e2e-nix test-e2e-install test-docker test-ssh test-distributed test-all test-summary test-ci clean install install-gotestsum lint fmt db-seed db-clean db-migrate run-server-debug swagger update-ui snapshot-release github-release run-github-action docker-toolbox docker-toolbox-run docker-toolbox-shell docker-publish # Go parameters GOCMD=go @@ -317,7 +317,7 @@ github-release: @echo "$(PREFIX) Building and publishing GitHub release..." export GORELEASER_CURRENT_TAG="$(VERSION)" && goreleaser release --clean -github-action: +run-github-action: unset GH_TOKEN &&gh workflow run manual-release.yaml && gh workflow run nightly-release.yaml # Database commands @@ -393,7 +393,7 @@ help: @echo " make snapshot-release Build local snapshot release (no publish)" @echo " make local-release Build local snapshot for mac/linux arm (testing)" @echo " make github-release Build and publish GitHub release" - @echo " make github-action Trigger manual and nightly GitHub workflows" + @echo " make run-github-action Trigger manual and nightly GitHub workflows" @echo "" @echo "\033[33m DATABASE\033[0m" @echo " make db-seed Seed database with sample data" diff --git a/cmd/osmedeus/main.go b/cmd/osmedeus/main.go index 7e3883b..48425b1 100644 --- a/cmd/osmedeus/main.go +++ b/cmd/osmedeus/main.go @@ -1,6 +1,7 @@ package main import ( + "github.com/j3ssie/osmedeus/v5/internal/core" "github.com/j3ssie/osmedeus/v5/pkg/cli" ) @@ -32,6 +33,8 @@ var ( // @description JWT Bearer token authentication. Format: "Bearer {token}" func main() { + core.BuildTime = BuildTime + core.CommitHash = CommitHash cli.SetBuildInfo(BuildTime, CommitHash) cli.Execute() } diff --git a/internal/core/constants.go b/internal/core/constants.go index 2c4e020..71a9d6a 100644 --- a/internal/core/constants.go +++ b/internal/core/constants.go @@ -29,3 +29,6 @@ const ( // DefaultUA is the default User-Agent for HTTP clients DefaultUA = "Mozilla/5.0 (compatible; Osmedeus/" + VERSION + "; +" + REPO_URL + ")" ) + +var BuildTime = "unknown" +var CommitHash = "unknown" diff --git a/pkg/server/handlers/health.go b/pkg/server/handlers/health.go index ac52b57..28b481d 100644 --- a/pkg/server/handlers/health.go +++ b/pkg/server/handlers/health.go @@ -15,6 +15,8 @@ type ServerInfoData struct { Repo string Author string Docs string + Build string + Commit string } // cachedServerInfo holds server info set once at startup @@ -68,6 +70,8 @@ func Root(cfg *config.Config) fiber.Handler { "author": cachedServerInfo.Author, "docs": cachedServerInfo.Docs, "license": cachedServerInfo.License, + "build": cachedServerInfo.Build, + "commit": cachedServerInfo.Commit, }) } } @@ -88,6 +92,8 @@ func ServerInfo(cfg *config.Config) fiber.Handler { "author": cachedServerInfo.Author, "docs": cachedServerInfo.Docs, "license": cachedServerInfo.License, + "build": cachedServerInfo.Build, + "commit": cachedServerInfo.Commit, }) } } diff --git a/pkg/server/server.go b/pkg/server/server.go index 301ef23..b3ebfb2 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -51,6 +51,8 @@ var cachedServerInfo struct { Repo string Author string Docs string + Build string + Commit string } // Server represents the web server @@ -107,6 +109,8 @@ func New(cfg *config.Config, opts *Options) (*Server, error) { cachedServerInfo.Repo = core.REPO_URL cachedServerInfo.Author = core.AUTHOR cachedServerInfo.Docs = core.DOCS + cachedServerInfo.Build = core.BuildTime + cachedServerInfo.Commit = core.CommitHash // Set cached info for handlers to use handlers.SetServerInfo(&handlers.ServerInfoData{ @@ -116,6 +120,8 @@ func New(cfg *config.Config, opts *Options) (*Server, error) { Repo: cachedServerInfo.Repo, Author: cachedServerInfo.Author, Docs: cachedServerInfo.Docs, + Build: cachedServerInfo.Build, + Commit: cachedServerInfo.Commit, }) // Select error handler based on debug mode