Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post-action fails when running multiple builds in the same step with configuration-cache enabled #441

Closed
CharlieTap opened this issue Sep 24, 2022 · 7 comments · Fixed by #445
Milestone

Comments

@CharlieTap
Copy link

CharlieTap commented Sep 24, 2022

I'm attempting to configure this action in conjunction with using the gradle profiler

I'm running the workflow on the standard github ubuntu-latest runner

My config is the following:

  benchmark:
    runs-on: ubuntu-latest
    steps:

      - name: Clone Repo
        uses: actions/checkout@v3

      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
        with:
          cache-read-only: false

      - name: Install and run the gradle profiler
        run: |
          curl -s "https://get.sdkman.io" | bash
          source "$HOME/.sdkman/bin/sdkman-init.sh"
          sdk install gradleprofiler 0.18.0
          gradle-profiler --benchmark --scenario-file gradle/benchmark.scenarios assembleDebug --gradle-user-home ~/.gradle

But I'm getting the following failure in the Post Setup Gradle step:

Post job cleanup. In final post-action step, saving state and writing summary Warning: Unhandled error in Gradle post-action - job will continue: SyntaxError: Unexpected token { in JSON at position 310 SyntaxError: Unexpected token { in JSON at position 310 at JSON.parse (<anonymous>) at /home/runner/work/_actions/gradle/gradle-build-action/v[2](https://github.com/CharlieTap/motdujour/actions/runs/3119036265/jobs/5058738131#step:12:2)/dist/post/index.js:64660:21 at Array.map (<anonymous>) at loadBuildResults (/home/runner/work/_actions/gradle/gradle-build-action/v2/dist/post/index.js:64657:44) at Object.<anonymous> (/home/runner/work/_actions/gradle/gradle-build-action/v2/dist/post/index.js:66201:67) at Generator.next (<anonymous>) at /home/runner/work/_actions/gradle/gradle-build-action/v2/dist/post/index.js:6615[3](https://github.com/CharlieTap/motdujour/actions/runs/3119036265/jobs/5058738131#step:12:3):71 at new Promise (<anonymous>) at __webpack_modules__.8652.__awaiter (/home/runner/work/_actions/gradle/gradle-build-action/v2/dist/post/index.js:661[4](https://github.com/CharlieTap/motdujour/actions/runs/3119036265/jobs/5058738131#step:12:4)9:12) at Object.complete (/home/runner/work/_actions/gradle/gradle-build-action/v2/dist/post/index.js:6619[5](https://github.com/CharlieTap/motdujour/actions/runs/3119036265/jobs/5058738131#step:12:5):[12](https://github.com/CharlieTap/motdujour/actions/runs/3119036265/jobs/5058738131#step:12:12))

@bigdaz
Copy link
Member

bigdaz commented Sep 25, 2022

Thanks for the report. The error is happening when attempting to read the build result files, that capture various details about each Gradle invocation. These will be located in $RUNNER_TEMP/.build-results.

  • Is this a repeatable failure?
  • If so, can you please capture the $RUNNER_TEMP/.build-results directory in a final step in your workflow?

You can use the core upload-artifact action to save this directory. Something like:

      - name: Collect build results JSON
        uses: actions/upload-artifact@v3
        with:
          name: build-results
          path: ${env.RUNNER_TEMP}/.build-results

That should help work out why the action is failing to parse these files in the post-action step.

@CharlieTap
Copy link
Author

Thanks for coming back so quickly, yes this is a repeated failure.

I've attached the build results folder at the bottom, its worth noting that the RUNNER_TEMP variable doesn't seem to exist. I actually found the address of the folder by connecting via ssh to the machine the grepping the filesystem. Turns out its the following on my ubuntu runner:

~/work/_temp/.build-results

build-results.zip

@bigdaz
Copy link
Member

bigdaz commented Sep 26, 2022

Thanks for that. I can see that the build results data is duplicated in some of the JSON files eg:

{"rootProjectName":"motdujour","rootProjectDir":"/home/runner/work/motdujour/motdujour","requestedTasks":"assembleSrcFRDebug","gradleVersion":"7.5.1","gradleHomeDir":"/home/runner/.gradle/wrapper/dists/gradle-7.5.1-bin/7jzzequgds1hbszbhq3npc5ng/gradle-7.5.1","buildFailed":false,"buildScanUri":null,"buildScanFailed":false}
{"rootProjectName":"motdujour","rootProjectDir":"/home/runner/work/motdujour/motdujour","requestedTasks":"assembleSrcFRDebug","gradleVersion":"7.5.1","gradleHomeDir":"/home/runner/.gradle/wrapper/dists/gradle-7.5.1-bin/7jzzequgds1hbszbhq3npc5ng/gradle-7.5.1","buildFailed":false,"buildScanUri":null,"buildScanFailed":false}

Looking at the code I can see how this could happen if 2 builds share the same "invocation ID", and I'll add a guard to prevent this from happening.

However, I'm surprised that you have 2 builds starting at the exact same System.currentTimeMillis (which is part of the invocation ID. Do you happen to be running with the configuration-cache enabled?

@bigdaz bigdaz changed the title Post Setup Gradle Fails Post-action fails when running multiple builds in the same step with configuration-cache enabled Sep 26, 2022
@bigdaz
Copy link
Member

bigdaz commented Sep 26, 2022

OK so I've managed to reproduce this failure. It occurs when:

  • 2 identical builds are run within the same GitHub Actions step
  • Configuration-cache is enabled for the build

The problem is that we use the Step ID + build timestamp to uniquely identify a build. But the configuration-cache results in the same timestamp being used for the 2 subsequent builds in the same step. We then write both build results to the same file, resulting in invalid JSON when we subsequently load those results.

A temporary workaround is to enable build scan publishing for these builds. That works because this results in the existing results file being overwritten instead of appended.

@bigdaz bigdaz added this to the v2.3.1 milestone Sep 26, 2022
bigdaz added a commit that referenced this issue Sep 26, 2022
When configuration-cache is enabled, the invocationId may not be unique, which can result in
mulitple builds writing to the same file. Rather than failing the post-action, we simply
ignore any subsequent build results with the same ID.

Fixes #441
@CharlieTap
Copy link
Author

That would make sense as I'm using the gradle profiler to benchmark, so I'm running the build n many times in order to get an average. I'll have a look into whether I can enable scans in the profiler, though normally I wouldn't do this as actually doing 5 warm up builds and 15 measured builds which is quite a few build scans 😅

@bigdaz
Copy link
Member

bigdaz commented Sep 29, 2022

I've just released v2.3.2 which prevent the error in the post-action step.
@CharlieTap can you please see if this problem is fixed for you?

@CharlieTap
Copy link
Author

@bigdaz not only does it work, but it took my benchmarking workflow from 15 minutes down to 5 minutes. So big thank you for this 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants