Skip to content

Commit

Permalink
Infer scalafmt version from .scalafmt.conf instead of using arg (#5)
Browse files Browse the repository at this point in the history
* Infer scalafmt version from `.scalafmt.conf` instead of using arg

* Add GitHub step summary messages for failed and successful runs
  • Loading branch information
lzm0 authored Jun 24, 2024
1 parent f296366 commit 9d1eebd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 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" >> "$GITHUB_STEP_SUMMARY"
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 }}
9 changes: 1 addition & 8 deletions run-scalafmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ 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"
cat "$warnings" >&2
[ $result -eq 0 ] && exit
[ $result -eq 0 ] && echo "All files well-formatted ✨" >> "$GITHUB_STEP_SUMMARY" && exit

report() {
file="$1"
Expand Down

0 comments on commit 9d1eebd

Please # to comment.