mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-07 09:24:22 +02:00
Revert #1136 and use actionslib instead. revert chore: bump the module path to `/v3`, take the version from the VCS stamp (#1136) gitea can not consume the runner's api by version while it's version mismatches the module version: ``` go: gitea.com/gitea/runner@v3.0.1: invalid version: module contains a go.mod file, so module path must match major version ("gitea.com/gitea/runner/v3") ``` Fix that by bumping the module version now. The existing `v3.0.0` and `v3.0.1` tags stay unusable, so a new tag is needed after this lands. Also drop the version `-X` linker flags, which would otherwise have to repeat the new path in both `Makefile` and `.goreleaser.yaml`, where a stale path makes injection silently no-op. Go has recorded the module version in the build info since 1.24, so `Version()` reads it from there, keeping the variable as an override for builds without a VCS stamp. That part started as https://gitea.com/gitea/runner/pulls/1137 but belongs here: the stamp resolves against the tags that are legal for the module path, so without the `/v3` bump it would report `v1.0.9-0.<ts>-<sha>`. Since `release-nightly.yml` triggers on every push to `main`, splitting them would publish a nightly with a `v1` version. --------- Co-authored-by: bircni <bircni@icloud.com> Reviewed-on: https://gitea.com/gitea/runner/pulls/1136 Reviewed-by: techknowlogick <9+techknowlogick@noreply.gitea.com> Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/runner/pulls/1148 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
89 lines
3.2 KiB
Go
89 lines
3.2 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func Execute(ctx context.Context) {
|
|
// ./gitea-runner
|
|
rootCmd := &cobra.Command{
|
|
Use: "gitea-runner",
|
|
Short: "Gitea Runner",
|
|
Version: ver.Version(),
|
|
SilenceUsage: true,
|
|
}
|
|
configFile := ""
|
|
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file path. `config` subcommands fall back to config.yaml in the working directory or next to the executable")
|
|
|
|
// ./gitea-runner register
|
|
var regArgs registerArgs
|
|
registerCmd := &cobra.Command{
|
|
Use: "register",
|
|
Short: "Register a runner to the server",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runRegister(ctx, ®Args, &configFile), // must use a pointer to regArgs
|
|
}
|
|
registerCmd.Flags().BoolVar(®Args.NoInteractive, "no-interactive", false, "Disable interactive mode")
|
|
registerCmd.Flags().StringVar(®Args.InstanceAddr, "instance", "", "Gitea instance address")
|
|
registerCmd.Flags().StringVar(®Args.Token, "token", "", "Runner token (or set the GITEA_RUNNER_REGISTRATION_TOKEN envvar)")
|
|
registerCmd.Flags().StringVar(®Args.TokenFile, "token-file", "", "Path to a file containing the runner token")
|
|
registerCmd.Flags().StringVar(®Args.RunnerName, "name", "", "Runner name")
|
|
registerCmd.Flags().StringVar(®Args.Labels, "labels", "", "Runner tags, comma separated")
|
|
registerCmd.Flags().BoolVar(®Args.Ephemeral, "ephemeral", false, "Configure the runner to be ephemeral and only ever be able to pick a single job (stricter than --once)")
|
|
rootCmd.AddCommand(registerCmd)
|
|
|
|
// ./gitea-runner daemon
|
|
var daemArgs daemonArgs
|
|
daemonCmd := &cobra.Command{
|
|
Use: "daemon",
|
|
Short: "Run as a runner daemon",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runDaemon(ctx, &daemArgs, &configFile),
|
|
}
|
|
daemonCmd.Flags().BoolVar(&daemArgs.Once, "once", false, "Run one job then exit")
|
|
daemonCmd.Flags().StringVar(&daemArgs.Labels, "labels", os.Getenv("GITEA_RUNNER_LABELS"), "Runner labels, comma separated. Overrides the labels of an already registered runner")
|
|
rootCmd.AddCommand(daemonCmd)
|
|
|
|
// ./gitea-runner exec
|
|
rootCmd.AddCommand(loadExecCmd(ctx))
|
|
|
|
// ./gitea-runner bug-report
|
|
rootCmd.AddCommand(loadBugReportCmd())
|
|
|
|
// ./gitea-runner config
|
|
rootCmd.AddCommand(loadConfigCmd(&configFile))
|
|
|
|
// ./gitea-runner generate-config
|
|
generateConfigCmd := loadGenerateConfigCmd("generate-config")
|
|
generateConfigCmd.Deprecated = "use `config generate` instead."
|
|
rootCmd.AddCommand(generateConfigCmd)
|
|
|
|
// ./gitea-runner cache-server
|
|
var cacheArgs cacheServerArgs
|
|
cacheCmd := &cobra.Command{
|
|
Use: "cache-server",
|
|
Short: "Start a cache server for the cache action",
|
|
Args: cobra.MaximumNArgs(0),
|
|
RunE: runCacheServer(&configFile, &cacheArgs),
|
|
}
|
|
cacheCmd.Flags().StringVarP(&cacheArgs.Dir, "dir", "d", "", "Cache directory")
|
|
cacheCmd.Flags().StringVarP(&cacheArgs.Host, "host", "s", "", "Host of the cache server")
|
|
cacheCmd.Flags().Uint16VarP(&cacheArgs.Port, "port", "p", 0, "Port of the cache server")
|
|
rootCmd.AddCommand(cacheCmd)
|
|
|
|
// hide completion command
|
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|