@@ -31,7 +31,7 @@ func init() {
31
31
// ActionArtifact is a file that is stored in the artifact storage.
32
32
type ActionArtifact struct {
33
33
ID int64 `xorm:"pk autoincr"`
34
- RunID int64 `xorm:"index UNIQUE(runid_name )"` // The run id of the artifact
34
+ RunID int64 `xorm:"index index(runid_name_path )"` // The run id of the artifact
35
35
RunnerID int64
36
36
RepoID int64 `xorm:"index"`
37
37
OwnerID int64
@@ -40,27 +40,28 @@ type ActionArtifact struct {
40
40
FileSize int64 // The size of the artifact in bytes
41
41
FileCompressedSize int64 // The size of the artifact in bytes after gzip compression
42
42
ContentEncoding string // The content encoding of the artifact
43
- ArtifactPath string // The path to the artifact when runner uploads it
44
- ArtifactName string `xorm:"UNIQUE(runid_name )"` // The name of the artifact when runner uploads it
45
- Status int64 `xorm:"index"` // The status of the artifact, uploading, expired or need-delete
43
+ ArtifactPath string `xorm:"index index(runid_name_path)"` // The path to the artifact when runner uploads it
44
+ ArtifactName string `xorm:"index index(runid_name_path )"` // The name of the artifact when runner uploads it
45
+ Status int64 `xorm:"index"` // The status of the artifact, uploading, expired or need-delete
46
46
CreatedUnix timeutil.TimeStamp `xorm:"created"`
47
47
UpdatedUnix timeutil.TimeStamp `xorm:"updated index"`
48
48
}
49
49
50
- // CreateArtifact create a new artifact with task info or get same named artifact in the same run
51
- func CreateArtifact (ctx context.Context , t * ActionTask , artifactName string ) (* ActionArtifact , error ) {
50
+ func CreateArtifact (ctx context.Context , t * ActionTask , artifactName , artifactPath string ) (* ActionArtifact , error ) {
52
51
if err := t .LoadJob (ctx ); err != nil {
53
52
return nil , err
54
53
}
55
- artifact , err := getArtifactByArtifactName (ctx , t .Job .RunID , artifactName )
54
+ artifact , err := getArtifactByNameAndPath (ctx , t .Job .RunID , artifactName , artifactPath )
56
55
if errors .Is (err , util .ErrNotExist ) {
57
56
artifact := & ActionArtifact {
58
- RunID : t .Job .RunID ,
59
- RunnerID : t .RunnerID ,
60
- RepoID : t .RepoID ,
61
- OwnerID : t .OwnerID ,
62
- CommitSHA : t .CommitSHA ,
63
- Status : ArtifactStatusUploadPending ,
57
+ ArtifactName : artifactName ,
58
+ ArtifactPath : artifactPath ,
59
+ RunID : t .Job .RunID ,
60
+ RunnerID : t .RunnerID ,
61
+ RepoID : t .RepoID ,
62
+ OwnerID : t .OwnerID ,
63
+ CommitSHA : t .CommitSHA ,
64
+ Status : ArtifactStatusUploadPending ,
64
65
}
65
66
if _ , err := db .GetEngine (ctx ).Insert (artifact ); err != nil {
66
67
return nil , err
@@ -72,9 +73,9 @@ func CreateArtifact(ctx context.Context, t *ActionTask, artifactName string) (*A
72
73
return artifact , nil
73
74
}
74
75
75
- func getArtifactByArtifactName (ctx context.Context , runID int64 , name string ) (* ActionArtifact , error ) {
76
+ func getArtifactByNameAndPath (ctx context.Context , runID int64 , name , fpath string ) (* ActionArtifact , error ) {
76
77
var art ActionArtifact
77
- has , err := db .GetEngine (ctx ).Where ("run_id = ? AND artifact_name = ?" , runID , name ).Get (& art )
78
+ has , err := db .GetEngine (ctx ).Where ("run_id = ? AND artifact_name = ? AND artifact_path = ? " , runID , name , fpath ).Get (& art )
78
79
if err != nil {
79
80
return nil , err
80
81
} else if ! has {
@@ -120,3 +121,9 @@ func ListArtifactsByRepoID(ctx context.Context, repoID int64) ([]*ActionArtifact
120
121
arts := make ([]* ActionArtifact , 0 , 10 )
121
122
return arts , db .GetEngine (ctx ).Where ("repo_id=?" , repoID ).Find (& arts )
122
123
}
124
+
125
+ // ListArtifactsByRunIDAndName returns artifacts by name of a run
126
+ func ListArtifactsByRunIDAndName (ctx context.Context , runID int64 , name string ) ([]* ActionArtifact , error ) {
127
+ arts := make ([]* ActionArtifact , 0 , 10 )
128
+ return arts , db .GetEngine (ctx ).Where ("run_id=? AND artifact_name=?" , runID , name ).Find (& arts )
129
+ }
0 commit comments