How to setup a GitHub action to run a spring boot project with a mysql database?

Viewed 829

I am trying to set up a GitHub Action that is able to test if my spring boot project compiles after every commit. The Spring project connects to a MySQL database. I have created the following workflow file.

# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_DATABASE: jeremyuniversity
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
        ports:
        - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 1.14
      uses: actions/setup-java@v1
      with:
        java-version: 14.0.2
      env:
        database.password: 
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build  --stacktrace

Yet the build always fails with the following error.

JeremyUniversityApplicationTests > testGetStudents() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.BeanCreationException at BeanDefinitionValueResolver.java:342
            Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1794
                Caused by: org.hibernate.service.spi.ServiceException at AbstractServiceRegistryImpl.java:275
                    Caused by: org.hibernate.HibernateException at DialectFactoryImpl.java:100

The environmental variable database.password is used to set the database password in the application.properties file. What is causing this error to be thrown?

Full code: https://github.com/rustylocks79/jeremyuniversity.git

0 Answers
Related