-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Artifacts download api for artifact actions v4 #33510
Merged
wxiaoguang
merged 47 commits into
go-gitea:main
from
ChristopherHX:artifacts-download-api
Feb 16, 2025
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
32b6aef
Artifacts download api for artifact actions v4
ChristopherHX f7a1dca
Update swagger docs
ChristopherHX 3f0cafd
fix swagger
ChristopherHX ef5b069
format code
ChristopherHX 26514c9
use MakeAbsoluteURL
ChristopherHX e7308ac
fix lint? swagger command defect?
ChristopherHX e129fe8
revert encoding /
ChristopherHX d5520bd
302 => http.StatusFound
ChristopherHX d3dbfcb
extract getArtifactByID into a helper function
ChristopherHX d50358f
move old and new logic to modules
ChristopherHX bbb7017
fixup
ChristopherHX fcb8d55
intial tests
ChristopherHX db619c3
use correct json lib
ChristopherHX f4b0811
use http.ServeContent
ChristopherHX c6f1557
fix tests
ChristopherHX dfae484
use MakeAbsoluteURL
ChristopherHX ae2202d
add copyright header
ChristopherHX b4c318c
more tests fix old type from my side
ChristopherHX 5e3c79d
fmt code
ChristopherHX b1b0ef3
add DeleteArtifact api
ChristopherHX e1ce404
Merge branch 'main' of https://github.com/go-gitea/gitea into artifac…
ChristopherHX 59cf964
fix some swagger docu issues
ChristopherHX 4721100
use repository apiurl method
ChristopherHX 7a35443
remove unused ctx
ChristopherHX e137972
Merge branch 'main' into artifacts-download-api
ChristopherHX 44bde87
fix merge
ChristopherHX a18c8dd
fix private repository artifact download redirect
ChristopherHX f8ce2f6
fmt
ChristopherHX 5b76dbe
fix import
ChristopherHX 6009e63
Merge branch 'main' into artifacts-download-api
silverwind 8485044
add download test for private repo and remove the token to the redirect
ChristopherHX f58f33d
Merge branch 'main' into artifacts-download-api
wxiaoguang d56cebf
refactor path parm & error handling
wxiaoguang ee37003
fix type casting
wxiaoguang 5d7bf81
refactor getArtifactByPathParam
wxiaoguang 3d1b156
refactor build endpoint
wxiaoguang e6629fc
remove repoAssignment for raw endpoint
wxiaoguang 7861808
fix test
wxiaoguang 8e48777
fix comment
wxiaoguang 421b7b4
remove TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerMis…
ChristopherHX a00f7f8
Update test comments and names to reflect only repo check
ChristopherHX 156f0db
use unix timestamp in sig
ChristopherHX 3df911a
fix comment
ChristopherHX 4c1399d
revert owner_id changes to reflect only repoid check
ChristopherHX a0ed53d
Update routers/api/v1/repo/action.go
wxiaoguang 12c627a
Merge branch 'main' into artifacts-download-api
wxiaoguang f80f4d1
Merge branch 'main' into artifacts-download-api
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
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,48 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"net/http" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/storage" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
// Artifacts using the v4 backend are stored as a single combined zip file per artifact on the backend | ||
// The v4 backend ensures ContentEncoding is set to "application/zip", which is not the case for the old backend | ||
func IsArtifactV4(art *actions_model.ActionArtifact) bool { | ||
return art.ArtifactName+".zip" == art.ArtifactPath && art.ContentEncoding == "application/zip" | ||
} | ||
|
||
func DownloadArtifactV4ServeDirectOnly(ctx *context.Base, art *actions_model.ActionArtifact) (bool, error) { | ||
if setting.Actions.ArtifactStorage.ServeDirect() { | ||
u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, nil) | ||
if u != nil && err == nil { | ||
ctx.Redirect(u.String(), http.StatusFound) | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
func DownloadArtifactV4Fallback(ctx *context.Base, art *actions_model.ActionArtifact) error { | ||
f, err := storage.ActionsArtifacts.Open(art.StoragePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
http.ServeContent(ctx.Resp, ctx.Req, art.ArtifactName+".zip", art.CreatedUnix.AsLocalTime(), f) | ||
return nil | ||
} | ||
|
||
func DownloadArtifactV4(ctx *context.Base, art *actions_model.ActionArtifact) error { | ||
ok, err := DownloadArtifactV4ServeDirectOnly(ctx, art) | ||
if ok || err != nil { | ||
return err | ||
} | ||
return DownloadArtifactV4Fallback(ctx, art) | ||
} |
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
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
Oops, something went wrong.
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.
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.
I think this
err
should be returned if it's not nilThere 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.
You are right, currently the error return value seems to be accidentally not returned.
But I want to make sure we get the expected behavior here, therefore I want some discussion about this before making changes
If we just return the error here (without changing the callers), this error may get returned by the api instead of triggering the fallback ( tunneling blob via gitea ).
What do we want to do with this error?
ServeDirect
in this repoThere 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.
I think it's fine to keep as other behaviors, no need to introduce too many changes at the moment.
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.
Yes. I think it's OK to keep the current behavior. Maybe we can add some logs for this error later to help us debug cases where
SERVE_DIRECT
doesn't work.