mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-13 22:41:54 +02:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ea5134ac6 |
+1
-1
@@ -65,7 +65,7 @@ builds:
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X gitea.com/gitea/runner/internal/pkg/ver.version={{ .Summary }}
|
||||
- -s -w -X main.version={{ .Summary }}
|
||||
binary: >-
|
||||
{{ .ProjectName }}-
|
||||
{{- .Version }}-
|
||||
|
||||
@@ -72,7 +72,8 @@ else
|
||||
endif
|
||||
|
||||
TAGS ?=
|
||||
LDFLAGS ?= -X "gitea.com/gitea/runner/internal/pkg/ver.version=v$(RELASE_VERSION)"
|
||||
LDFLAGS ?= -X "main.version=v$(RELASE_VERSION)"
|
||||
VERSION_CHECK_BIN := $(DIST)/version-check$(suffix $(EXECUTABLE))
|
||||
|
||||
.PHONY: all
|
||||
all: build
|
||||
@@ -113,7 +114,19 @@ deps-tools: ## install tool dependencies
|
||||
wait
|
||||
|
||||
.PHONY: checks
|
||||
checks: tidy-check fmt-check security-check ## run the non-lint source checks
|
||||
checks: tidy-check fmt-check security-check version-check ## run the non-lint source checks
|
||||
|
||||
.PHONY: version-check
|
||||
version-check: ## verify the version is injected into the binary
|
||||
@mkdir -p $(DIST)
|
||||
@$(GO) build -tags '$(TAGS)' -ldflags '-s -w $(EXTLDFLAGS) -X "main.version=v0.0.0-injected"' -o $(VERSION_CHECK_BIN) .
|
||||
@case "$$($(VERSION_CHECK_BIN) --version)" in \
|
||||
*v0.0.0-injected*) ;; \
|
||||
*) echo "version injection is broken, the Makefile -X target no longer matches a variable" >&2; exit 1;; \
|
||||
esac
|
||||
@rm -f $(VERSION_CHECK_BIN)
|
||||
@# goreleaser builds releases from its own ldflags, so a stale -X target there ships an unversioned binary
|
||||
@grep -q -- '-X main.version=' .goreleaser.yaml || { echo ".goreleaser.yaml no longer injects main.version" >&2; exit 1; }
|
||||
|
||||
.PHONY: lint
|
||||
lint: lint-go lint-go-windows ## lint everything
|
||||
|
||||
@@ -3,9 +3,15 @@
|
||||
|
||||
package ver
|
||||
|
||||
// go build -ldflags "-X gitea.com/gitea/runner/internal/pkg/ver.version=1.2.3"
|
||||
var version = "dev"
|
||||
|
||||
// SetVersion records the version injected into package main at build time.
|
||||
func SetVersion(v string) {
|
||||
if v != "" {
|
||||
version = v
|
||||
}
|
||||
}
|
||||
|
||||
func Version() string {
|
||||
return version
|
||||
}
|
||||
|
||||
@@ -11,3 +11,17 @@ func TestVersion(t *testing.T) {
|
||||
t.Errorf("Version() = %q, want %q", got, version)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetVersion(t *testing.T) {
|
||||
t.Cleanup(func() { version = "dev" })
|
||||
|
||||
SetVersion("v1.2.3")
|
||||
if got := Version(); got != "v1.2.3" {
|
||||
t.Errorf("Version() = %q, want %q", got, "v1.2.3")
|
||||
}
|
||||
|
||||
SetVersion("")
|
||||
if got := Version(); got != "v1.2.3" {
|
||||
t.Errorf("Version() = %q, want %q", got, "v1.2.3")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,14 @@ import (
|
||||
"syscall"
|
||||
|
||||
"gitea.com/gitea/runner/internal/app/cmd"
|
||||
"gitea.com/gitea/runner/internal/pkg/ver"
|
||||
)
|
||||
|
||||
// version is injected at build time with `-ldflags "-X main.version=v1.2.3"`.
|
||||
var version = "dev"
|
||||
|
||||
func main() {
|
||||
ver.SetVersion(version)
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
// run the command
|
||||
|
||||
Reference in New Issue
Block a user