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

Development: Improve exercise configuration for GitLab CI #9608

Merged
merged 62 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e21d669
Fix setup instructions and minor bugs
bensofficial Jul 20, 2023
d78a764
Add REST endpoint to view build plan of a exercise
bensofficial Jul 20, 2023
970f801
Update version of notification plugin
bensofficial Jul 21, 2023
bace35a
Merge branch 'develop' into fix/gitlab-ci
bensofficial Jul 21, 2023
676adba
Improve CI variable setup
bensofficial Jul 23, 2023
5bd2130
Fix test
bensofficial Jul 23, 2023
60996f1
Fix tests
bensofficial Jul 23, 2023
50f18a8
Fix test
bensofficial Jul 23, 2023
0a6fea2
Improve test case
bensofficial Jul 23, 2023
6fe7941
Fix test
bensofficial Jul 23, 2023
5df6f8c
Rename run configuration
bensofficial Jul 27, 2023
ec51711
Merge branch 'develop' into fix/gitlab-ci
bensofficial Aug 14, 2023
2bf2cbd
Implement overwrite feature
bensofficial Aug 16, 2023
d0a5332
Rename methods and add overwrite for build plan creation
bensofficial Aug 16, 2023
ab7af1c
Update run script
bensofficial Aug 16, 2023
51b32ab
Add timeouts
bensofficial Aug 16, 2023
6a9c533
Remove allow_failure
bensofficial Aug 16, 2023
a9f4edf
Merge branch 'develop' into fix/gitlab-ci
bensofficial Aug 22, 2023
e4df3bf
Merge branch 'develop' into fix/gitlab-ci
bensofficial Sep 23, 2023
86ce8b3
Merge branch 'develop' into fix/gitlab-ci
bensofficial Sep 23, 2023
1b332ac
Update setup documentation and fix bugs
bensofficial Sep 23, 2023
e9bc651
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 2, 2023
78ec4f7
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 3, 2023
ed02781
Merge branch 'develop' into fix/gitlab-ci
bensofficial Oct 4, 2023
ecf6364
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 4, 2023
80cfab0
Add saveAndFlush() before triggerBuild()
bensofficial Oct 4, 2023
c679856
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 5, 2023
8b6ec03
Merge branch 'fix/gitlab-ci-setup' of ssh://github.com/ls1intum/Artem…
bensofficial Oct 5, 2023
f0c7509
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 8, 2023
6e62644
Remove saveAndFlush()
bensofficial Oct 8, 2023
c33d9a3
Refactor trigger
bensofficial Oct 8, 2023
5b07511
Fix build plan id for creation of participation
bensofficial Oct 8, 2023
df4ea40
Merge branch 'develop' into fix/gitlab-ci
bensofficial Oct 10, 2023
c26e0da
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 10, 2023
ffdc6fd
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Oct 24, 2023
8beed6d
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 9, 2024
804bb28
Remove fix
bensofficial Feb 12, 2024
1cff56a
Fix compile error
bensofficial Feb 12, 2024
f96e0fd
Remove gitlab from migration
bensofficial Feb 12, 2024
c10df02
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 12, 2024
9827b14
Enable TS10
bensofficial Feb 12, 2024
d88c104
Merge branch 'fix/gitlab-ci-setup' of ssh://github.com/ls1intum/Artem…
bensofficial Feb 12, 2024
4c90818
Merge branch 'develop' into fix/gitlab-ci-setup
bensofficial Feb 16, 2024
b3cf7c5
Merge branch 'fix/gitlab-ci-setup' into fix/gitlab-ci
bensofficial Feb 16, 2024
3aebe47
Merge branch 'develop' into fix/gitlab-ci
bensofficial Apr 4, 2024
ae4c731
Merge branch 'develop' of github.com:ls1intum/Artemis into fix/gitlab-ci
bensofficial Apr 11, 2024
f478934
Revert: Show build plans to students
bensofficial Apr 11, 2024
a9afd80
Remove TS
bensofficial Apr 11, 2024
0d80263
Add token generation
bensofficial Apr 11, 2024
11a853d
Fix test
bensofficial Apr 11, 2024
6f94ee6
Merge branch 'develop' of github.com:ls1intum/Artemis into fix/gitlab-ci
bensofficial Aug 26, 2024
e106f8a
Rename method
bensofficial Aug 26, 2024
be8c66a
Merge branch 'develop' of github.com:ls1intum/Artemis into fix/gitlab-ci
bensofficial Sep 10, 2024
a07fa6c
Revert changes in .gitlab-ci.yml templates
bensofficial Sep 10, 2024
1896223
Remove todos and log unsupported actions as debug
bensofficial Sep 10, 2024
28a4097
Fix build and tests
bensofficial Sep 10, 2024
286a5b5
Change log level for unsupported action in GitLabCIUserManagementServ…
bensofficial Sep 10, 2024
d1b6c8d
Fix .gitlab-ci.yml and project token generation
bensofficial Sep 10, 2024
697e692
Fix
bensofficial Oct 22, 2024
acbea2a
Fix compile error
bensofficial Oct 27, 2024
f2e7dc5
Merge branch 'develop' of github.com:ls1intum/Artemis into fix/gitlab-ci
bensofficial Oct 27, 2024
47bb320
Fix coderabbit issues
bensofficial Oct 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ Optional<ProgrammingExercise> findWithTemplateAndSolutionParticipationTeamAssign
@EntityGraph(type = LOAD, attributePaths = "submissionPolicy")
List<ProgrammingExercise> findWithSubmissionPolicyByProjectKey(String projectKey);

