Getting a "Missing commit" error with github actions

Hi,

Just started using github actions as a replacement for travis ci, but my build is failing with a strange error:

Run ./gradlew clean build
Downloading https://services.gradle.org/distributions/gradle-6.9-all.zip
..............10%..............20%...............30%..............40%..............50%...............60%..............70%...............80%..............90%..............100%

Welcome to Gradle 6.9!

Here are the highlights of this release:
 - This is a small backport release.
 - Java 16 can be used to compile when used with Java toolchains
 - Dynamic versions can be used within plugin declarations
 - Native support for Apple Silicon processors

For more details see https://docs.gradle.org/6.9/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Unexpected error while parsing HEAD commit: Missing commit 6253cc4565412691e21fd9447d3f57f1d55083ce
> Missing commit 6253cc4565412691e21fd9447d3f57f1d55083ce

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 45s
Error: Process completed with exit code 1.

The commit is in fact in the repository, but it’s not the HEAD, it’s the second commit from the HEAD. Here’s the git log:

* 2feb003 - (15 minutes ago) ... (HEAD -> master, origin/master)
* 6253cc4 - (30 minutes ago) ...

The workflow file is here: kotlin-faker/build.yml at 2feb003eb2b718e30b6bc10a5beb75b79dab0d62 · serpro69/kotlin-faker · GitHub

I must be missing something very obvious here, but I can’t for the life of me figure out what’s wrong with the setup.
Can someone help me understand what’s going on here and how to fix it?

UPD:
I’ve tried to add a “Java CI with Gradle” action directly from UI without doing any changes to it, and I’m getting the same error in that action as well.

Accessing that previous commit fails because actions/checkout retrieves only the commit that triggered the workflow. You can can change that with the fetch-depth parameter.

I’m not familiar with Gradle, so I can’t say why it’s trying to access the previous commit.

Hi @airtower-luna ,

Thanks for the tip. I did some more testing, and I still can’t get why gradle command is using the previous commit.
I even tried to add an explicit git checkout into the same command and still it fails with same error.

/usr/bin/git checkout origin/master && ./gradlew clean test
...
HEAD is now at 0e680bc Add test
...
...
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Unexpected error while parsing HEAD commit: Missing commit b4569d6e4d8174bc166c58b9bf1d6abb9710ef1d
> Missing commit b4569d6e4d8174bc166c58b9bf1d6abb9710ef1d

OK, so it looks like adding explicit depth: 0 for the checkout step does help:

      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

Though I’d think that should’ve been default behavior, since it’s not set explicitly in the “java with gradle” workflow template. And I haven’t seen this in examples that I’ve found around github also.