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

setup-java@v4.2.0 redownloading jdk on every run #632

Open
2 of 5 tasks
Ivanuil opened this issue May 9, 2024 · 20 comments
Open
2 of 5 tasks

setup-java@v4.2.0 redownloading jdk on every run #632

Ivanuil opened this issue May 9, 2024 · 20 comments
Assignees
Labels
bug Something isn't working

Comments

@Ivanuil
Copy link

Ivanuil commented May 9, 2024

Description:
setup-java@v4.2.0 redownloading jdk on every every job in a pipeline while executing on a self-hosted Linux runner (about 15min on every job).

Task version:
v4.2.0

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
Workflow file:

build:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - name: set up JDK 17
        uses: actions/setup-java@v4.2.0
        with:
          distribution: 'oracle'
          java-version: 17
          check-latest: false
          cache: 'maven'
      - name: Maven Verify
        run: mvn clean compile

  codestyle:
    needs: build
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4
      - name: set up JDK 17
        uses: actions/setup-java@v4.2.0
        with:
          distribution: 'oracle'
          java-version: 17
          check-latest: false
          cache: 'maven'
      - name: Maven Verify
        run: mvn checkstyle:check

  test:
    needs: codestyle
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4
      - name: set up JDK 17
        uses: actions/setup-java@v4.2.0
        with:
          distribution: 'oracle'
          java-version: 17
          check-latest: false
          cache: 'maven'
      - name: Maven Verify
        run: mvn -B clean verify
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4.0.1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: Ivanuil/ImageEditor

Setup JDK log:

Run actions/setup-java@v4.2.0
  with:
    distribution: oracle
    java-version: 17
    check-latest: false
    cache: maven
    java-package: jdk
    server-id: github
    server-username: GITHUB_ACTOR
    server-password: GITHUB_TOKEN
    overwrite-settings: true
    job-status: success
    token: ***
