forked from jhipster/jhipster-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds the feature of generation a GitHub Actions YML file to the generated projects see https://github.com/features/actions Fix jhipster#422
- Loading branch information
Showing
12 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ch/jhipster/lite/generator/githubactions/application/GithubActionsApplicationService.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,23 @@ | ||
package tech.jhipster.lite.generator.githubactions.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import tech.jhipster.lite.generator.githubactions.domain.GithubActionsService; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
@Service | ||
public class GithubActionsApplicationService { | ||
|
||
private final GithubActionsService githubActionsService; | ||
|
||
public GithubActionsApplicationService(GithubActionsService githubActionsService) { | ||
this.githubActionsService = githubActionsService; | ||
} | ||
|
||
public void init(Project project) { | ||
githubActionsService.init(project); | ||
} | ||
|
||
public void addYml(Project project) { | ||
githubActionsService.addYml(project); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...in/java/tech/jhipster/lite/generator/githubactions/domain/GithubActionsDomainService.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,27 @@ | ||
package tech.jhipster.lite.generator.githubactions.domain; | ||
|
||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
|
||
public class GithubActionsDomainService implements GithubActionsService { | ||
|
||
public static final String SOURCE = "githubactions"; | ||
public static final String GITHUB_ACTIONS_FOLDER = ".github/workflows/"; | ||
public static final String GITHUB_ACTIONS_YML = "github-actions.yml.mustache"; | ||
|
||
private final ProjectRepository projectRepository; | ||
|
||
public GithubActionsDomainService(ProjectRepository projectRepository) { | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Override | ||
public void init(Project project) { | ||
addYml(project); | ||
} | ||
|
||
@Override | ||
public void addYml(Project project) { | ||
projectRepository.template(project, SOURCE, GITHUB_ACTIONS_YML, GITHUB_ACTIONS_FOLDER); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/tech/jhipster/lite/generator/githubactions/domain/GithubActionsService.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,9 @@ | ||
package tech.jhipster.lite.generator.githubactions.domain; | ||
|
||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
public interface GithubActionsService { | ||
void init(Project project); | ||
|
||
void addYml(Project project); | ||
} |
23 changes: 23 additions & 0 deletions
23
...er/lite/generator/githubactions/infrastructure/config/GithubActionsBeanConfiguration.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,23 @@ | ||
package tech.jhipster.lite.generator.githubactions.infrastructure.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.objenesis.SpringObjenesis; | ||
import tech.jhipster.lite.generator.githubactions.domain.GithubActionsDomainService; | ||
import tech.jhipster.lite.generator.githubactions.domain.GithubActionsService; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
|
||
@Configuration | ||
public class GithubActionsBeanConfiguration { | ||
|
||
private final ProjectRepository projectRepository; | ||
|
||
public GithubActionsBeanConfiguration(ProjectRepository projectRepository) { | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Bean | ||
public GithubActionsService githubActionsService() { | ||
return new GithubActionsDomainService(projectRepository); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...pster/lite/generator/githubactions/infrastructure/primary/rest/GithubActionsResource.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,34 @@ | ||
package tech.jhipster.lite.generator.githubactions.infrastructure.primary.rest; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import tech.jhipster.lite.generator.githubactions.application.GithubActionsApplicationService; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; | ||
import tech.jhipster.lite.technical.infrastructure.primary.annotation.GeneratorStep; | ||
|
||
@RestController | ||
@RequestMapping("/api/github-actions/") | ||
@Tag(name = "Github Actions") | ||
class GithubActionsResource { | ||
|
||
private final GithubActionsApplicationService githubActionsApplicationService; | ||
|
||
GithubActionsResource(GithubActionsApplicationService githubActionsApplicationService) { | ||
this.githubActionsApplicationService = githubActionsApplicationService; | ||
} | ||
|
||
@Operation(summary = "Init Github Actions YML file") | ||
@ApiResponse(responseCode = "500", description = "An error occurred while initializing the github-actions.yml.mustache file") | ||
@PostMapping("/init") | ||
@GeneratorStep(id = "init") | ||
public void init(@RequestBody ProjectDTO projectDTO) { | ||
Project project = ProjectDTO.toProject(projectDTO); | ||
githubActionsApplicationService.init(project); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/tech/jhipster/lite/generator/githubactions/package-info.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,2 @@ | ||
@tech.jhipster.lite.BusinessContext | ||
package tech.jhipster.lite.generator.githubactions; |
17 changes: 17 additions & 0 deletions
17
src/main/resources/generator/githubactions/github-actions.yml.mustache
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,17 @@ | ||
name: GitHub Actions | ||
on: [push] | ||
jobs: | ||
Explore-GitHub-Actions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | ||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | ||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | ||
- name: Check out repository code | ||
uses: actions/checkout@v2 | ||
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." | ||
- run: echo "🖥️ The workflow is now ready to test your code on the runner." | ||
- name: List files in the repository | ||
run: | | ||
ls ${{ github.workspace }} | ||
- run: echo "🍏 This job's status is ${{ job.status }}." |
34 changes: 34 additions & 0 deletions
34
.../jhipster/lite/generator/githubactions/application/GithubActionsApplicationServiceIT.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,34 @@ | ||
package tech.jhipster.lite.generator.githubactions.application; | ||
|
||
import static tech.jhipster.lite.TestUtils.tmpProject; | ||
import static tech.jhipster.lite.generator.githubactions.application.GithubActionsAssertFiles.assertFilesYml; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import tech.jhipster.lite.IntegrationTest; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
@IntegrationTest | ||
class GithubActionsApplicationServiceIT { | ||
|
||
@Autowired | ||
GithubActionsApplicationService githubActionsApplicationService; | ||
|
||
@Test | ||
void shouldInit() { | ||
Project project = tmpProject(); | ||
|
||
githubActionsApplicationService.init(project); | ||
|
||
assertFilesYml(project); | ||
} | ||
|
||
@Test | ||
void shouldAddYml() { | ||
Project project = tmpProject(); | ||
|
||
githubActionsApplicationService.addYml(project); | ||
|
||
assertFilesYml(project); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...java/tech/jhipster/lite/generator/githubactions/application/GithubActionsAssertFiles.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,16 @@ | ||
package tech.jhipster.lite.generator.githubactions.application; | ||
|
||
import static tech.jhipster.lite.TestUtils.assertFileExist; | ||
|
||
import tech.jhipster.lite.generator.project.domain.Project; | ||
|
||
public class GithubActionsAssertFiles { | ||
|
||
public static void assertFilesYml(Project project) { | ||
assertFileExist(project, ".github/workflows/github-actions.yml"); | ||
} | ||
|
||
public static void assertFilesGithubActions(Project project) { | ||
assertFilesYml(project); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ava/tech/jhipster/lite/generator/githubactions/domain/GithubActionsDomainServiceTest.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,44 @@ | ||
package tech.jhipster.lite.generator.githubactions.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.verify; | ||
import static tech.jhipster.lite.TestUtils.tmpProject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import tech.jhipster.lite.UnitTest; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.domain.ProjectRepository; | ||
|
||
@UnitTest | ||
@ExtendWith(MockitoExtension.class) | ||
class GithubActionsDomainServiceTest { | ||
|
||
@Mock | ||
private ProjectRepository projectRepository; | ||
|
||
@InjectMocks | ||
private GithubActionsDomainService githubActionsDomainService; | ||
|
||
@Test | ||
void shouldInit() { | ||
Project project = tmpProject(); | ||
|
||
assertThatCode(() -> githubActionsDomainService.init(project)).doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void shouldAddYml() { | ||
Project project = tmpProject(); | ||
|
||
assertThatCode(() -> githubActionsDomainService.addYml(project)).doesNotThrowAnyException(); | ||
|
||
verify(projectRepository) | ||
.template(any(Project.class), eq("githubactions"), eq("github-actions.yml.mustache"), eq(".github/workflows/")); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../lite/generator/githubactions/infrastructure/config/GithubActionsBeanConfigurationIT.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,23 @@ | ||
package tech.jhipster.lite.generator.githubactions.infrastructure.config; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import tech.jhipster.lite.IntegrationTest; | ||
import tech.jhipster.lite.generator.githubactions.domain.GithubActionsDomainService; | ||
import tech.jhipster.lite.generator.init.domain.InitDomainService; | ||
|
||
@IntegrationTest | ||
class GithubActionsBeanConfigurationIT { | ||
|
||
@Autowired | ||
ApplicationContext applicationContext; | ||
|
||
@Test | ||
void shouldGetBean() { | ||
assertThat(applicationContext.getBean("githubActionsService")).isNotNull().isInstanceOf(GithubActionsDomainService.class); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ter/lite/generator/githubactions/infrastructure/primary/rest/GithubActionsResourceIT.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,42 @@ | ||
package tech.jhipster.lite.generator.githubactions.infrastructure.primary.rest; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static tech.jhipster.lite.TestUtils.convertObjectToJsonBytes; | ||
import static tech.jhipster.lite.TestUtils.readFileToObject; | ||
import static tech.jhipster.lite.generator.githubactions.application.GithubActionsAssertFiles.assertFilesGithubActions; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import tech.jhipster.lite.IntegrationTest; | ||
import tech.jhipster.lite.common.domain.FileUtils; | ||
import tech.jhipster.lite.generator.githubactions.application.GithubActionsApplicationService; | ||
import tech.jhipster.lite.generator.project.domain.Project; | ||
import tech.jhipster.lite.generator.project.infrastructure.primary.dto.ProjectDTO; | ||
|
||
@IntegrationTest | ||
@AutoConfigureMockMvc | ||
class GithubActionsResourceIT { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
GithubActionsApplicationService githubActionsApplicationService; | ||
|
||
@Test | ||
void shouldInit() throws Exception { | ||
ProjectDTO projectDTO = readFileToObject("json/chips.json", ProjectDTO.class).folder(FileUtils.tmpDirForTest()); | ||
|
||
mockMvc | ||
.perform(post("/api/github-actions/init").contentType(MediaType.APPLICATION_JSON).content(convertObjectToJsonBytes(projectDTO))) | ||
.andExpect(status().isOk()); | ||
|
||
Project project = ProjectDTO.toProject(projectDTO); | ||
assertFilesGithubActions(project); | ||
} | ||
} |