That's not really a Gradle question.
You could for example use some GitHub Action that spins up a database.
Or you could maybe use Testcontainers from a Gradle build service that you use to spin up a database.
Or you could make sure the respective test are skipped if you did not provide a database.
...