CI for Maven project at Github Actions

Continuing from the following article, this time I will use Github Actions. https://qiita.com/kasa_le/items/1ce0d9e34f29e34835cb

Github Actions

You can set / browse from the [Actions] tab of each repository on Github.

githubactions.png

Feature

A CI tool dedicated to Github. Of course, there are official actions, but the stance of making them as open source is "likely", isn't it? Action can be found on the Marketplace. https://github.com/marketplace?type=actions

Fee

There are no usage restrictions for public repositories. Private repositories are billed on a pay-as-you-go basis, but there is a free monthly range. I think this will be helpful for the estimation calculation method. https://qiita.com/euxn23/items/8cec3a3b8de9e3213424

Even if you use it for free, it is very convenient to be able to choose Windows / Ubuntu / macOS.

Performance

It seems like it's about to come, but after all, Microsoft has been added, so there will be some knowledge on Azure Pipelines, and I think it will definitely be used in the future. However, on the contrary, it may be integrated into Azure Pipelines and disappear ?: grin:

Setting

Use the yml file. Create a directory called .github / wrokflows directly under the root of the project and place it under that directory.

If you click the [Actions] tab first, you can choose from various templates, and the first commit will be done to the above folder.

As for the template, I can find two Maven builds, but this time it is only a build, so I used the one in the red frame.

github_actions_template.png

Here is the yml that finally achieved its purpose.

./github/workflows/maven.yml


Skip to content
Search or jump to…

Pull requests
Issues
Marketplace
Explore
 
@le-kamba 
le-kamba
/
JerseySample
1
00
 Code Issues 0 Pull requests 0 Actions Projects 0 Wiki Security Insights Settings
Update maven.yml
feature/for_github_actions @le-kamba  8ba108d
 
Java CI with Maven
on: push
 
Java CI with Maven
This run
Workflow file
.github/workflows/maven.yml
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
  push:
    branches: [ feature/for_github_actions ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: '11.0.6'
    - name: Build and Test with Maven
      run: mvn clean install
    - name: Archive JAR
      if: always()
      uses: actions/upload-artifact@v1
      with: 
        name: repository
        path: repository/target/repository.jar
    - name: Archive WAR
      if: always()
      uses: actions/upload-artifact@v1
      with: 
        name: serverapi
        path: serverapi/target/serverapi.war
    - name: Gather test results
      if: always()
      run: |
        mvn site -DgenerateReports=false -Daggregate=true surefire-report:report-only
        mkdir -p test-results/junit/
        find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} test-results/junit/ \;
    - name: Archive test resuls xml
      if: always()
      uses: actions/upload-artifact@v1
      with: 
        name: test-results
        path: test-results/junit/
    - name: Archive test resuls html
      if: always()
      uses: actions/upload-artifact@v1
      with: 
        name: test-results-html
        path: target/site

The steps are not so different from other CI tools, so I will omit them, but only the points.

--Set up JDK 11 step --I'm using the official action setup-java. However, it seems that the Zulu version of OpenJDK will be adopted here (Zulu is basically paid, but it is free if you use it from Azure, is it related?). Some people have made the AdoptOpenJDK version, so it's a good idea to search for it on the Marketplace and use it.

--Gather test results step

** Addendum 2020/03/25 ** ~~ With this writing method, even if the test fails, the build success will be reported, so it seems that you have to think about other methods. I was in trouble ... ~~

** Addendum 2020/03/27 ** It is now possible to issue an html report issued by surefire while detecting a test error, so I am modifying it to yml with that pattern.

Impressions

I also touched it on the Android build (https://qiita.com/kasa_le/items/5feb953cd50489c30c90), and since I was familiar with it, it was easier to set up than the previous two (AppVeyor, CircleCI). I was a little addicted to the surefire report.

It would be nice to see the test results on the Actions page. Now I can't see it until I download and unzip it one by one, so that's a hassle.

I'm wondering if it will be possible by uploading the html spit out from surefire to Github Pages, but I haven't investigated it in detail yet.

Oh yeah, Artifact's path doesn't seem to be able to use regular expressions or wildcards like CircleCI, which is inconvenient.

Recommended Posts

CI for Maven project at Github Actions
CI for Maven project on AppVeyor
CI for Maven project in Azure Pipelines
Create Maven Project
That? Why is this repository bad for Github Actions CI running on Ruby 3.0?
Try actions on GitHub [actions]
Create Maven Web Project
GitHub Actions users now prepare for Docker Hub pull limits
[Circle CI] Procedure for automatic deployment when pushing to GitHub