code.gitea.io/gitea@v1.22.3/cmd/actions.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package cmd 5 6 import ( 7 "fmt" 8 9 "code.gitea.io/gitea/modules/private" 10 "code.gitea.io/gitea/modules/setting" 11 12 "github.com/urfave/cli/v2" 13 ) 14 15 var ( 16 // CmdActions represents the available actions sub-commands. 17 CmdActions = &cli.Command{ 18 Name: "actions", 19 Usage: "Manage Gitea Actions", 20 Subcommands: []*cli.Command{ 21 subcmdActionsGenRunnerToken, 22 }, 23 } 24 25 subcmdActionsGenRunnerToken = &cli.Command{ 26 Name: "generate-runner-token", 27 Usage: "Generate a new token for a runner to use to register with the server", 28 Action: runGenerateActionsRunnerToken, 29 Aliases: []string{"grt"}, 30 Flags: []cli.Flag{ 31 &cli.StringFlag{ 32 Name: "scope", 33 Aliases: []string{"s"}, 34 Value: "", 35 Usage: "{owner}[/{repo}] - leave empty for a global runner", 36 }, 37 }, 38 } 39 ) 40 41 func runGenerateActionsRunnerToken(c *cli.Context) error { 42 ctx, cancel := installSignals() 43 defer cancel() 44 45 setting.MustInstalled() 46 47 scope := c.String("scope") 48 49 respText, extra := private.GenerateActionsRunnerToken(ctx, scope) 50 if extra.HasError() { 51 return handleCliResponseExtra(extra) 52 } 53 _, _ = fmt.Printf("%s\n", respText.Text) 54 return nil 55 }