From f6b893d89ce5541eb50daa06c1d17fb3eb4e1763 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Tue, 25 Mar 2025 04:58:35 +0100 Subject: [PATCH] feat: version --- .github/workflows/ci-build.yml | 37 +++++++++++++++++++++++++++++++--- .gitignore | 1 + .goreleaser.yaml | 34 +++++++++++++++++++++++++++++++ internal/domain/types.go | 2 ++ internal/terminal/terminal.go | 11 ++++++++-- main.go | 13 +++++++++++- 6 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index cea8032..dfab235 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -1,15 +1,19 @@ name: ci-build run-name: Building ${{ github.ref_name }} on: -- push -- pull_request + push: + branches: + - "**" + tags: + - "v[0-9]+*" + pull_request: jobs: lint: runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - uses: ludeeus/action-shellcheck@2.0.0 - backend: + build: runs-on: ubuntu-24.04 needs: - lint @@ -50,3 +54,30 @@ jobs: env: DOCKER_API_VERSION: "1.45" run: mise run test_integration_ci + release: + needs: + - lint + - build + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Setup Go 1.24.1 + uses: actions/setup-go@v5 + with: + go-version: '1.24.1' + - name: install OS dependencies + run: | + sudo apt-get -y update && \ + sudo apt-get -y --no-install-recommends install \ + libx11-dev + - name: release + uses: goreleaser/goreleaser-action@v5 + with: + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index c3b5d86..04dbd5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.log /mediamtx.yml +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d9192ab --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,34 @@ +version: 2 + +before: + hooks: + - go mod tidy + - go generate ./... + +builds: + - env: + # - CGO_ENABLED=0 + goos: + - linux + # - windows + - darwin + +archives: + - formats: [tar.gz] + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + formats: [zip] + +changelog: + sort: asc + filters: + exclude: + - "^doc:" + - "^test:" diff --git a/internal/domain/types.go b/internal/domain/types.go index a5be8ae..9793fbf 100644 --- a/internal/domain/types.go +++ b/internal/domain/types.go @@ -25,6 +25,8 @@ func (s *AppState) Clone() AppState { type BuildInfo struct { GoVersion string Version string + Commit string + Date string } // Source represents the source, currently always the mediaserver. diff --git a/internal/terminal/terminal.go b/internal/terminal/terminal.go index 7ff0589..664edc3 100644 --- a/internal/terminal/terminal.go +++ b/internal/terminal/terminal.go @@ -737,12 +737,19 @@ func (ui *UI) confirmQuit() { } func (ui *UI) showAbout() { + commit := ui.buildInfo.Commit + if len(commit) > 8 { + commit = commit[:8] + } + ui.showModal( modalGroupAbout, fmt.Sprintf( - "%s: live stream multiplexer\n\nv0.0.0 %s (%s)", + "%s: live stream multiplexer\n(c) Rob Watson\nhttps://git.netflux.io/rob/octoplex\n\nReleased under AGPL3.\n\nv%s (%s)\nBuilt on %s (%s).", domain.AppName, - ui.buildInfo.Version, + cmp.Or(ui.buildInfo.Version, "0.0.0-devel"), + cmp.Or(commit, "unknown SHA"), + cmp.Or(ui.buildInfo.Date, "unknown date"), ui.buildInfo.GoVersion, ), []string{"Ok"}, diff --git a/main.go b/main.go index 2fc79ae..f4005c6 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,15 @@ import ( "golang.design/x/clipboard" ) +var ( + // version is the version of the application. + version string + // commit is the commit hash of the application. + commit string + // date is the date of the build. + date string +) + func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -86,7 +95,9 @@ func run(ctx context.Context) error { ConfigFilePath: configService.Path(), BuildInfo: domain.BuildInfo{ GoVersion: buildInfo.GoVersion, - Version: buildInfo.Main.Version, + Version: version, + Commit: commit, + Date: date, }, Logger: logger, },