Skip to content
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

Actions Artifacts v4 backend #28965

Merged
merged 37 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5df4665
Actions Artifacts v4 backend
ChristopherHX Feb 2, 2024
d3b4226
fix all other places use http.StatusXxx constants
ChristopherHX Feb 8, 2024
f689531
refactor chunk code to reduce duplication
ChristopherHX Feb 8, 2024
e7ccbea
fix md5 check
ChristopherHX Feb 8, 2024
aedd382
add DeleteArtifact endpoint + test
ChristopherHX Feb 17, 2024
01d82bf
fix lint
ChristopherHX Feb 17, 2024
2dbaedf
Merge branch 'main' of github.com:go-gitea/gitea into gitea-artifacts-v4
ChristopherHX Feb 17, 2024
6f2e550
add comment about v4 zipped artifact
ChristopherHX Feb 17, 2024
fa92d6a
Handle MinioConfig.ServeDirect and cleanup dups
ChristopherHX Feb 18, 2024
374df49
remove old code
ChristopherHX Feb 18, 2024
68ca394
move verifySignature into it's own method
ChristopherHX Feb 18, 2024
f47f679
extract content encoding and unify expire time
ChristopherHX Feb 18, 2024
d48b7c2
Add invalid checksum test / fix fmt
ChristopherHX Feb 18, 2024
fb733ad
fix style
ChristopherHX Feb 18, 2024
db3db91
Merge branch 'main' of github.com:go-gitea/gitea into gitea-artifacts-v4
ChristopherHX Feb 18, 2024
745f100
prefer `setting.GetGeneralTokenSigningSecret()`
ChristopherHX Feb 18, 2024
ff30004
actions.SetArtifactNeedDelete in deleteArtifact
ChristopherHX Feb 18, 2024
68aaa83
Merge branch 'main' of github.com:go-gitea/gitea into gitea-artifacts-v4
ChristopherHX Feb 27, 2024
9df9325
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Feb 29, 2024
22393be
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Feb 29, 2024
129710e
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Feb 29, 2024
82bde15
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
14f6bd5
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
f064f06
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
a2ef3b1
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
b4fa521
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
af77320
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
5be1086
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
85af31d
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
26009dd
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
05e7f13
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
a6881e5
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
9047e50
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
c585870
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 1, 2024
977d26e
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 2, 2024
c305fa7
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 2, 2024
e46283d
Merge branch 'main' into gitea-artifacts-v4
GiteaBot Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 170 additions & 12 deletions routers/api/actions/artifact.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions routers/api/actions/artifact.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ message GetSignedArtifactURLRequest {
message GetSignedArtifactURLResponse {
string signed_url = 1;
}

message DeleteArtifactRequest {
string workflow_run_backend_id = 1;
string workflow_job_run_backend_id = 2;
string name = 3;
}

message DeleteArtifactResponse {
bool ok = 1;
int64 artifact_id = 2;
}
55 changes: 55 additions & 0 deletions routers/api/actions/artifactsv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func ArtifactsV4Routes(prefix string) *web.Route {
m.Post("FinalizeArtifact", r.finalizeArtifact)
m.Post("ListArtifacts", r.listArtifacts)
m.Post("GetSignedArtifactURL", r.getSignedArtifactURL)
m.Post("DeleteArtifact", r.deleteArtifact)
}, ArtifactContexter())
m.Group("", func() {
m.Put("UploadArtifact", r.uploadArtifact)
Expand Down Expand Up @@ -524,3 +525,57 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) {

_, _ = io.Copy(ctx.Resp, file)
}

func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
var req DeleteArtifactRequest

body, err := io.ReadAll(ctx.Req.Body)
if err != nil {
log.Error("Error decode request body: %v", err)
ctx.Error(http.StatusInternalServerError, "Error decode request body")
return
}
err = protojson.Unmarshal(body, &req)
if err != nil {
log.Error("Error decode request body: %v", err)
ctx.Error(http.StatusInternalServerError, "Error decode request body")
return
}
_, runID, ok := validateRunIDV4(ctx, req.WorkflowRunBackendId)
if !ok {
return
}

artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID, ArtifactName: req.Name, ListOptions: db.ListOptions{PageSize: 1}})
if err != nil {
log.Error("Error getting artifacts: %v", err)
ctx.Error(http.StatusInternalServerError, err.Error())
return
}
if len(artifacts) != 1 {
log.Debug("[artifact] handleListArtifacts, no artifacts")
ctx.Error(http.StatusNotFound)
return
}

_, err = db.DeleteByID[actions.ActionArtifact](ctx, artifacts[0].ID)
ChristopherHX marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Error("Error getting artifacts: %v", err)
ctx.Error(http.StatusInternalServerError, err.Error())
return
}

respData := DeleteArtifactResponse{
Ok: true,
ArtifactId: artifacts[0].ID,
}
resp, err := protojson.Marshal(&respData)
if err != nil {
log.Error("Error encode response body: %v", err)
ctx.Error(http.StatusInternalServerError, "Error encode response body")
return
}
ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8")
ctx.Resp.WriteHeader(http.StatusOK)
_, _ = ctx.Resp.Write(resp)
}
18 changes: 18 additions & 0 deletions tests/integration/api_actions_artifact_v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,21 @@ func TestActionsArtifactV4DownloadSingle(t *testing.T) {
body := strings.Repeat("A", 1024)
assert.Equal(t, resp.Body.String(), body)
}

func TestActionsArtifactV4Delete(t *testing.T) {
defer tests.PrepareTestEnv(t)()

token, err := actions_service.CreateAuthorizationToken(48, 792, 193)
assert.NoError(t, err)

// delete artifact by name
req := NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/DeleteArtifact", toProtoJSON(&actions.DeleteArtifactRequest{
Name: "artifact",
WorkflowRunBackendId: "792",
WorkflowJobRunBackendId: "193",
})).AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK)
var deleteResp actions.DeleteArtifactResponse
protojson.Unmarshal(resp.Body.Bytes(), &deleteResp)
assert.True(t, deleteResp.Ok)
}
Loading