You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.go 3.1KB

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