liquibase / github-action-generator

Main repository to generate GitHub Actions for liquibase-github-actions
1 stars 1 forks source link

Error: JAVA_HOME not configured correctly #118

Closed MafcoCinco closed 5 months ago

MafcoCinco commented 6 months ago

The following action configuration is generating an error:

      # Install Java 21
      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          distribution: 'oracle'
          java-version: '21'

      # Install Liquibase DB Migration Tool and migrat DB
      - name: Setup Liquibase DB Migration Tool
        uses: liquibase-github-actions/update@v4.27.0
        with:
          changelogFile: db/db-changelog.yaml
          driver: org.postgresql.Driver
          classpath: libs/postgresql-42.7.3.jar
          url: ${{ secrets.HEROKU_DATABASE_URL }}
          username: ${{ secrets.HEROKU_USERNAME }}
          password: ${{ secrets.HEROKU_PASSWORD }}

The error that I'm seeing in the GitHub action logs is as follows:

ERROR: The JAVA_HOME environment variable is not defined correctly, so Liquibase cannot be started. JAVA_HOME is set to "/opt/hostedtoolcache/Java_Oracle_jdk/21/x64" and it does not exist.

I added the following debugging steps after the Java 21 install step to verify that JAVA_HOME looked correctly configured. It yielded this output, which looks correct to me:

0s
Run echo $JAVA_HOME
  echo $JAVA_HOME
  ls -lah $JAVA_HOME
  java -version
  shell: /usr/bin/bash -e {0}
  env:
    JAVA_HOME: /opt/hostedtoolcache/Java_Oracle_jdk/21/x64
    JAVA_HOME_21_X64: /opt/hostedtoolcache/Java_Oracle_jdk/21/x64
/opt/hostedtoolcache/Java_Oracle_jdk/21/x64
total 44K
drwxrwxrwx+  9 runner docker 4.0K Apr 29 22:10 .
drwxrwxrwx+  3 runner docker 4.0K Apr 29 22:10 ..
lrwxrwxrwx   1 runner docker   23 Apr 29 22:10 LICENSE -> legal/java.base/LICENSE
-rw-r--r--+  1 runner docker  290 Apr 29 22:10 README
drwxr-xr-x+  2 runner docker 4.0K Apr 29 22:10 bin
drwxr-xr-x+  5 runner docker 4.0K Apr 29 22:10 conf
drwxr-xr-x+  3 runner docker 4.0K Apr 29 22:10 include
drwxr-xr-x+  2 runner docker 4.0K Apr 29 22:10 jmods
drwxr-xr-x+ 71 runner docker 4.0K Apr 29 22:10 legal
drwxr-xr-x+  5 runner docker 4.0K Apr 29 22:10 lib
drwxr-xr-x+  3 runner docker 4.0K Apr 29 22:10 man
-rw-r--r--+  1 runner docker 1.3K Apr 29 22:10 release
java version "21.0.3" 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)

Any suggestions a to how to proceed with debugging this issue? One additional note: I have tried with multiple versions of Java supported by GitHub, including Zulu, Oracle and Temurin. All suffered from the same error.

pokebadgerswithspoon commented 6 months ago

These actions are built on liquibase docker image. I had a look: docker run -it liquibase/liquibase:4.27.0 bash, it has java preinstalled in /opt/java/openjdk.

So in github actions this env should be restored.

     - id: liquibase-update
        env:
          JAVA_HOME: /opt/java/openjdk
        uses: liquibase-github-actions/update@v4.27.0
        with:
        .....

This way it works.

However there will be next problem: how to add a driver to class path? Some drivers are already included, even postgre and oracle, so classpath seems to be safe to omitted

jnewton03 commented 6 months ago

hi @MafcoCinco, what @pokebadgerswithspoon said is correct. The github actions are based on the liquibase docker image, so java comes pre-installed. You should be able to remove setup-java entirely to resolve this issue.