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

Add output parameter with path to installed JDK #65

Closed
tbroyer opened this issue May 24, 2020 · 4 comments · Fixed by #66 · 4 remaining pull requests
Closed

Add output parameter with path to installed JDK #65

tbroyer opened this issue May 24, 2020 · 4 comments · Fixed by #66 · 4 remaining pull requests

Comments

@tbroyer
Copy link
Contributor

tbroyer commented May 24, 2020

When calling the action several times, it will overwrite the JAVA_HOME environment variable and prepend it to the PATH, effectively shadowing a previous run of the action.
Fortunately, it will also set a JAVA_HOME_<version>_<architecture> environment variable, but this could be more idiomatic as an output parameter (in addition to the environment variable, which can also be useful on its own: #44 (comment))

This would be a great addition to #21

That way, one could write something like:

- name: Setup JDK 11
  id: setup-java-11
  uses: actions/setup-java@v1
  with:
    java-version: 11
    # here with #21, one would disable "installation"
- name: Setup JDK 14
  id: setup-java-14
  uses: actions/setup-java@v1
  with:
    java-version: 14
    # here with #21, one would disable "installation"
- name: Setup JDK 8
  # Ran last due each run shadowing the previous ones; see also #21
  uses: actions/setup-java@v1
  with:
    java-version: 8
- name: Build and run tests (with JDK 8)
  run: ./gradlew build
- name: Run tests with JDK 11
  run: ./gradlew test -Ptest.jdk-path="${{ steps.setup-java-11.outputs.jdk-path }}"
- name: Run tests with JDK 14
  run: ./gradlew test -Ptest.jdk-path="${{ steps.setup-java-14.outputs.jdk-path }}"

(here, the build is still running with JDK 8, but it coud configure its tests to actually use another JDK)

@tbroyer
Copy link
Contributor Author

tbroyer commented May 24, 2020

This is actually worse than that: java-version: 11 won't actually set JAVA_HOME_11_x64, but JAVA_HOME_11.0.7_x64, making that variable essentially useless as its name will actually change whenever a new version of the JDK is released.

As a workaround, I'm using (with a previous call with java-version: 11 and a previous Gradle build with JDK 11: the new build here still runs with JDK 11 so it won't recompile Java sources)

      # Workaround for https://github.com/actions/setup-java/issues/65
      - name: Backup JAVA_HOME
        id: java-home
        run: echo "::set-output name=path::$JAVA_HOME"

I could have used a ::set-env too of course to set JAVA_HOME_11_x64.

tbroyer added a commit to tbroyer/setup-java that referenced this issue May 25, 2020
This allows calling the action multiple times in the
same job and retrieving the path and/or version in
other steps.

Fixes actions#65
tbroyer added a commit to tbroyer/setup-java that referenced this issue May 25, 2020
This allows calling the action multiple times in the
same job and retrieving the path and/or version in
other steps.

Fixes actions#65
tbroyer added a commit to tbroyer/setup-java that referenced this issue May 25, 2020
This allows calling the action multiple times in the
same job and retrieving the path and/or version in
other steps.

Fixes actions#65
tbroyer added a commit to tbroyer/setup-java that referenced this issue May 25, 2020
This allows calling the action multiple times in the
same job and retrieving the path and/or version in
other steps.

Fixes actions#65
tbroyer added a commit to tbroyer/setup-java that referenced this issue May 27, 2020
This allows calling the action multiple times in the
same job and retrieving the path and/or version in
other steps.

Fixes actions#65
@Ryan9Manu
Copy link

Nmnbbb

@Ryan9Manu
Copy link

Bjjk

@Ryan9Manu
Copy link

Bnnk no nn

Nn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment