-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Artifacts retention and auto clean up #26131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f8a93c1
add artifact retention support and clean up cron task
fuxiaohei 0c4aaf1
support custom retention days from upload-actions
fuxiaohei d6a7200
show unclickable text when artifact is expxired in repo view page
fuxiaohei f690e2a
missing license header
fuxiaohei 0c64d9c
Merge branch 'main' into feat/artifact-retention
fuxiaohei c94b163
use query string to pass through retention days to next uploading req…
fuxiaohei 0016a7a
use query string to pass artifact retention days, fix test failures
fuxiaohei 5140cdc
update list artifact methods
fuxiaohei aa3154c
Merge remote-tracking branch 'origin' into feat/artifact-retention
fuxiaohei c0d531d
Merge remote-tracking branch 'origin' into feat/artifact-retention
fuxiaohei 9c4738a
add expired_unix column in artifact table migration
fuxiaohei bac5707
fix lint problem
fuxiaohei 92998d7
Merge branch 'main' into feat/artifact-retention
fuxiaohei 786fa2e
add docs for artifact clean task
fuxiaohei 5db8297
Merge branch 'main' into feat/artifact-retention
fuxiaohei ef07143
Merge branch 'main' into feat/artifact-retention
GiteaBot ba784d8
Merge branch 'main' into feat/artifact-retention
GiteaBot 102efd8
Merge branch 'main' into feat/artifact-retention
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_21 //nolint | ||
import ( | ||
"time" | ||
|
||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func AddExpiredUnixColumnInActionArtifactTable(x *xorm.Engine) error { | ||
type ActionArtifact struct { | ||
ExpiredUnix timeutil.TimeStamp `xorm:"index"` // time when the artifact will be expired | ||
} | ||
if err := x.Sync(new(ActionArtifact)); err != nil { | ||
return err | ||
} | ||
return updateArtifactsExpiredUnixTo90Days(x) | ||
} | ||
|
||
func updateArtifactsExpiredUnixTo90Days(x *xorm.Engine) error { | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
expiredTime := time.Now().AddDate(0, 0, 90).Unix() | ||
if _, err := sess.Exec(`UPDATE action_artifact SET expired_unix=? WHERE status='2' AND expired_unix is NULL`, expiredTime); err != nil { | ||
return err | ||
} | ||
|
||
return sess.Commit() | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/storage" | ||
) | ||
|
||
// Cleanup removes expired actions logs, data and artifacts | ||
func Cleanup(taskCtx context.Context, olderThan time.Duration) error { | ||
// TODO: clean up expired actions logs | ||
|
||
// clean up expired artifacts | ||
return CleanupArtifacts(taskCtx) | ||
} | ||
|
||
// CleanupArtifacts removes expired artifacts and set records expired status | ||
func CleanupArtifacts(taskCtx context.Context) error { | ||
artifacts, err := actions.ListNeedExpiredArtifacts(taskCtx) | ||
if err != nil { | ||
return err | ||
} | ||
log.Info("Found %d expired artifacts", len(artifacts)) | ||
for _, artifact := range artifacts { | ||
if err := storage.ActionsArtifacts.Delete(artifact.StoragePath); err != nil { | ||
log.Error("Cannot delete artifact %d: %v", artifact.ID, err) | ||
continue | ||
} | ||
if err := actions.SetArtifactExpired(taskCtx, artifact.ID); err != nil { | ||
log.Error("Cannot set artifact %d expired: %v", artifact.ID, err) | ||
continue | ||
} | ||
log.Info("Artifact %d set expired", artifact.ID) | ||
} | ||
return nil | ||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.