From 2b14cdf7f6401fcc9652de355ee7fca81474d71a Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 24 Nov 2025 20:57:32 +0000 Subject: [PATCH] tsk-1: Go version bump (#2) Closes #1 Reviewed-on: https://git.kundeng.us/phoenix/catapult/pulls/2 Co-authored-by: phoenix Co-committed-by: phoenix --- .gitea/workflows/workflow.yaml | 44 ++++++++++++++++++++++++++++++++++ Makefile | 21 ++++++++++++++++ README.md | 6 +++++ go.mod | 2 +- internal/version/version.go | 17 +++++++++++++ main.go | 14 ++++++++++- 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/workflow.yaml create mode 100644 Makefile create mode 100644 internal/version/version.go diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml new file mode 100644 index 0000000..e7aee65 --- /dev/null +++ b/.gitea/workflows/workflow.yaml @@ -0,0 +1,44 @@ +name: Go + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-24.04 # You can change this to macos-latest or windows-latest if needed + + steps: + - uses: actions/checkout@v5 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: '1.25.4' # You can specify a specific version or 'stable' + + - name: Build + run: | + echo "Initializing config" + mkdir -p ~/.ssh + echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key + chmod 600 ~/.ssh/textsender_models_deploy_key + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts + + eval $(ssh-agent -s) + ssh-add -v ~/.ssh/textsender_models_deploy_key + + go env -w GOPRIVATE='${{ secrets.GIT_HOST_ROOT }}' + + echo "Creating local .gitconfig" + touch ~/.gitconfig + cat > ~/.gitconfig << "EOF" + [url "ssh://git@${{ secrets.GIT_HOST_ROOT }}"] + insteadOf = https://${{ secrets.GIT_HOST_ROOT }} + EOF + + make build + + - name: Test + run: go test -v ./... diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..84b9a7a --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +VERSION ?= $(shell git describe --tags 2>/dev/null || echo "dev") +COMMIT ?= $(shell git rev-parse --short HEAD) +BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) +GO_VERSION ?= $(shell go version | awk '{print $$3}') + +.PHONY: build +build: + go build -ldflags="\ + -X 'git.kundeng.us/phoenix/catapult/version.Version=$(VERSION)' \ + -X 'git.kundeng.us/phoenix/catapult/version.BuildTime=$(BUILD_TIME)' \ + -X 'git.kundeng.us/phoenix/catapult/version.Commit=$(COMMIT)' \ + -X 'git.kundeng.us/phoenix/catapult/version.GoVersion=$(GO_VERSION)'" \ + -o catapult main.go + +.PHONY: install +install: + go install -ldflags="\ + -X 'git.kundeng.us/phoenix/catapult/version.Version=$(VERSION)' \ + -X 'git.kundeng.us/phoenix/catapult/version.BuildTime=$(BUILD_TIME)' \ + -X 'git.kundeng.us/phoenix/catapult/version.Commit=$(COMMIT)' \ + -X 'git.kundeng.us/phoenix/catapult/version.GoVersion=$(GO_VERSION)'" diff --git a/README.md b/README.md index 4148460..cd19078 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Catapult A service used to send text messages + + +Building the service +``` +make build +``` diff --git a/go.mod b/go.mod index 7669e2b..2732c40 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module git.kundeng.us/phoenix/catapult -go 1.25.3 +go 1.25.4 diff --git a/internal/version/version.go b/internal/version/version.go new file mode 100644 index 0000000..91e3782 --- /dev/null +++ b/internal/version/version.go @@ -0,0 +1,17 @@ +package version + +import "fmt" + +var ( + Version = "dev" + BuildTime = "unknown" + Commit = "unknown" + GoVersion = "unknown" +) + +func String() string { + return fmt.Sprintf( + "Version: %s\nBuild Date: %s\nCommit: %s\nGo Version: %s", + Version, BuildTime, Commit, GoVersion, + ) +} diff --git a/main.go b/main.go index e9463c1..f3135ce 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,22 @@ package main import ( + "flag" "fmt" + + "git.kundeng.us/phoenix/catapult/internal/version" ) +const App_Name = "catapult" func main() { - fmt.Println("catapult") + fmt.Println(App_Name) + + versionFlag := flag.Bool("version", false, "Print version information") + flag.Parse() + + if *versionFlag { + fmt.Println(version.String()) + return + } }