From ba9f67f4f1ab439f1e217f6ea769c545db399c6d Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Wed, 15 Nov 2023 17:31:46 +0100 Subject: [PATCH 01/10] add skip ci functionality --- services/actions/notifier_helper.go | 11 +++ tests/integration/actions_trigger_test.go | 89 +++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 7d5f6c6c0a3c..d2c91cc87f48 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -144,6 +144,17 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } + if input.Event == webhook_module.HookEventPush || input.Event == webhook_module.HookEventPullRequest { + // skip runs with skip ci prefix in commit message if the event is push or pull_request + // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs + for _, prefix := range []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"} { + if strings.HasPrefix(commit.CommitMessage, prefix) { + log.Debug("repo %s with commit %s: skipped run because of %s prefix", input.Repo.RepoPath(), commit.ID, prefix) + return nil + } + } + } + var detectedWorkflows []*actions_module.DetectedWorkflow actionsConfig := input.Repo.MustGetUnit(ctx, unit_model.TypeActions).ActionsConfig() workflows, schedules, err := actions_module.DetectWorkflows(gitRepo, commit, input.Event, input.Payload) diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 253de7032655..28e944d2302f 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -194,3 +194,92 @@ func TestPullRequestTargetEvent(t *testing.T) { assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: baseRepo.ID})) }) } + +func TestSkipCI(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + // create the repo + repo, err := repo_service.CreateRepository(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{ + Name: "skip-ci-prefix", + Description: "test skip ci functionality", + AutoInit: true, + Gitignores: "Go", + License: "MIT", + Readme: "Default", + DefaultBranch: "main", + IsPrivate: false, + }) + assert.NoError(t, err) + assert.NotEmpty(t, repo) + + // enable actions + err = repo_model.UpdateRepositoryUnits(db.DefaultContext, repo, []repo_model.RepoUnit{{ + RepoID: repo.ID, + Type: unit_model.TypeActions, + }}, nil) + assert.NoError(t, err) + + // add workflow file to the repo + addWorkflowToBaseResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ + Files: []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: ".gitea/workflows/pr.yml", + ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"), + }, + }, + Message: "add workflow", + OldBranch: "main", + NewBranch: "main", + Author: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Committer: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Dates: &files_service.CommitDateOptions{ + Author: time.Now(), + Committer: time.Now(), + }, + }) + assert.NoError(t, err) + assert.NotEmpty(t, addWorkflowToBaseResp) + + // a run has been created + assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) + + // add a file with [skip ci] prefix in commit message + addFileResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ + Files: []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: "bar.txt", + ContentReader: strings.NewReader("bar"), + }, + }, + Message: "[skip ci] add bar", + OldBranch: "main", + NewBranch: "main", + Author: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Committer: &files_service.IdentityOptions{ + Name: user2.Name, + Email: user2.Email, + }, + Dates: &files_service.CommitDateOptions{ + Author: time.Now(), + Committer: time.Now(), + }, + }) + assert.NoError(t, err) + assert.NotEmpty(t, addFileResp) + + // the commit message contains a [skip ci] prefix, so there is still only 1 record + assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) + }) +} From e793507d85df169bebd1ccb8c5a25378d1dd9bcc Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Wed, 15 Nov 2023 18:09:21 +0100 Subject: [PATCH 02/10] add configuration option --- docs/content/administration/config-cheat-sheet.en-us.md | 1 + modules/setting/actions.go | 2 ++ services/actions/notifier_helper.go | 3 ++- tests/integration/actions_trigger_test.go | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 385830e5d896..50118d482d18 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -1396,6 +1396,7 @@ PROXY_HOSTS = *.github.com - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time - `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time +- `SKIP_RUN_PREFIX`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Prefixes committers can place inside a commit message to skip executing the workflow `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`. diff --git a/modules/setting/actions.go b/modules/setting/actions.go index 026bab4bfcfd..98c20fdeada1 100644 --- a/modules/setting/actions.go +++ b/modules/setting/actions.go @@ -22,9 +22,11 @@ var ( ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"` EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"` AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"` + SkipRunPrefix []string `ìni:"SKIP_RUN_PREFIX"` }{ Enabled: true, DefaultActionsURL: defaultActionsURLGitHub, + SkipRunPrefix: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"}, } ) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index d2c91cc87f48..cf5ae113e82f 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/services/convert" @@ -147,7 +148,7 @@ func notify(ctx context.Context, input *notifyInput) error { if input.Event == webhook_module.HookEventPush || input.Event == webhook_module.HookEventPullRequest { // skip runs with skip ci prefix in commit message if the event is push or pull_request // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs - for _, prefix := range []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"} { + for _, prefix := range setting.Actions.SkipRunPrefix { if strings.HasPrefix(commit.CommitMessage, prefix) { log.Debug("repo %s with commit %s: skipped run because of %s prefix", input.Repo.RepoPath(), commit.ID, prefix) return nil diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 28e944d2302f..548322aa4a19 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -4,6 +4,7 @@ package integration import ( + "fmt" "net/url" "strings" "testing" @@ -18,6 +19,7 @@ import ( user_model "code.gitea.io/gitea/models/user" actions_module "code.gitea.io/gitea/modules/actions" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/setting" pull_service "code.gitea.io/gitea/services/pull" repo_service "code.gitea.io/gitea/services/repository" files_service "code.gitea.io/gitea/services/repository/files" @@ -260,7 +262,7 @@ func TestSkipCI(t *testing.T) { ContentReader: strings.NewReader("bar"), }, }, - Message: "[skip ci] add bar", + Message: fmt.Sprintf("%s add bar", setting.Actions.SkipRunPrefix[0]), OldBranch: "main", NewBranch: "main", Author: &files_service.IdentityOptions{ From 4dcc6a3cee93110be2675fae856f5ada61f95823 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Wed, 15 Nov 2023 21:04:19 +0100 Subject: [PATCH 03/10] switch from prefix to contains --- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- modules/setting/actions.go | 4 ++-- services/actions/notifier_helper.go | 8 ++++---- tests/integration/actions_trigger_test.go | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 50118d482d18..fbc12abfe575 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -1396,7 +1396,7 @@ PROXY_HOSTS = *.github.com - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time - `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time -- `SKIP_RUN_PREFIX`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Prefixes committers can place inside a commit message to skip executing the workflow +- `SKIP_RUN_STRINGS`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`. diff --git a/modules/setting/actions.go b/modules/setting/actions.go index 98c20fdeada1..175512bc0fe0 100644 --- a/modules/setting/actions.go +++ b/modules/setting/actions.go @@ -22,11 +22,11 @@ var ( ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"` EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"` AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"` - SkipRunPrefix []string `ìni:"SKIP_RUN_PREFIX"` + SkipRunStrings []string `ìni:"SKIP_RUN_STRINGS"` }{ Enabled: true, DefaultActionsURL: defaultActionsURLGitHub, - SkipRunPrefix: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"}, + SkipRunStrings: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"}, } ) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index cf5ae113e82f..343c18e2c08a 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -146,11 +146,11 @@ func notify(ctx context.Context, input *notifyInput) error { } if input.Event == webhook_module.HookEventPush || input.Event == webhook_module.HookEventPullRequest { - // skip runs with skip ci prefix in commit message if the event is push or pull_request + // skip runs with a configured skip-ci string in commit message if the event is push or pull_request // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs - for _, prefix := range setting.Actions.SkipRunPrefix { - if strings.HasPrefix(commit.CommitMessage, prefix) { - log.Debug("repo %s with commit %s: skipped run because of %s prefix", input.Repo.RepoPath(), commit.ID, prefix) + for _, s := range setting.Actions.SkipRunStrings { + if strings.Contains(commit.CommitMessage, s) { + log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s) return nil } } diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 548322aa4a19..6ab63f58c063 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -203,7 +203,7 @@ func TestSkipCI(t *testing.T) { // create the repo repo, err := repo_service.CreateRepository(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{ - Name: "skip-ci-prefix", + Name: "skip-ci", Description: "test skip ci functionality", AutoInit: true, Gitignores: "Go", @@ -253,7 +253,7 @@ func TestSkipCI(t *testing.T) { // a run has been created assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) - // add a file with [skip ci] prefix in commit message + // add a file with a configured skip-ci string in commit message addFileResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ Files: []*files_service.ChangeRepoFile{ { @@ -262,7 +262,7 @@ func TestSkipCI(t *testing.T) { ContentReader: strings.NewReader("bar"), }, }, - Message: fmt.Sprintf("%s add bar", setting.Actions.SkipRunPrefix[0]), + Message: fmt.Sprintf("%s add bar", setting.Actions.SkipRunStrings[0]), OldBranch: "main", NewBranch: "main", Author: &files_service.IdentityOptions{ @@ -281,7 +281,7 @@ func TestSkipCI(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, addFileResp) - // the commit message contains a [skip ci] prefix, so there is still only 1 record + // the commit message contains a configured skip-ci string, so there is still only 1 record assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID})) }) } From c312fe067e962510ba33e09c38842aa7f5ff82e9 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Thu, 16 Nov 2023 17:03:37 +0100 Subject: [PATCH 04/10] add pull-request-sync --- services/actions/notifier_helper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 343c18e2c08a..84898a8387eb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "fmt" + "slices" "strings" actions_model "code.gitea.io/gitea/models/actions" @@ -145,7 +146,7 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } - if input.Event == webhook_module.HookEventPush || input.Event == webhook_module.HookEventPullRequest { + if slices.Contains([]webhook_module.HookEventType{webhook_module.HookEventPush, webhook_module.HookEventPullRequest, webhook_module.HookEventPullRequestSync}, input.Event) { // skip runs with a configured skip-ci string in commit message if the event is push or pull_request // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs for _, s := range setting.Actions.SkipRunStrings { From 016498c8a962a578721d5ba74664691e70b6ccd1 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Thu, 16 Nov 2023 17:04:55 +0100 Subject: [PATCH 05/10] add pull-request-sync --- services/actions/notifier_helper.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 84898a8387eb..8a662f5fdc66 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -146,8 +146,13 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } - if slices.Contains([]webhook_module.HookEventType{webhook_module.HookEventPush, webhook_module.HookEventPullRequest, webhook_module.HookEventPullRequestSync}, input.Event) { - // skip runs with a configured skip-ci string in commit message if the event is push or pull_request + skipRunEvents := []webhook_module.HookEventType{ + webhook_module.HookEventPush, + webhook_module.HookEventPullRequest, + webhook_module.HookEventPullRequestSync, + } + if slices.Contains(skipRunEvents, input.Event) { + // skip runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs for _, s := range setting.Actions.SkipRunStrings { if strings.Contains(commit.CommitMessage, s) { From 31f85796ce84ebb9f97690cbef1bf0edd9f54bf8 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 17 Nov 2023 17:39:54 +0100 Subject: [PATCH 06/10] move skip ci functionality to function --- services/actions/notifier_helper.go | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 8a662f5fdc66..3719ce362fc8 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -146,20 +146,8 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } - skipRunEvents := []webhook_module.HookEventType{ - webhook_module.HookEventPush, - webhook_module.HookEventPullRequest, - webhook_module.HookEventPullRequestSync, - } - if slices.Contains(skipRunEvents, input.Event) { - // skip runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) - // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs - for _, s := range setting.Actions.SkipRunStrings { - if strings.Contains(commit.CommitMessage, s) { - log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s) - return nil - } - } + if skipped := skipCIRuns(input, commit); skipped { + return nil } var detectedWorkflows []*actions_module.DetectedWorkflow @@ -213,6 +201,25 @@ func notify(ctx context.Context, input *notifyInput) error { return handleWorkflows(ctx, detectedWorkflows, commit, input, ref) } +func skipCIRuns(input *notifyInput, commit *git.Commit) bool { + // skip runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) + // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs + skipRunEvents := []webhook_module.HookEventType{ + webhook_module.HookEventPush, + webhook_module.HookEventPullRequest, + webhook_module.HookEventPullRequestSync, + } + if slices.Contains(skipRunEvents, input.Event) { + for _, s := range setting.Actions.SkipRunStrings { + if strings.Contains(commit.CommitMessage, s) { + log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s) + return true + } + } + } + return false +} + func handleWorkflows( ctx context.Context, detectedWorkflows []*actions_module.DetectedWorkflow, From 693415f3f0eeb15043eb4d7b23f59889c0961a71 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 17 Nov 2023 17:44:53 +0100 Subject: [PATCH 07/10] rename function --- services/actions/notifier_helper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 3719ce362fc8..96b587f23f20 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -146,7 +146,7 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } - if skipped := skipCIRuns(input, commit); skipped { + if skipped := skipWorkflowsForCommit(input, commit); skipped { return nil } @@ -201,7 +201,7 @@ func notify(ctx context.Context, input *notifyInput) error { return handleWorkflows(ctx, detectedWorkflows, commit, input, ref) } -func skipCIRuns(input *notifyInput, commit *git.Commit) bool { +func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool { // skip runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs skipRunEvents := []webhook_module.HookEventType{ From e371c3c330c1992bc0efcb9813714f60bae227fe Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 17 Nov 2023 17:46:28 +0100 Subject: [PATCH 08/10] parameters --- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- modules/setting/actions.go | 8 ++++---- services/actions/notifier_helper.go | 8 ++++---- tests/integration/actions_trigger_test.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index fbc12abfe575..12495a85aaad 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -1396,7 +1396,7 @@ PROXY_HOSTS = *.github.com - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time - `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time -- `SKIP_RUN_STRINGS`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow +- `SKIP_WORKFLOW_STRINGS`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`. diff --git a/modules/setting/actions.go b/modules/setting/actions.go index 175512bc0fe0..9fd484c3b804 100644 --- a/modules/setting/actions.go +++ b/modules/setting/actions.go @@ -22,11 +22,11 @@ var ( ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"` EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"` AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"` - SkipRunStrings []string `ìni:"SKIP_RUN_STRINGS"` + SkipWorkflowStrings []string `ìni:"SKIP_WORKFLOW_STRINGS"` }{ - Enabled: true, - DefaultActionsURL: defaultActionsURLGitHub, - SkipRunStrings: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"}, + Enabled: true, + DefaultActionsURL: defaultActionsURLGitHub, + SkipWorkflowStrings: []string{"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"}, } ) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 96b587f23f20..94bc820148dd 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -202,15 +202,15 @@ func notify(ctx context.Context, input *notifyInput) error { } func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool { - // skip runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) + // skip workflow runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync) // https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs - skipRunEvents := []webhook_module.HookEventType{ + skipWorkflowEvents := []webhook_module.HookEventType{ webhook_module.HookEventPush, webhook_module.HookEventPullRequest, webhook_module.HookEventPullRequestSync, } - if slices.Contains(skipRunEvents, input.Event) { - for _, s := range setting.Actions.SkipRunStrings { + if slices.Contains(skipWorkflowEvents, input.Event) { + for _, s := range setting.Actions.SkipWorkflowStrings { if strings.Contains(commit.CommitMessage, s) { log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s) return true diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 6ab63f58c063..684b93ed1dfc 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -262,7 +262,7 @@ func TestSkipCI(t *testing.T) { ContentReader: strings.NewReader("bar"), }, }, - Message: fmt.Sprintf("%s add bar", setting.Actions.SkipRunStrings[0]), + Message: fmt.Sprintf("%s add bar", setting.Actions.SkipWorkflowStrings[0]), OldBranch: "main", NewBranch: "main", Author: &files_service.IdentityOptions{ From a0207c78941610ff5b365d087994f6eb1d8038ca Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 17 Nov 2023 19:14:37 +0100 Subject: [PATCH 09/10] resolve review comments --- custom/conf/app.example.ini | 4 +++- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- services/actions/notifier_helper.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 325e31af3902..457597e09ee9 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1017,7 +1017,7 @@ LEVEL = Info ;ALLOWED_TYPES = ;; ;; Max size of each file in megabytes. Defaults to 50MB -;FILE_MAX_SIZE = 50 +;FILE_MAX_SIZE = 50 ;; ;; Max number of files per upload. Defaults to 5 ;MAX_FILES = 5 @@ -2583,6 +2583,8 @@ LEVEL = Info ;ENDLESS_TASK_TIMEOUT = 3h ;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time ;ABANDONED_JOB_TIMEOUT = 24h +;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow +;SKIP_WORKFLOW_STRINGS = "[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index 12495a85aaad..e2903428957c 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -1396,7 +1396,7 @@ PROXY_HOSTS = *.github.com - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time - `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time -- `SKIP_WORKFLOW_STRINGS`: **[skip ci]**, **[ci skip]**, **[no ci]**, **[skip actions]**, **[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow +- `SKIP_WORKFLOW_STRINGS`: **"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`. diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 94bc820148dd..1c08cec0073d 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -146,7 +146,7 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %w", err) } - if skipped := skipWorkflowsForCommit(input, commit); skipped { + if skipWorkflowsForCommit(input, commit) { return nil } From 3f7e25aeeed2afdfb4f0b01f4925955916a5e457 Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 17 Nov 2023 19:24:28 +0100 Subject: [PATCH 10/10] use correct ini syntax --- custom/conf/app.example.ini | 2 +- docs/content/administration/config-cheat-sheet.en-us.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 457597e09ee9..18d6fe37a8ba 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2584,7 +2584,7 @@ LEVEL = Info ;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time ;ABANDONED_JOB_TIMEOUT = 24h ;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow -;SKIP_WORKFLOW_STRINGS = "[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]" +;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md index e2903428957c..e7ce7f05b5d2 100644 --- a/docs/content/administration/config-cheat-sheet.en-us.md +++ b/docs/content/administration/config-cheat-sheet.en-us.md @@ -1396,7 +1396,7 @@ PROXY_HOSTS = *.github.com - `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time - `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time - `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time -- `SKIP_WORKFLOW_STRINGS`: **"[skip ci]", "[ci skip]", "[no ci]", "[skip actions]", "[actions skip]"**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow +- `SKIP_WORKFLOW_STRINGS`: **[skip ci],[ci skip],[no ci],[skip actions],[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow `DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path. For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`.