Installed distributions
  Trying to resolve the latest version from remote
  Resolved latest version as 17
  Trying to download...
  Downloading Java 17 (Oracle) from https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz ...
  Extracting Java archive...
  /usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/ivanuil/actions-runner/_work/_temp/6ec944e[2](https://github.com/Ivanuil/ImageEditor/actions/runs/9017688035/job/24776650890#step:3:2)-cb2c-4b87-ad79-8f27ace92481 -f /home/ivanuil/actions-runner/_work/_temp/7f52[3](https://github.com/Ivanuil/ImageEditor/actions/runs/9017688035/job/24776650890#step:3:3)1a7-7ee0-4356-a299-19e1080a6[4](https://github.com/Ivanuil/ImageEditor/actions/runs/9017688035/job/24776650890#step:3:4)80
  Java 17 was downloaded
  Setting Java 17 as the default
  Creating toolchains.xml for JDK version 17 from oracle
  Overwriting existing file /home/ivanuil/.m2/toolchains.xml
  
  Java configuration:
    Distribution: oracle
    Version: 17
    Path: /home/ivanuil/actions-runner/_work/_tool/Java_Oracle_jdk/17/x[6](https://github.com/Ivanuil/ImageEditor/actions/runs/9017688035/job/24776650890#step:3:6)4
  
Creating settings.xml with server-id: github
Overwriting existing file /home/ivanuil/.m2/settings.xml
maven cache is not found

Post setup JDK log:

Post job cleanup.
/usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/ivanuil/actions-runner/_work/ImageEditor/ImageEditor --files-from manifest.txt --use-compress-program zstdmt
Cache Size: ~3[2](https://github.com/Ivanuil/ImageEditor/actions/runs/9017688035/job/24776650890#step:7:2)1 MB (336496180 B)
Cache saved successfully
Cache saved with the key: setup-java-Linux-maven-a1b758b65f9e0e80afb7bef1758b722af2701f1dbe542c6f8a9f6a83933ce403
@Ivanuil Ivanuil added bug Something isn't working needs triage labels May 9, 2024
@aparnajyothi-y
Copy link
Contributor

Hello @Ivanuil, Thank you for creating this issue and we will look into it :)

@Sebagai
Copy link

Sebagai commented May 15, 2024

Haha

@mahabaleshwars mahabaleshwars self-assigned this May 15, 2024
@abelmatos
Copy link

abelmatos commented May 24, 2024

I'm using the default installed version java 21.
there is a 17 too
https://github.com/actions/runner-images/blob/ubuntu22/20240516.1/images/ubuntu/Ubuntu2204-Readme.md#java
e.g.

        # https://github.com/actions/runner-images/blob/ubuntu22/20240516.1/images/ubuntu/Ubuntu2204-Readme.md#java
      - name: Switch to Java 17
        run: echo "JAVA_HOME=$JAVA_HOME_17_X64" | tee -a $GITHUB_ENV ;  sudo update-java-alternatives --set $JAVA_HOME_17_X64;

Will be cool this action to take advantage of the pre-existent java versions already installed

@oscar-b
Copy link

oscar-b commented May 31, 2024

We're seeing the same thing on our self hosted runners. Shouldn't it re-use /opt/actions-runner/_work/_tool/Java_Oracle_jdk/17/x64 if it's already there? Or do we need to setup a tools cache like Githubs runners? This is all quite poorly documented for us running self hosted runners. Any idea @aparnajyothi-y

@oscar-b
Copy link

oscar-b commented May 31, 2024

Try specifying java-version: 17.0.11, the action doesn't use the cache if it's not an exact version.

https://github.com/actions/toolkit/blob/main/packages/tool-cache/src/tool-cache.ts#L553

@Ivanuil
Copy link
Author

Ivanuil commented May 31, 2024

Try specifying java-version: 17.0.11, the action doesn't use the cache if it's not an exact version.

That did the trick. Thanks)

@mahabaleshwars
Copy link
Contributor

Hello @Ivanuil, I've tried to reproduce the issue but didn't encounter any problems. Here's a screenshot for you to look at. Could you please outline the steps that led to this issue, so I can attempt to recreate it?

Image

@oscar-b
Copy link

oscar-b commented Jun 3, 2024

@mahabaleshwars
Your screenshot says: "Java 17 was downloaded"

It should say: "Resolved Java 17.0.11 from tool-cache" when it re-uses the cache.

Look at the code I pointed to above, using "17" as the version will disqualify that dir in _work/_tool/Java_Oracle_jdk. However, if you'd happen to have both 17 and 17.0.1, it will pass the check that it has any caches and 17 will find its directory anyway. The logic there is quite badly implemented.

@mahabaleshwars
Copy link
Contributor

Hello @Ivanuil,
If you're using the setup-java action and specify a major version like java-version: 17, the action will try to resolve it to the latest minor version. If a new minor version is released (say 17.0.12), it won't match the cache key for 17.0.11 and the JDK will be downloaded again.
To ensure that the exact version is cached and used across workflows, it's recommended to specify the exact JDK version you want to cache in your workflow file, like java-version: 17.0.11. This way, the cache key will remain consistent across workflow runs.

@oscar-b
Copy link

oscar-b commented Jun 14, 2024

Hello @Ivanuil Yeah but that's not how it works in reality, unfortunately. See my comments above.

@Ivanuil Ivanuil closed this as completed Jun 14, 2024
@LetapF
Copy link

LetapF commented Jul 11, 2024

something is downloading every time that i build something

jobs:
  build_android:
    if: "contains(github.event.head_commit.message, 'build-android')"
    name: Build Android
    runs-on: self-hosted
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18.19.1"
      - name: Setup Java
        uses: actions/setup-java@v4.2.0
        with:
          java-version: 17.0.11
          distribution: "oracle"
          check-latest: false
          cache: "gradle"
      - name: Setup Android SDK
        uses: android-actions/setup-android@v3

image

@Ivanuil
Copy link
Author

Ivanuil commented Jul 11, 2024

something is downloading every time that i build something

jobs:
  build_android:
    if: "contains(github.event.head_commit.message, 'build-android')"
    name: Build Android
    runs-on: self-hosted
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "18.19.1"
      - name: Setup Java
        uses: actions/setup-java@v4.2.0
        with:
          java-version: 17.0.11
          distribution: "oracle"
          check-latest: false
          cache: "gradle"
      - name: Setup Android SDK
        uses: android-actions/setup-android@v3

image

Same for me :( Everything worked as it was supposed to for a month. And a few days ago the action started redownloading something on every run. It also usually fails to download (percentage get stuck at some point) and i have to cancel that run

@Ivanuil Ivanuil reopened this Jul 11, 2024
@Ivanuil
Copy link
Author

Ivanuil commented Jul 11, 2024

My job looks like this:

- name: set up JDK 17
        uses: actions/setup-java@v4.2.0
        with:
          distribution: 'oracle'
          java-version: 17.0.11
          check-latest: false
          cache: 'maven'

@mahabaleshwars
Copy link
Contributor

Hi @Ivanuil, I've attempted to reproduce the issue but I didn't encounter the problem you described. Could you provide a public repository where the issue is reproducible?

@Ivanuil
Copy link
Author

Ivanuil commented Jul 18, 2024

Hi @Ivanuil, I've attempted to reproduce the issue but I didn't encounter the problem you described. Could you provide a public repository where the issue is reproducible?

Sure, repo: https://github.com/Ivanuil/FriendAlertBot
action: https://github.com/Ivanuil/FriendAlertBot/actions/runs/9856712473

@mahabaleshwars
Copy link
Contributor

Hello @Ivanuil,

I have forked the repository ""FriendAlertBot"" but am still unable to reproduce the issue.
For your reference, I am sharing my workflow: workflow link
I noticed that the cache is not visible in your repository, whereas it is being saved in my repository and setup-java is using it for the next run.

@aparnajyothi-y
Copy link
Contributor

Hello @Ivanuil, Please let us know if you still have any concerns on the above comment.

@Ivanuil
Copy link
Author

Ivanuil commented Aug 14, 2024

the cache is not visible in your repository

Thank you for the info. Could you give me some advice on how to set up cahche in my reposityory so that everything works? :)

@mahabaleshwars
Copy link
Contributor

Hello @Ivanuil,

Could you enable debugging in your repository by adding the following secrets:
ACTIONS_RUNNER_DEBUG: true and ACTIONS_STEP_DEBUG: true ?

Additionally, could you share your runner configuration file and its log so we can examine if it is contributing to this issue?

@mahabaleshwars
Copy link
Contributor

Hello @Ivanuil, were you able to debug with the commands mentioned above?
Please share the logs that will help us identify the root cause more effectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants