diff --git a/action.yml b/action.yml index 4def6f9..0ae0f69 100644 --- a/action.yml +++ b/action.yml @@ -9,25 +9,29 @@ inputs: description: "Args to pass to scalafmt" default: "--list" required: false - version: - description: "Version of scalafmt" - default: "3.7.15" - required: false runs: using: "composite" steps: + - shell: bash + id: extract-scalafmt-version + run: | + version=$(perl -ne 'next unless /^\s*version\s*=\s*(\d+\.\d+\.\d+)/; print "$1"; last' .scalafmt.conf) + if [ -z "$version" ]; then + echo "Failed to extract scalafmt version from .scalafmt.conf" + exit 1 + fi + echo "scalafmt_version=$version" >> "$GITHUB_ENV" - shell: bash run: | "$action_path/set-path.sh" env: - scalafmt_version: ${{ inputs.version }} action_path: ${{ github.action_path }} - uses: actions/cache/restore@v4 id: cache with: path: ${{ env.SCALAFMT_PATH }} - key: scalafmt-${{ inputs.version }} + key: scalafmt-${{ env.scalafmt_version }} - shell: bash id: retrieve-scalafmt if: ${{ !steps.cache.outputs.cache-hit }} @@ -45,4 +49,4 @@ runs: uses: actions/cache/save@v4 with: path: ${{ env.SCALAFMT_PATH }} - key: scalafmt-${{ inputs.version }} + key: scalafmt-${{ env.scalafmt_version }} diff --git a/run-scalafmt.sh b/run-scalafmt.sh index 6f538b1..7979602 100755 --- a/run-scalafmt.sh +++ b/run-scalafmt.sh @@ -3,13 +3,6 @@ output=$(mktemp) warnings=$(mktemp) errors=$(mktemp) -enforce_scala_format_version() { - if [ -e .scalafmt.conf ]; then - perl -pi -e 'next unless s/^\s*(version)=.*/$1=$ENV{scalafmt_version}/' .scalafmt.conf - fi -} - -enforce_scala_format_version scalafmt --non-interactive $args > "$output" 2> "$warnings" result=$? cat "$output"