Skip to content

Commit

Permalink
Added actions/setup/action.yml for github-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkurane committed Mar 5, 2022
1 parent 1b57fdc commit 3d18e30
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public void init(Project project) {
}

public void addYml(Project project) {
githubActionsService.addYml(project);
githubActionsService.addYmls(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

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";
public static final String GITHUB_ACTIONS_CI_SOURCE_FOLDER = "githubactions/.github/workflows/";
public static final String GITHUB_ACTIONS_CI_YML = "github-actions.yml.mustache";
public static final String GITHUB_ACTIONS_CI_DESTINATION_FOLDER = ".github/workflows/";

public static final String GITHUB_ACTIONS_SETUP_SOURCE_FOLDER = "githubactions/.github/actions/setup/";
public static final String GITHUB_ACTIONS_SETUP_YML = "action.yml.mustache";
public static final String GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER = ".github/actions/setup/";

private final ProjectRepository projectRepository;

Expand All @@ -17,11 +21,17 @@ public GithubActionsDomainService(ProjectRepository projectRepository) {

@Override
public void init(Project project) {
addYml(project);
addYmls(project);
}

@Override
public void addYml(Project project) {
projectRepository.template(project, SOURCE, GITHUB_ACTIONS_YML, GITHUB_ACTIONS_FOLDER);
public void addYmls(Project project) {
projectRepository.template(
project,
GITHUB_ACTIONS_SETUP_SOURCE_FOLDER,
GITHUB_ACTIONS_SETUP_YML,
GITHUB_ACTIONS_SETUP_DESTINATION_FOLDER
);
projectRepository.template(project, GITHUB_ACTIONS_CI_SOURCE_FOLDER, GITHUB_ACTIONS_CI_YML, GITHUB_ACTIONS_CI_DESTINATION_FOLDER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
public interface GithubActionsService {
void init(Project project);

void addYml(Project project);
void addYmls(Project project);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GithubActionsResource {
@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")
@GeneratorStep(id = "github-actions")
public void init(@RequestBody ProjectDTO projectDTO) {
Project project = ProjectDTO.toProject(projectDTO);
githubActionsApplicationService.init(project);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'Setup'
description: 'Setup environment with Java 17, Node 16.14.0'
runs:
using: 'composite'
steps:
- name: 'Setup: Node.js'
uses: actions/setup-node@v2.5.0
with:
node-version: 16.14.0
- name: 'Setup: update NPM'
shell: bash
run: npm install -g npm
- name: 'Setup: Java 17'
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17.x'
- name: 'Setup: check tools'
shell: bash
run: |
node -v
npm -v
java -version
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void shouldInit() {
}

@Test
void shouldAddYml() {
void shouldAddYmls() {
Project project = tmpProject();

githubActionsApplicationService.addYml(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GithubActionsAssertFiles {

public static void assertFilesYml(Project project) {
assertFileExist(project, ".github/workflows/github-actions.yml");
assertFileExist(project, ".github/actions/setup/action.yml");
}

public static void assertFilesGithubActions(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ void shouldInit() {
void shouldAddYml() {
Project project = tmpProject();

assertThatCode(() -> githubActionsDomainService.addYml(project)).doesNotThrowAnyException();
assertThatCode(() -> githubActionsDomainService.addYmls(project)).doesNotThrowAnyException();

verify(projectRepository)
.template(any(Project.class), eq("githubactions"), eq("github-actions.yml.mustache"), eq(".github/workflows/"));
.template(any(Project.class), eq("githubactions/.github/actions/setup/"), eq("action.yml.mustache"), eq(".github/actions/setup/"));
verify(projectRepository)
.template(any(Project.class), eq("githubactions/.github/workflows/"), eq("github-actions.yml.mustache"), eq(".github/workflows/"));
}
}

0 comments on commit 3d18e30

Please sign in to comment.