Inject version when building and report version to Gitea via log and header #43
|
@ -60,7 +60,7 @@ builds:
|
|||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X gitea.com/gitea/act_runner/cmd.RunnerVersion={{ .Version }}
|
||||
- -s -w -X gitea.com/gitea/act_runner/cmd.version={{ .Version }}
|
||||
binary: >-
|
||||
{{ .ProjectName }}-
|
||||
{{- if .IsSnapshot }}{{ .Branch }}-
|
||||
|
|
2
Makefile
2
Makefile
|
@ -62,7 +62,7 @@ else
|
|||
endif
|
||||
|
||||
TAGS ?=
|
||||
LDFLAGS ?= -X "$(RUNNER_CMD_PACKAGE_PATH).RunnerVersion=$(RELASE_VERSION)"
|
||||
LDFLAGS ?= -X "$(RUNNER_CMD_PACKAGE_PATH).version=$(RELASE_VERSION)"
|
||||
|
||||
all: build
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ func getHttpClient(endpoint string, insecure bool) *http.Client {
|
|||
}
|
||||
|
||||
// New returns a new runner client.
|
||||
func New(endpoint string, insecure bool, uuid, token string, opts ...connect.ClientOption) *HTTPClient {
|
||||
func New(endpoint string, insecure bool, uuid, token, runnerVersion string, opts ...connect.ClientOption) *HTTPClient {
|
||||
baseURL := strings.TrimRight(endpoint, "/") + "/api/actions"
|
||||
|
||||
opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
||||
|
@ -40,6 +40,9 @@ func New(endpoint string, insecure bool, uuid, token string, opts ...connect.Cli
|
|||
if token != "" {
|
||||
req.Header().Set(core.TokenHeader, token)
|
||||
}
|
||||
if runnerVersion != "" {
|
||||
req.Header().Set(core.VersionHeader, runnerVersion)
|
||||
}
|
||||
return next(ctx, req)
|
||||
}
|
||||
})))
|
||||
|
|
18
cmd/cmd.go
18
cmd/cmd.go
|
@ -5,15 +5,13 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const version = "0.1.5"
|
||||
|
||||
var RunnerVersion = "develop"
|
||||
// the version of act_runner
|
||||
var version = "develop"
|
||||
|
||||
|
||||
type globalArgs struct {
|
||||
EnvFile string
|
||||
|
@ -26,7 +24,7 @@ func Execute(ctx context.Context) {
|
|||
|
||||
// ./act_runner
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"",
|
||||
Use: "act_runner [event name to run]\nIf no event name passed, will default to \"on: push\"",
|
||||
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Version: version,
|
||||
|
@ -50,16 +48,6 @@ func Execute(ctx context.Context) {
|
|||
registerCmd.Flags().StringVar(®Args.Labels, "labels", "", "Runner tags, comma separated")
|
||||
rootCmd.AddCommand(registerCmd)
|
||||
|
||||
// ./act_runner version
|
||||
versionCmd := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version of act runner",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("act_runner version %s\n", RunnerVersion)
|
||||
},
|
||||
}
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
||||
// ./act_runner daemon
|
||||
daemonCmd := &cobra.Command{
|
||||
Use: "daemon",
|
||||
|
|
|
@ -66,6 +66,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
|
|||
cfg.Client.Insecure,
|
||||
cfg.Runner.UUID,
|
||||
cfg.Runner.Token,
|
||||
version,
|
||||
)
|
||||
|
||||
runner := &runtime.Runner{
|
||||
|
@ -74,7 +75,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
|
|||
ForgeInstance: cfg.Client.Address,
|
||||
Environ: cfg.Runner.Environ,
|
||||
Labels: cfg.Runner.Labels,
|
||||
Version: RunnerVersion,
|
||||
Version: version,
|
||||
CacheHandler: handler,
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,9 @@ func doRegister(cfg *config.Config, inputs *registerInputs) error {
|
|||
cli := client.New(
|
||||
inputs.InstanceAddr,
|
||||
inputs.Insecure,
|
||||
"", "",
|
||||
"",
|
||||
"",
|
||||
version,
|
||||
)
|
||||
|
||||
for {
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
package core
|
||||
|
||||
const (
|
||||
UUIDHeader = "x-runner-uuid"
|
||||
TokenHeader = "x-runner-token"
|
||||
UUIDHeader = "x-runner-uuid"
|
||||
TokenHeader = "x-runner-token"
|
||||
VersionHeader = "x-runner-version"
|
||||
)
|
||||
|
||||
// Runner struct
|
||||
|
|
Loading…
Reference in New Issue
Block a user
What is this
version
used for?From the output of executing
./act_runner
, it seems likeversion for act
. I am not sure thisversion
is useful, so I declare a new variableRunnerVersion
. If thisversion
is useless, i will use this to save the version ofact_runner
.I'm pretty sure it's useless.