Quarkus (GraalVM Native)- GitHub Action PR Validation

If you ever need to use Quarkus or GraalVM in order to produce an AWS Lambda function running on Java code, you are probably going to want to create some CI, in order to validate any changes made, when making pull requests into your repository.

The following is a basic example of a GitHib action which will set up your environment with the required dependencies and then perform build and unit test validation on your named branch.

name: Build And Run Unit Tests

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# 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:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
      - name: Set up Maven
        uses: stCarolas/setup-maven@v4.2
        with:
          maven-version: 3.8.4
      - name: Install GraalVM 22.0.0
        uses: ayltai/setup-graalvm@v1
        with:
          java-version: 11
          graalvm-version: 22.0.0.2
          native-image: true
      - name: Cache Maven packages
        uses: actions/cache@v2.1.7
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      - name: Maven Clean and Verify
        run: mvn -e clean verify -Pnative --define quarkus.native.container-build=true

And voila! You now have a working action to successfully validate your code based on a GraalVM Native Image. Simple as that.