c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
actions_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/actions"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/graceful"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/log"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/queue"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/util"
|
|
notify_service "git.mokoconsulting.tech/MokoConsulting/MokoGitea/services/notify"
|
|
)
|
|
|
|
func initGlobalRunnerToken(ctx context.Context) error {
|
|
// use the same env name as the runner, for consistency
|
|
token := os.Getenv("GITEA_RUNNER_REGISTRATION_TOKEN")
|
|
tokenFile := os.Getenv("GITEA_RUNNER_REGISTRATION_TOKEN_FILE")
|
|
if token != "" && tokenFile != "" {
|
|
return errors.New("both GITEA_RUNNER_REGISTRATION_TOKEN and GITEA_RUNNER_REGISTRATION_TOKEN_FILE are set, only one can be used")
|
|
}
|
|
if tokenFile != "" {
|
|
file, err := os.ReadFile(tokenFile)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to read GITEA_RUNNER_REGISTRATION_TOKEN_FILE: %w", err)
|
|
}
|
|
token = strings.TrimSpace(string(file))
|
|
}
|
|
if token == "" {
|
|
return nil
|
|
}
|
|
|
|
if len(token) < 32 {
|
|
return errors.New("GITEA_RUNNER_REGISTRATION_TOKEN must be at least 32 random characters")
|
|
}
|
|
|
|
existing, err := actions_model.GetRunnerToken(ctx, token)
|
|
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
|
return fmt.Errorf("unable to check existing token: %w", err)
|
|
}
|
|
if existing != nil {
|
|
if !existing.IsActive {
|
|
log.Warn("The token defined by GITEA_RUNNER_REGISTRATION_TOKEN is already invalidated, please use the latest one from web UI")
|
|
}
|
|
return nil
|
|
}
|
|
_, err = actions_model.NewRunnerTokenWithValue(ctx, 0, 0, token)
|
|
return err
|
|
}
|
|
|
|
func Init(ctx context.Context) error {
|
|
if !setting.Actions.Enabled {
|
|
return nil
|
|
}
|
|
|
|
jobEmitterQueue = queue.CreateUniqueQueue(graceful.GetManager().ShutdownContext(), "actions_ready_job", jobEmitterQueueHandler)
|
|
if jobEmitterQueue == nil {
|
|
return errors.New("unable to create actions_ready_job queue")
|
|
}
|
|
go graceful.GetManager().RunWithCancel(jobEmitterQueue)
|
|
|
|
notify_service.RegisterNotifier(NewNotifier())
|
|
return initGlobalRunnerToken(ctx)
|
|
}
|