@@ -31,7 +31,7 @@ func init() {
3131// ActionArtifact is a file that is stored in the artifact storage.
3232type ActionArtifact struct {
3333 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
3535 RunnerID int64
3636 RepoID int64 `xorm:"index"`
3737 OwnerID int64
@@ -40,27 +40,28 @@ type ActionArtifact struct {
4040 FileSize int64 // The size of the artifact in bytes
4141 FileCompressedSize int64 // The size of the artifact in bytes after gzip compression
4242 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
4646 CreatedUnix timeutil.TimeStamp `xorm:"created"`
4747 UpdatedUnix timeutil.TimeStamp `xorm:"updated index"`
4848}
4949
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 ) {
5251 if err := t .LoadJob (ctx ); err != nil {
5352 return nil , err
5453 }
55- artifact , err := getArtifactByArtifactName (ctx , t .Job .RunID , artifactName )
54+ artifact , err := getArtifactByNameAndPath (ctx , t .Job .RunID , artifactName , artifactPath )
5655 if errors .Is (err , util .ErrNotExist ) {
5756 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 ,
6465 }
6566 if _ , err := db .GetEngine (ctx ).Insert (artifact ); err != nil {
6667 return nil , err
@@ -72,9 +73,9 @@ func CreateArtifact(ctx context.Context, t *ActionTask, artifactName string) (*A
7273 return artifact , nil
7374}
7475
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 ) {
7677 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 )
7879 if err != nil {
7980 return nil , err
8081 } else if ! has {
@@ -120,3 +121,9 @@ func ListArtifactsByRepoID(ctx context.Context, repoID int64) ([]*ActionArtifact
120121 arts := make ([]* ActionArtifact , 0 , 10 )
121122 return arts , db .GetEngine (ctx ).Where ("repo_id=?" , repoID ).Find (& arts )
122123}
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