-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add build repository with auto generated build date,sequence and alise
- Loading branch information
Showing
10 changed files
with
270 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.build.model.Build; | ||
import com.flowci.common.model.Variables; | ||
|
||
public interface TriggerBuild { | ||
/** | ||
* Trigger a new build | ||
* | ||
* @param flowId flow id | ||
* @param trigger trigger | ||
* @param inputs extra variables | ||
* @return build object | ||
*/ | ||
Build invoke(Long flowId, Build.Trigger trigger, Variables inputs); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/flowci/build/business/impl/TriggerBuildImpl.java
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,28 @@ | ||
package com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.TriggerBuild; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.build.repo.BuildRepo; | ||
import com.flowci.build.repo.BuildYamlRepo; | ||
import com.flowci.common.model.Variables; | ||
import com.flowci.flow.business.FetchFlow; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@AllArgsConstructor | ||
public class TriggerBuildImpl implements TriggerBuild { | ||
|
||
private final FetchFlow fetchFlow; | ||
|
||
private final BuildRepo buildRepo; | ||
|
||
private final BuildYamlRepo buildYamlRepo; | ||
|
||
@Override | ||
public Build invoke(Long flowId, Build.Trigger trigger, Variables inputs) { | ||
return null; | ||
} | ||
} |
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,82 @@ | ||
package com.flowci.build.model; | ||
|
||
import com.flowci.common.model.EntityBase; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.hibernate.annotations.Generated; | ||
import org.hibernate.generator.EventType; | ||
|
||
import java.util.Set; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false, of = {"id"}) | ||
@Entity | ||
@Table(name = "build") | ||
public class Build extends EntityBase { | ||
|
||
public enum Trigger { | ||
MANUAL, | ||
API, | ||
SCHEDULED, | ||
GIT_PUSH, | ||
GIT_PR_OPEN, | ||
GIT_PR_CLOSE, | ||
GIT_TAG, | ||
} | ||
|
||
public enum Status { | ||
CREATED, // init status | ||
LOADING, // when need to loading yaml from git | ||
QUEUED, // been put to job queue and waiting for agent | ||
ASSIGNED, // assigned to an agent | ||
RUNNING, // agent start to execute the flow | ||
CANCELLING, // will be cancelled, but waiting for response from agent | ||
SUCCESS, | ||
FAILURE, | ||
CANCELLED, | ||
TIMEOUT | ||
} | ||
|
||
public static final Set<Status> FINAL_STATUS = Set.of( | ||
Status.SUCCESS, | ||
Status.FAILURE, | ||
Status.CANCELLED, | ||
Status.TIMEOUT | ||
); | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "build_id_gen") | ||
@SequenceGenerator(name = "build_id_gen", sequenceName = "build_id_sequence", allocationSize = 1) | ||
private Long id; | ||
|
||
private Long flowId; | ||
|
||
// auto generated from db, YYYYMMMDD as integer | ||
@Generated(event = EventType.INSERT) | ||
@Column(name = "build_date", insertable = false, updatable = false, nullable = false) | ||
private Integer buildDate; | ||
|
||
// auto generated from db, sequence ref to build date | ||
@Generated(event = EventType.INSERT) | ||
@Column(name = "build_sequence", insertable = false, updatable = false, nullable = false) | ||
private Long buildSequence; | ||
|
||
// auto generated from db, <buildDate>.<buildSequence> | ||
@Generated(event = EventType.INSERT) | ||
@Column(name = "build_alias", insertable = false, updatable = false, nullable = false) | ||
private String buildAlias; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Trigger trigger; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Status status; | ||
|
||
@Nullable | ||
private String commitHash; | ||
|
||
@Nullable | ||
private Long agentId; | ||
} |
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,26 @@ | ||
package com.flowci.build.model; | ||
|
||
import com.flowci.common.model.EntityBase; | ||
import com.flowci.common.model.Variables; | ||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false, of = "buildId") | ||
@Entity | ||
@Table(name = "build_yaml") | ||
public class BuildYaml extends EntityBase { | ||
|
||
@Id | ||
private Long id; | ||
|
||
// ref to flow variables | ||
@Convert(converter = Variables.AttributeConverter.class) | ||
private Variables variables; | ||
|
||
private String yaml; | ||
} |
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 @@ | ||
package com.flowci.build; |
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,9 @@ | ||
package com.flowci.build.repo; | ||
|
||
import com.flowci.build.model.Build; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface BuildRepo extends JpaRepository<Build, Long> { | ||
} |
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,9 @@ | ||
package com.flowci.build.repo; | ||
|
||
import com.flowci.build.model.BuildYaml; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface BuildYamlRepo extends JpaRepository<BuildYaml, Long> { | ||
} |
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,34 @@ | ||
package com.flowci.build.repo; | ||
|
||
|
||
import com.flowci.SpringTestWithDB; | ||
import com.flowci.build.model.Build; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static com.flowci.TestUtils.newDummyInstance; | ||
import static org.instancio.Select.field; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class BuildRepoTest extends SpringTestWithDB { | ||
|
||
@Autowired | ||
private BuildRepo buildRepo; | ||
|
||
@Test | ||
void givenBuild_whenSaving_thenBuildIsSaved() { | ||
var mockFlowId = 100L; | ||
var build = newDummyInstance(Build.class) | ||
.set(field(Build::getFlowId), mockFlowId) | ||
.ignore(field(Build::getId)) | ||
.ignore(field(Build::getBuildDate)) | ||
.ignore(field(Build::getBuildSequence)) | ||
.ignore(field(Build::getBuildAlias)) | ||
.create(); | ||
|
||
var saved = buildRepo.save(build); | ||
assertNotNull(saved.getBuildDate()); | ||
assertNotNull(saved.getBuildSequence()); | ||
assertNotNull(saved.getBuildSequence()); | ||
} | ||
} |