Skip to content

Commit

Permalink
Add test label
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanNemeth committed Feb 14, 2025
1 parent 7da82fc commit 9b50d88
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 24 deletions.
6 changes: 3 additions & 3 deletions client/src/app/core/modules/openapi/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ export const PullRequestSchema = {
merged: {
type: 'boolean',
},
pullRequest: {
draft: {
type: 'boolean',
},
draft: {
pullRequest: {
type: 'boolean',
},
locked: {
Expand Down Expand Up @@ -855,7 +855,7 @@ export const WorkflowDtoSchema = {
},
label: {
type: 'string',
enum: ['BUILD', 'DEPLOYMENT', 'NONE'],
enum: ['BUILD', 'DEPLOYMENT', 'NONE', 'TEST'],
},
createdAt: {
type: 'string',
Expand Down
6 changes: 3 additions & 3 deletions client/src/app/core/modules/openapi/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export type PullRequest = {
requestedReviewers?: Array<User>;
workflowRuns?: Array<WorkflowRun>;
merged?: boolean;
pullRequest?: boolean;
draft?: boolean;
pullRequest?: boolean;
locked?: boolean;
};

Expand Down Expand Up @@ -266,7 +266,7 @@ export type WorkflowDto = {
url?: string;
htmlUrl?: string;
badgeUrl?: string;
label: 'BUILD' | 'DEPLOYMENT' | 'NONE';
label: 'BUILD' | 'DEPLOYMENT' | 'NONE' | 'TEST';
createdAt?: string;
updatedAt?: string;
};
Expand Down Expand Up @@ -453,7 +453,7 @@ export type BranchDetailsDto = {
};

export type UpdateWorkflowLabelData = {
body: 'BUILD' | 'DEPLOYMENT' | 'NONE';
body: 'BUILD' | 'DEPLOYMENT' | 'NONE' | 'TEST';
path: {
workflowId: number;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ProjectSettingsComponent {
showAddGroupDialog = false;
newGroupName = '';
// Store the previous label temporarily for the confirmation dialog
private previousLabel: 'BUILD' | 'DEPLOYMENT' | 'NONE' = 'NONE';
private previousLabel: 'BUILD' | 'DEPLOYMENT' | 'NONE' | 'TEST' = 'NONE';

// Drag & Drop logic for groupedWorkflowsArray
private dragIndex: number | null = null;
Expand Down Expand Up @@ -253,6 +253,7 @@ export class ProjectSettingsComponent {
<ul class="list-disc list-inside text-sm text-gray-600">
<li><strong>DEPLOYMENT</strong>: This label sets the workflow to trigger server deployments.</li>
<li><strong>BUILD</strong>: This label sets the workflow to trigger build processes.</li>
<li><strong>TEST</strong>: This label sets the workflow to be searched for test artifacts.</li>
<li><strong>NONE</strong>: No label is set for this workflow.</li>
</ul>
</div>
Expand Down
6 changes: 4 additions & 2 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ paths:
- BUILD
- DEPLOYMENT
- NONE
- TEST
required: true
responses:
"200":
Expand Down Expand Up @@ -1344,10 +1345,10 @@ components:
uniqueItems: true
merged:
type: boolean
pullRequest:
type: boolean
draft:
type: boolean
pullRequest:
type: boolean
locked:
type: boolean
required:
Expand Down Expand Up @@ -1553,6 +1554,7 @@ components:
- BUILD
- DEPLOYMENT
- NONE
- TEST
createdAt:
type: string
format: date-time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import de.tum.cit.aet.helios.github.GitHubService;
import de.tum.cit.aet.helios.tests.parsers.JunitParser;
import de.tum.cit.aet.helios.tests.parsers.TestParserResult;
import de.tum.cit.aet.helios.workflow.Workflow;
import de.tum.cit.aet.helios.workflow.WorkflowRun;
import de.tum.cit.aet.helios.workflow.WorkflowService;
import java.io.FilterInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -24,34 +27,42 @@ public class TestResultProcessor {
private final GitHubService gitHubService;
private final TestResultRepository testResultRepository;
private final JunitParser junitParser;
private final WorkflowService workflowService;

@Value("${tests.artifactName:Test Results}")
private String testArtifactName;

@Value("${tests.runName:Test}")
private String testRunName;

public boolean shouldProcess(WorkflowRun workflowRun) {
log.debug(
"Checking if test results should be processed for workflow run {}", workflowRun.getName());

if (!workflowRun.getName().equals(this.testRunName)) {
if (workflowRun.getStatus() != WorkflowRun.Status.COMPLETED) {
return false;
}

if (workflowRun.getStatus() != WorkflowRun.Status.COMPLETED) {
final Workflow testWorkflow =
this.workflowService.getTestWorkflow(workflowRun.getRepository().getRepositoryId());

if (testWorkflow == null || workflowRun.getWorkflowId() != testWorkflow.getId()) {
return false;
}

return this.testResultRepository.findByWorkflowRun(workflowRun).isEmpty();
}

@Async
@Async("testResultProcessorExecutor")
public void processRun(WorkflowRun workflowRun) {
log.debug("Processing test results for workflow run {}", workflowRun.getName());

GHArtifact testResultsArtifact = null;

// thread sleep 2 seconds
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

try {
PagedIterable<GHArtifact> artifacts =
this.gitHubService.getWorkflowRunArtifacts(
Expand Down Expand Up @@ -103,6 +114,10 @@ private List<TestParserResult> processTestResultArtifact(GHArtifact artifact) th
// Download the ZIP artifact, find all parsable XML files and parse them
return artifact.download(
stream -> {
if (stream.available() == 0) {
throw new TestResultException("Empty artifact stream");
}

List<TestParserResult> results = new ArrayList<>();

try (ZipInputStream zipInput = new ZipInputStream(stream)) {
Expand All @@ -111,7 +126,15 @@ private List<TestParserResult> processTestResultArtifact(GHArtifact artifact) th
while ((entry = zipInput.getNextEntry()) != null) {
if (!entry.isDirectory()) {
if (this.junitParser.supports(entry.getName())) {
results.add(this.junitParser.parse(zipInput));
var nonClosingStream =
new FilterInputStream(zipInput) {
@Override
public void close() throws IOException {
// Do nothing, so the underlying stream stays open.
}
};

results.add(this.junitParser.parse(nonClosingStream));
}
}
zipInput.closeEntry();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.tum.cit.aet.helios.tests;

import de.tum.cit.aet.helios.workflow.WorkflowRun;
import java.util.Optional;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TestResultRepository extends JpaRepository<TestResult, Long> {
Optional<TestResult> findByWorkflowRun(WorkflowRun workflowRun);
List<TestResult> findByWorkflowRun(WorkflowRun workflowRun);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.tum.cit.aet.helios.tests;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class TestsConfig {
/**
* Creates a TaskExecutor bean named "testResultProcessorExecutor". This executor is used to
* process test results asynchronously.
*
* @return a configured ThreadPoolTaskExecutor instance
*/
@Bean("testResultProcessorExecutor")
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("test-result-processor-");
return executor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum State {
public enum Label {
BUILD,
DEPLOYMENT,
NONE
NONE,
TEST
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ public Workflow getDeploymentWorkflow(Long repositoryId) {
Workflow.Label.DEPLOYMENT, repositoryId);
return workflow;
}

public Workflow getTestWorkflow(Long repositoryId) {
Workflow workflow =
workflowRepository.findFirstByLabelAndRepositoryRepositoryIdOrderByCreatedAtDesc(
Workflow.Label.TEST, repositoryId);
return workflow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ create table test_result (
references workflow_run ( id )
);

-- We only want one test result per workflow run
create unique index idx_test_result_workflow_run_id on
test_result (
workflow_run_id
);
alter table workflow drop constraint workflow_label_check;

0 comments on commit 9b50d88

Please sign in to comment.