Skip to content

Commit b47371b

Browse files
committed
Support overriding Java version
1 parent 07338af commit b47371b

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.bsp/
2+
/project/
3+
/target/

action.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
name: "Setup Scala with both Java and sbt"
22
description: "Much longer description"
3-
#inputs:
4-
# sbt-runner-version:
5-
# description: "The runner version (The actual version is controlled via project/build.properties)"
6-
# required: true
7-
# default: 1.10.2
3+
inputs:
4+
major-java-version:
5+
description: 'Specify a major Java version (21, 11, etc) as an alternative to reading one from .tool-versions'
6+
required: false
7+
default: ''
88
runs:
99
using: "composite"
1010
steps:
1111
- name: Determine major Java version
1212
id: determine-java-version
1313
shell: bash
14+
env:
15+
MAJOR_JAVA_VERSION: ${{ inputs.major-java-version }}
1416
run: |
15-
if [ ! -f .tool-versions ]; then
16-
echo "::error title=Missing .tool-versions file::setup-scala requires an asdf-format .tool-versions file to establish the Java version for the build."
17-
exit 1
17+
if [ ${MAJOR_JAVA_VERSION:-} ]; then
18+
echo "Reading Java version from the 'major-java-version' input property, rather than .tool-versions"
19+
else
20+
if [ ! -f .tool-versions ]; then
21+
echo "::error title=Missing .tool-versions file::setup-scala requires an asdf-format .tool-versions file to establish the Java version for the build."
22+
exit 1
23+
fi
24+
MAJOR_JAVA_VERSION=$( grep -Eo 'java [[:alnum:]-]+-[[:digit:]]+' .tool-versions | rev | cut -d'-' -f1 | rev )
25+
26+
if [ -z "${MAJOR_JAVA_VERSION}" ]; then
27+
echo "::error title=Missing Java version in .tool-versions file::Could not establish the project's required Java version - the '.tool-versions' file should have a line like 'java corretto-21.0.3.9.1'."
28+
exit 1
29+
fi
1830
fi
19-
MAJOR_JAVA_VERSION=$( grep -Eo 'java [[:alnum:]-]+-[[:digit:]]+' .tool-versions | rev | cut -d'-' -f1 | rev )
31+
2032
echo "Using Java $MAJOR_JAVA_VERSION"
21-
if [ -z "${MAJOR_JAVA_VERSION}" ]; then
22-
echo "::error title=Missing Java version in .tool-versions file::Could not establish the project's required Java version - the '.tool-versions' file should have a line like 'java corretto-21.0.3.9.1'."
23-
exit 1
24-
fi
2533
2634
cat << EndOfFile >> $GITHUB_OUTPUT
2735
major_java_version=$MAJOR_JAVA_VERSION
@@ -35,4 +43,4 @@ runs:
3543
cache: sbt
3644

3745
- name: Setup sbt
38-
uses: sbt/setup-sbt@v1.1.0
46+
uses: sbt/setup-sbt@v1.1.5

0 commit comments

Comments
 (0)