-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use UTC as default timezone when schedule Actions cron tasks #31742
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37062c3
fix: use UTC by default
wolfogre 71195ec
test: TestActionScheduleSpec_Parse
wolfogre 49047e7
chore: improve comments
wolfogre a526365
chore: avoid shadow var
wolfogre 10bdf74
Merge branch 'main' into bugfix/actions_cron_timezone
GiteaBot 2317de7
Merge branch 'main' into bugfix/actions_cron_timezone
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestActionScheduleSpec_Parse(t *testing.T) { | ||
// Mock the local timezone is not UTC | ||
local := time.Local | ||
tz, err := time.LoadLocation("Asia/Shanghai") | ||
require.NoError(t, err) | ||
defer func() { | ||
time.Local = local | ||
}() | ||
time.Local = tz | ||
|
||
now, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00") | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
spec string | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "regular", | ||
spec: "0 10 * * *", | ||
want: "2024-07-31T10:00:00Z", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "invalid", | ||
spec: "0 10 * *", | ||
want: "", | ||
wantErr: assert.Error, | ||
}, | ||
{ | ||
name: "with timezone", | ||
spec: "TZ=America/New_York 0 10 * * *", | ||
want: "2024-07-31T14:00:00Z", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "timezone irrelevant", | ||
spec: "@every 5m", | ||
want: "2024-07-31T07:52:55Z", | ||
wantErr: assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := &ActionScheduleSpec{ | ||
Spec: tt.spec, | ||
} | ||
got, err := s.Parse() | ||
tt.wantErr(t, err) | ||
|
||
if err == nil { | ||
assert.Equal(t, tt.want, got.Next(now).UTC().Format(time.RFC3339)) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we handle leading whitespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not "we", it's how "robfig/cron" handle this.
https://github.com/robfig/cron/blob/bc59245fe10efaed9d51b56900192527ed733435/parser.go#L95
If we want to handle leading whitespace, it could be done before storing it into the database.