code.gitea.io/gitea@v1.22.3/modules/setting/actions.go (about)

     1  // Copyright 2022 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package setting
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  	"time"
    10  
    11  	"code.gitea.io/gitea/modules/log"
    12  )
    13  
    14  // Actions settings
    15  var (
    16  	Actions = struct {
    17  		LogStorage            *Storage // how the created logs should be stored
    18  		ArtifactStorage       *Storage // how the created artifacts should be stored
    19  		ArtifactRetentionDays int64    `ini:"ARTIFACT_RETENTION_DAYS"`
    20  		Enabled               bool
    21  		DefaultActionsURL     defaultActionsURL `ini:"DEFAULT_ACTIONS_URL"`
    22  		ZombieTaskTimeout     time.Duration     `ini:"ZOMBIE_TASK_TIMEOUT"`
    23  		EndlessTaskTimeout    time.Duration     `ini:"ENDLESS_TASK_TIMEOUT"`
    24  		AbandonedJobTimeout   time.Duration     `ini:"ABANDONED_JOB_TIMEOUT"`
    25  		SkipWorkflowStrings   []string          `ìni:"SKIP_WORKFLOW_STRINGS"`
    26  	}{
    27  		Enabled:             true,
    28  		DefaultActionsURL:   defaultActionsURLGitHub,
    29  		SkipWorkflowStrings: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"},
    30  	}
    31  )
    32  
    33  type defaultActionsURL string
    34  
    35  func (url defaultActionsURL) URL() string {
    36  	switch url {
    37  	case defaultActionsURLGitHub:
    38  		return "https://github.com"
    39  	case defaultActionsURLSelf:
    40  		return strings.TrimSuffix(AppURL, "/")
    41  	default:
    42  		// This should never happen, but just in case, use GitHub as fallback
    43  		return "https://github.com"
    44  	}
    45  }
    46  
    47  const (
    48  	defaultActionsURLGitHub = "github" // https://github.com
    49  	defaultActionsURLSelf   = "self"   // the root URL of the self-hosted Gitea instance
    50  	// DefaultActionsURL only supports GitHub and the self-hosted Gitea.
    51  	// It's intentionally not supported more, so please be cautious before adding more like "gitea" or "gitlab".
    52  	// If you get some trouble with `uses: username/action_name@version` in your workflow,
    53  	// please consider to use `uses: https://the_url_you_want_to_use/username/action_name@version` instead.
    54  )
    55  
    56  func loadActionsFrom(rootCfg ConfigProvider) error {
    57  	sec := rootCfg.Section("actions")
    58  	err := sec.MapTo(&Actions)
    59  	if err != nil {
    60  		return fmt.Errorf("failed to map Actions settings: %v", err)
    61  	}
    62  
    63  	if urls := string(Actions.DefaultActionsURL); urls != defaultActionsURLGitHub && urls != defaultActionsURLSelf {
    64  		url := strings.Split(urls, ",")[0]
    65  		if strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://") {
    66  			log.Error("[actions] DEFAULT_ACTIONS_URL does not support %q as custom URL any longer, fallback to %q",
    67  				urls,
    68  				defaultActionsURLGitHub,
    69  			)
    70  			Actions.DefaultActionsURL = defaultActionsURLGitHub
    71  		} else {
    72  			return fmt.Errorf("unsupported [actions] DEFAULT_ACTIONS_URL: %q", urls)
    73  		}
    74  	}
    75  
    76  	// don't support to read configuration from [actions]
    77  	Actions.LogStorage, err = getStorage(rootCfg, "actions_log", "", nil)
    78  	if err != nil {
    79  		return err
    80  	}
    81  
    82  	actionsSec, _ := rootCfg.GetSection("actions.artifacts")
    83  
    84  	Actions.ArtifactStorage, err = getStorage(rootCfg, "actions_artifacts", "", actionsSec)
    85  
    86  	// default to 90 days in Github Actions
    87  	if Actions.ArtifactRetentionDays <= 0 {
    88  		Actions.ArtifactRetentionDays = 90
    89  	}
    90  
    91  	Actions.ZombieTaskTimeout = sec.Key("ZOMBIE_TASK_TIMEOUT").MustDuration(10 * time.Minute)
    92  	Actions.EndlessTaskTimeout = sec.Key("ENDLESS_TASK_TIMEOUT").MustDuration(3 * time.Hour)
    93  	Actions.AbandonedJobTimeout = sec.Key("ABANDONED_JOB_TIMEOUT").MustDuration(24 * time.Hour)
    94  
    95  	return err
    96  }