This repository has been archived on 2024-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
forgejo/cmd/actions.go

67 lines
1.6 KiB
Go

// SPDX-License-Identifier: MIT
package cmd
import (
"context"
"errors"
"fmt"
"log"
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/urfave/cli"
)
// CmdActions represents the available actions sub-command.
var CmdActions = cli.Command{
Name: "actions",
Usage: "Actions",
Description: "Actions",
Action: runActions,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "registration-token-admin",
Usage: "Show the runner registration admin token",
},
},
}
func runActions(ctx *cli.Context) error {
setting.InitProviderFromExistingFile()
setting.LoadCommonSettings()
setting.LoadDBSetting()
stdCtx, cancel := installSignals()
defer cancel()
if err := db.InitEngine(stdCtx); err != nil {
fmt.Println(err)
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
return nil
}
if ctx.Bool("registration-token-admin") {
return runActionsRegistrationToken(ctx, stdCtx, 0, 0)
}
return nil
}
func runActionsRegistrationToken(ctx *cli.Context, stdCtx context.Context, ownerID, repoID int64) error {
var token *actions_model.ActionRunnerToken
token, err := actions_model.GetUnactivatedRunnerToken(stdCtx, ownerID, repoID)
if errors.Is(err, util.ErrNotExist) {
token, err = actions_model.NewRunnerToken(stdCtx, ownerID, repoID)
if err != nil {
log.Fatalf("CreateRunnerToken", err)
}
} else if err != nil {
log.Fatalf("GetUnactivatedRunnerToken", err)
}
fmt.Printf(token.Token)
return nil
}