@EntityGraph(type = LOAD, attributePaths = { "buildConfig" })
Optional<ProgrammingExercise> findWithBuildConfigById(long exerciseId);

/**
* Finds one programming exercise including its submission policy by the exercise's project key.
*
Expand Down Expand Up @@ -743,6 +746,18 @@ default ProgrammingExercise findForCreationByIdElseThrow(long programmingExercis
return getValueElseThrow(findForCreationById(programmingExerciseId), programmingExerciseId);
}

/**
* Find a programming exercise by its id, with eagerly loaded build config.
*
* @param programmingExerciseId of the programming exercise.
* @return The programming exercise related to the given id
* @throws EntityNotFoundException the programming exercise could not be found.
*/
@NotNull
default ProgrammingExercise findByIdWithBuildConfigElseThrow(long programmingExerciseId) throws EntityNotFoundException {
return getValueElseThrow(findWithBuildConfigById(programmingExerciseId), programmingExerciseId);
}

/**
* Saves the given programming exercise to the database.
* <p>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public void updateCoursePermissions(Course updatedCourse, String oldInstructorGr
}

private void logUnsupportedAction() {
log.error("Please refer to the repository for user management.");
log.debug("Please refer to the repository for user management.");
bensofficial marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ test-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
allow_failure: true
refs:
- triggers
variables:
GIT_STRATEGY: none
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=[yyyy-MM-dd'T'HH:mm:ssX] -Dorg.slf4j.simpleLogger.logFile=${ARTEMIS_BUILD_LOGS_FILE}
script:
- git clone --branch ${ARTEMIS_TEST_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${ARTEMIS_TEST_GIT_REPOSITORY_SLUG} .
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- export ARTEMIS_NOTIFICATION_SECRET=[hidden] # Workaround for overwriting the secret
- export ARTEMIS_TEST_GIT_TOKEN=[hidden]
# TODO: Install dependencies not provided by the Docker image
Expand All @@ -41,6 +42,8 @@ upload-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
refs:
- triggers
variables:
GIT_STRATEGY: none
script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ test-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
allow_failure: true
refs:
- triggers
variables:
GIT_STRATEGY: none
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=[yyyy-MM-dd'T'HH:mm:ssX] -Dorg.slf4j.simpleLogger.logFile=${ARTEMIS_BUILD_LOGS_FILE}
script:
- git clone --branch ${ARTEMIS_TEST_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${ARTEMIS_TEST_GIT_REPOSITORY_SLUG} .
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- export ARTEMIS_NOTIFICATION_SECRET=[hidden] # Workaround for overwriting the secret
- export ARTEMIS_TEST_GIT_TOKEN=[hidden]
- mvn test -B && echo "ARTEMIS_BUILD_STATUS=success" > .env || echo "ARTEMIS_BUILD_STATUS=failed" > .env
Expand All @@ -38,6 +39,8 @@ upload-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
refs:
- triggers
variables:
GIT_STRATEGY: none
script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ test-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
allow_failure: true
refs:
- triggers
variables:
GIT_STRATEGY: none
script:
- git clone --branch ${ARTEMIS_TEST_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${ARTEMIS_TEST_GIT_REPOSITORY_SLUG} .
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://${ARTEMIS_TEST_GIT_USER}:${ARTEMIS_TEST_GIT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- git clone --branch ${ARTEMIS_SUBMISSION_GIT_BRANCH} ${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME} assignment
- export ARTEMIS_NOTIFICATION_SECRET=[hidden] # Workaround for overwriting the secret
- export ARTEMIS_TEST_GIT_TOKEN=[hidden]
- cargo nextest run --profile ci | tee -a "${ARTEMIS_BUILD_LOGS_FILE}" && echo "ARTEMIS_BUILD_STATUS=success" > .env || echo "ARTEMIS_BUILD_STATUS=failed" > .env
Expand All @@ -39,6 +40,8 @@ upload-job:
only:
variables:
- $CI_COMMIT_BRANCH == $ARTEMIS_SUBMISSION_GIT_BRANCH
refs:
- triggers
variables:
GIT_STRATEGY: none
script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.gitlab4j.api.models.AccessLevel.GUEST;
import static org.gitlab4j.api.models.AccessLevel.MAINTAINER;
import static org.gitlab4j.api.models.AccessLevel.REPORTER;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyLong;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.gitlab4j.api.models.PipelineFilter;
import org.gitlab4j.api.models.PipelineStatus;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectAccessToken;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProtectedBranch;
import org.gitlab4j.api.models.PushData;
Expand Down Expand Up @@ -919,6 +921,15 @@ public void mockUpdateProject(boolean shouldFail) throws GitLabApiException {
}
}

public void mockCreateProjectAccessToken(boolean shouldFail) throws GitLabApiException {
if (shouldFail) {
doThrow(new GitLabApiException("Internal Error", 500)).when(projectApi).createProjectAccessToken(anyString(), anyString(), anyList(), any(), anyLong());
}
else {
doReturn(new ProjectAccessToken()).when(projectApi).createProjectAccessToken(anyString(), anyString(), anyList(), any(), anyLong());
}
}

public void mockGetBuildStatus(PipelineStatus pipelineStatus) throws GitLabApiException {
Pipeline pipeline = new Pipeline();
pipeline.setId(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,18 @@ void testTriggerBuildFails() throws GitLabApiException {
void testConfigureBuildPlanSuccess() throws Exception {
final ProgrammingExercise exercise = programmingExerciseRepository.findWithBuildConfigById(programmingExerciseId).orElseThrow();
final ProgrammingExerciseStudentParticipation participation = participationUtilService.addStudentParticipationForProgrammingExercise(exercise, TEST_PREFIX + "student1");
final String repositoryPath = uriService.getRepositoryPathFromRepositoryUri(participation.getVcsRepositoryUri());
mockConfigureBuildPlan(participation, defaultBranch);

continuousIntegrationService.configureBuildPlan(participation, defaultBranch);

verifyMocks();
verify(gitlab, atLeastOnce()).getProjectApi();
verify(gitlab.getProjectApi(), atLeastOnce()).getProject(eq(repositoryPath));
verify(gitlab.getProjectApi(), atLeastOnce()).updateProject(any(Project.class));
verify(gitlab.getProjectApi(), atLeastOnce()).getOptionalVariable(eq(repositoryPath), anyString());
verify(gitlab.getProjectApi(), atLeastOnce()).createVariable(eq(repositoryPath), anyString(), anyString(), any(), anyBoolean(), anyBoolean());
verify(gitlab.getGroupApi(), never()).createVariable(anyString(), anyString(), anyString(), anyBoolean(), anyBoolean());
}

@Test
Expand All @@ -198,9 +207,16 @@ void testCreateBuildPlanForExercise() throws GitLabApiException {
continuousIntegrationService.createBuildPlanForExercise(exercise, "TEST-EXERCISE", participation.getVcsRepositoryUri(), null, null);

verify(gitlab, atLeastOnce()).getProjectApi();
verify(gitlab, atLeastOnce()).getGroupApi();

verify(gitlab.getProjectApi(), atLeastOnce()).getProject(eq(repositoryPath));
verify(gitlab.getProjectApi(), atLeastOnce()).updateProject(any(Project.class));
verify(gitlab.getProjectApi(), atLeastOnce()).getOptionalVariable(any(), anyString());
verify(gitlab.getProjectApi(), atLeastOnce()).createVariable(anyString(), anyString(), anyString(), any(), anyBoolean(), anyBoolean());

verify(gitlab.getGroupApi(), atLeastOnce()).getOptionalVariable(any(), anyString());
verify(gitlab.getGroupApi(), atLeastOnce()).createVariable(anyString(), anyString(), anyString(), anyBoolean(), anyBoolean());

var buildPlanOptional = buildPlanRepository.findByProgrammingExercises_IdWithProgrammingExercises(exercise.getId());
assertThat(buildPlanOptional).isPresent();
assertThat(buildPlanOptional.get().getBuildPlan()).isNotBlank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
import java.util.Optional;
import java.util.Set;

import jakarta.validation.constraints.NotNull;

import org.hibernate.Hibernate;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise;
import de.tum.cit.aet.artemis.programming.repository.ProgrammingExerciseRepository;

Expand Down Expand Up @@ -90,11 +87,6 @@ default List<ProgrammingExercise> findAllWithBuildAndTestAfterDueDateInFuture()

List<ProgrammingExercise> findAllByCourse_TeachingAssistantGroupNameIn(Set<String> groupNames);

@NotNull
default ProgrammingExercise findByIdWithBuildConfigElseThrow(long programmingExerciseId) throws EntityNotFoundException {
return getValueElseThrow(findWithBuildConfigById(programmingExerciseId), programmingExerciseId);
}

@EntityGraph(type = LOAD, attributePaths = { "templateParticipation", "solutionParticipation", "studentParticipations.team.students", "buildConfig" })
Optional<ProgrammingExercise> findWithAllParticipationsAndBuildConfigById(long exerciseId);

Expand All @@ -107,9 +99,6 @@ default ProgrammingExercise findByIdWithBuildConfigElseThrow(long programmingExe
""")
Optional<ProgrammingExercise> findWithEagerTemplateAndSolutionParticipationsById(@Param("exerciseId") long exerciseId);

@EntityGraph(type = LOAD, attributePaths = { "buildConfig" })
Optional<ProgrammingExercise> findWithBuildConfigById(long exerciseId);

/**
* Fetch the programming exercise with the build config, or throw an EntityNotFoundException if it cannot be found.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public void mockConfigureBuildPlan(ProgrammingExerciseParticipation participatio
public void mockAddBuildPlanToGitLabRepositoryConfiguration(boolean shouldFail) throws GitLabApiException {
gitlabRequestMockProvider.mockGetProject(shouldFail);
gitlabRequestMockProvider.mockUpdateProject(shouldFail);
gitlabRequestMockProvider.mockCreateProjectAccessToken(shouldFail);
}

@Override
Expand Down
Loading