Skip to content

Commit

Permalink
Infer scalafmt version from .scalafmt.conf instead of using arg
Browse files Browse the repository at this point in the history
  • Loading branch information
lzm0 committed Jun 24, 2024
1 parent f296366 commit f18aabe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ jobs:
- uses: actions/checkout@v4
- name: Checking testdata (pass)
uses: ./
working-directory: .github/testdata
with:
args: "-c .github/testdata/.scalafmt.conf --exclude .github/testdata/Bad.scala --list"
args: "--exclude Bad.scala --list"
17 changes: 10 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ 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
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 }}
Expand All @@ -45,4 +48,4 @@ runs:
uses: actions/cache/save@v4
with:
path: ${{ env.SCALAFMT_PATH }}
key: scalafmt-${{ inputs.version }}
key: scalafmt-${{ env.scalafmt_version }}
7 changes: 0 additions & 7 deletions run-scalafmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f18aabe

Please sign in to comment.