GitHub Actions에 대해 아무 것도 모르는 사람이 CI를 구성 할 때까지 (Spring Boot)

소개



오랜만에 쓰므로 짧게.
GitHub Actions가 나와서 1년 이상이 되지만, 주위가 대단하다는 만큼 스스로 사용한 적이 없었기 때문에 만져 보았다.

환경


  • Java 11
  • IntelliJ IDEA 2020.3.2 (Community Edition)
  • Build #IC-203.7148.57, built on January 26, 2021


  • 설정



    이후의 내용은 하기 리포지토리에 놓았다.
    htps : // 기주 b. 코 m / 이케 포니 아 s / Sp 링 g 보오 t

    다음의 구현과 테스트 코드를 써서 이것을 CI에서 실행하도록 해 보았다. 실장과 테스트는 적당하므로 용서해 주십시오.

    TestController.java
    @RestController
    @RequestMapping("/test")
    public class TestController {
    
        @RequestMapping(method = RequestMethod.GET)
        public String getMessage() {
            return "Hello World!";
        }
    }
    

    TestControllerTest.java
        @Test
        public void successTest() throws Exception {
            MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test"))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andReturn();
            Assertions.assertEquals(mvcResult.getResponse().getContentAsString(), "Hello World!");
        }
    
        @Test
        public void failedTest() throws Exception {
            MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/test"))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andReturn();
            Assertions.assertEquals(mvcResult.getResponse().getContentAsString(), "Hello World");
        }
    

    GitHub 리포지토리의 탭 중에 Actions라는 열이 어느새 일어나고 있습니다.

    이것을 눌러 보면 GitHub Actions의 초기 설정 화면이 나온다.

    흠흠, 배포하기위한 워크 플로우 샘플도있는 것이 좋습니다.
    이번은 정말 간단하게 테스트하고 싶을 뿐이므로, Suggest되고 있다 Simple workflow 를 선택.
    그러면 다음과 같은 화면이 표시되었다.
    과연, 이 yml을 편집하는 것으로 CI의 설정을 할 수 있는 것일까.
    Jenkins에서 Jenkinsfile이라고 생각해 두면 좋을까.

    이번에는 push시에 테스트를 실행하고 싶었으므로 풀 요청시 설정을 삭제하고 Run testsmvn test를 추가해 보았습니다.
    # This is a basic workflow to help you get started with Actions
    
    name: CI
    
    # Controls when the action will run. 
    on: [push]
    
    # A workflow run is made up of one or more jobs that can run sequentially or in parallel
    jobs:
      # This workflow contains a single job called "build"
      build:
        # The type of runner that the job will run on
        runs-on: ubuntu-latest
    
        # Steps represent a sequence of tasks that will be executed as part of the job
        steps:
          # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
          - uses: actions/checkout@v2
    
          # Runs a single command using the runners shell
          - name: Run a one-line script
            run: echo Hello, world!
    
          # Runs a set of commands using the runners shell
          - name: Run a multi-line script
            run: |
              echo Add other actions to build,
              echo test, and deploy your project.
    
          - name: Run tests
            run:
              mvn test
    

    갑자기 나왔다 actions/checkout@v2 라고 난다 이거라고 생각했지만 htps : // 기주 b. 코 m / 아 c 치온 s / 치 ぇ c t
    구체적인 구문이나 설정 방법은 공식 문서를 참조하는 것이 좋다.
    특히 이번에는 Java 버전 등 설정하지 않았지만, 그 경우 pom의 값이 사용되는 것일까(모르겠다).
    htps : // / cs. 기주 b. 코 m / 자 / 아 c 치온 s

    실행 결과



    테스트가 모두 실행 성공하면 아래와 같이 되는 것을 확인할 수 있었다.

    테스트가 실패하면 아래와 같이 되는 것을 확인할 수 있었다.

    김에 GitHub에 등록되어 있는 메일 주소에 작업 결과가 도착하고 있는 것도 확인할 수 있었다.


    감상



    처음이라도 20분 정도로 설정할 수 있었으므로, Jenkins등과 비교하면 도입 코스트가 매우 낮다.
    간단하게 CI를 돌고 싶은 경우에, 이것은 아주 편하고 고맙게 생각한다.

    좋은 웹페이지 즐겨찾기