Skip to content

Commit

Permalink
add initial gitlab ci module
Browse files Browse the repository at this point in the history
closes #423
  • Loading branch information
atomfrede committed Jul 29, 2022
1 parent 35197e7 commit 2125a9d
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.jhipster.lite.generator.ci.gitlab.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.ci.gitlab.domain.GitLabCiModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class GitLabCiApplicationService {

private final GitLabCiModuleFactory factory;

public GitLabCiApplicationService() {
factory = new GitLabCiModuleFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tech.jhipster.lite.generator.ci.gitlab.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
import static tech.jhipster.lite.module.domain.JHipsterModule.to;

import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class GitLabCiModuleFactory {

private static final JHipsterSource SOURCE = from("ci/gitlab");

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

return moduleBuilder(properties).files().add(SOURCE.template(".gitlab-ci-maven.yml.mustache"), to(".gitlab-ci.yml")).and().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tech.jhipster.lite.generator.ci.gitlab.infrastructure.primary;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.ci.gitlab.application.GitLabCiApplicationService;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleApiDoc;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleResource;

@Configuration
class GitLabCiModuleConfiguration {

@Bean
JHipsterModuleResource gitlabCiModule(GitLabCiApplicationService gitlabCi) {
return JHipsterModuleResource
.builder()
.legacyUrl("/api/developer-tools/gitlab-ci")
.slug("gitlab-ci")
.withoutProperties()
.apiDoc(new JHipsterModuleApiDoc("Continuous Integration", "Add GitLab CI for Maven Build"))
.tags("ci", "gitlab")
.factory(gitlabCi::buildModule);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.BusinessContext
package tech.jhipster.lite.generator.ci.gitlab;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

image: eclipse-temurin:17

# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository

stages:
- test

Test:run-tests:
stage: test
script:
- ./mvnw $MAVEN_CLI_OPTS clean verify
interruptible: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tech.jhipster.lite.generator.ci.gitlab.domain;

import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModule;

import org.junit.jupiter.api.Test;
import tech.jhipster.lite.TestFileUtils;
import tech.jhipster.lite.UnitTest;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterModulesFixture;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@UnitTest
class GitLabCiModuleFactoryTest {

private static final GitLabCiModuleFactory factory = new GitLabCiModuleFactory();

@Test
void shouldBuildModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).build();

JHipsterModule module = factory.buildModule(properties);

assertThatModule(module).createFiles(".gitlab-ci.yml");
}
}

0 comments on commit 2125a9d

Please sign in to comment.