Skip to content

Commit

Permalink
Support overriding Java version
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyley committed Jan 10, 2025
1 parent 07338af commit 3f2acb0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.bsp/
/project/
/target/
36 changes: 22 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
name: "Setup Scala with both Java and sbt"
description: "Much longer description"
#inputs:
# sbt-runner-version:
# description: "The runner version (The actual version is controlled via project/build.properties)"
# required: true
# default: 1.10.2
inputs:
major-java-version:
description: 'Specify a major Java version (21, 11, etc) as an alternative to reading one from .tool-versions'
required: false
default: ''
runs:
using: "composite"
steps:
- name: Determine major Java version
id: determine-java-version
shell: bash
env:
MAJOR_JAVA_VERSION: ${{ inputs.major-java-version }}
run: |
if [ ! -f .tool-versions ]; then
echo "::error title=Missing .tool-versions file::setup-scala requires an asdf-format .tool-versions file to establish the Java version for the build."
exit 1
if [ ${MAJOR_JAVA_VERSION:-} ]; then
echo "Using 'major-java-version' setting rather than reading .tool-versions"
else
if [ ! -f .tool-versions ]; then
echo "::error title=Missing .tool-versions file::setup-scala requires an asdf-format .tool-versions file to establish the Java version for the build."
exit 1
fi
MAJOR_JAVA_VERSION=$( grep -Eo 'java [[:alnum:]-]+-[[:digit:]]+' .tool-versions | rev | cut -d'-' -f1 | rev )
if [ -z "${MAJOR_JAVA_VERSION}" ]; then
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'."
exit 1
fi
fi
MAJOR_JAVA_VERSION=$( grep -Eo 'java [[:alnum:]-]+-[[:digit:]]+' .tool-versions | rev | cut -d'-' -f1 | rev )
echo "Using Java $MAJOR_JAVA_VERSION"
if [ -z "${MAJOR_JAVA_VERSION}" ]; then
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'."
exit 1
fi
cat << EndOfFile >> $GITHUB_OUTPUT
major_java_version=$MAJOR_JAVA_VERSION
Expand All @@ -35,4 +43,4 @@ runs:
cache: sbt

- name: Setup sbt
uses: sbt/[email protected].0
uses: sbt/[email protected].5

0 comments on commit 3f2acb0

Please sign in to comment.