Building Java-based microservices as part of a GitHub Action

Aymen Furter
1 min readDec 1, 2021

--

I recently migrated all c14r builds from Azure DevOps to GitHub Actions.
The migration went smoothly. Here is a snippet:

build-dexter:
name: Static Code Analysis for Dexter Microservice
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/dexter/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.DEXTER_SONAR_TOKEN }}
run: cd dexter && mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

Pretty standard. The action does build the code on push and on a pull request, providing code quality metrics based on sonar insights and triggering all unit and integration tests. The full workflow is available here.

--

--

Aymen Furter

I am a Cloud Solution Architect working for Microsoft. The views expressed on this site are mine alone and do not necessarily reflect the views of my employer.