Inject version when building and report version to Gitea via log and header #43

Merged
wolfogre merged 4 commits from sillyguodong/act_runner:feature/issue_42 into main 2023-03-13 10:57:35 +00:00
7 changed files with 17 additions and 22 deletions
Showing only changes of commit 64cad20151 - Show all commits

View File

@ -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 }}-

View File

@ -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

View File

@ -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)
}
})))

View File

@ -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"

What is this version used for?

What is this `version` used for?

From the output of executing ./act_runner, it seems like version for act. I am not sure this version is useful, so I declare a new variable RunnerVersion. If this version is useless, i will use this to save the version of act_runner.

From the output of executing `./act_runner`, it seems like `version for act`. I am not sure this `version` is useful, so I declare a new variable `RunnerVersion`. If this `version` is useless, i will use this to save the version of `act_runner`.

I'm pretty sure it's useless.

I'm pretty sure it's useless.
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(&regArgs.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",

View File

@ -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,
}

View File

@ -274,7 +274,9 @@ func doRegister(cfg *config.Config, inputs *registerInputs) error {
cli := client.New(
inputs.InstanceAddr,
inputs.Insecure,
"", "",
"",
"",
version,
)
for {

View File

@ -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