forked from openlawteam/scalafmt-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* replace docker action with GitHub Composite Action * cache scalafmt binary * update references * upgrade actions/checkout to v4 * add step summary * strip GITHUB_WORKSPACE path from output * switch from scalafmt:v2.3.2 * enforce scala format version * support specifying an arbitrary version of scalafmt (as long as it's available as `scalafmt-linux-glibc` in releases) * take responsibility for this action * drop GitHub Marketplace instructions (this will come back once we publish) * drop references to HCL syntax (GitHub Actions Alpha is sufficiently obsolete that no one remembers it) * highlight `Segmentation fault` as an error * update readme
- Loading branch information
Showing
15 changed files
with
176 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
act -W .github/workflows/test-regenerate-good.yml 2>/dev/null | | ||
perl -ne ' | ||
unless ($state) { | ||
$state = 1 if (/run-scalafmt\.sh/); | ||
next; | ||
} | ||
if ($state == 1) { | ||
$state = 2 if (/docker exec/); | ||
next; | ||
} | ||
last unless s/^.*\| //; | ||
print; | ||
' > .github/testdata/Good.scala |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# I dont like this formatting directive in reality, but lets | ||
# I don't like this formatting directive in reality, but it lets | ||
# us verify that this is reading a conf file easily | ||
align = most | ||
align.preset = most | ||
version = 3.7.15 | ||
runner.dialect = scala213 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
on: [workflow_dispatch] | ||
name: Check with all testdata | ||
|
||
jobs: | ||
check-testdata: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checking testdata | ||
uses: ./ | ||
with: | ||
args: "-c .github/testdata/.scalafmt.conf --list" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
on: [workflow_dispatch] | ||
name: Regenerate Good file (run in act) | ||
|
||
jobs: | ||
regenerate-good: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checking testdata | ||
uses: ./ | ||
with: | ||
args: "-c .github/testdata/.scalafmt.conf --stdout .github/testdata/Bad.scala" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
on: [push] | ||
name: Check with testdata | ||
name: Check with good testdata | ||
|
||
jobs: | ||
check-testdata: | ||
check-good-testdata: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Checking testdata | ||
- uses: actions/checkout@v4 | ||
- name: Checking testdata (pass) | ||
uses: ./ | ||
with: | ||
args: "-c .github/testdata/.scalafmt.conf --exclude .github/testdata/Bad.scala --list" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env perl | ||
my $source_file = $ENV{source}; | ||
my $errors_file = $ENV{errors}; | ||
my $new_source_file = "$source_file.new"; | ||
open my $source_in, "<", $source_file; | ||
open my $source_out, ">", $new_source_file; | ||
open my $errors, ">>", $errors_file; | ||
my $found_error=0; | ||
while (<$source_in>) { | ||
if ($found_error) { | ||
print $errors $_; | ||
} elsif (/^error:|^Segmentation fault/) { | ||
$found_error=1; | ||
print $errors $_; | ||
} else { | ||
print $source_out $_; | ||
} | ||
} | ||
close $source_in; | ||
close $source_out; | ||
close $errors; | ||
rename $new_source_file, $source_file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
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 | ||
|
||
report() { | ||
file="$1" | ||
summary="$2" | ||
|
||
[ -s "$file" ] || return | ||
echo "<details><summary>$summary</summary>" | ||
echo | ||
echo '```' | ||
perl -pe 's/$ENV{GITHUB_WORKSPACE}//g' "$file" | ||
echo '```' | ||
echo '</details>' | ||
echo | ||
} | ||
|
||
source="$output" errors="$errors" extract-errors.pl | ||
source="$warnings" errors="$errors" extract-errors.pl | ||
|
||
( | ||
echo "# scalafmt failed ($result)" | ||
if [ -s "$errors" ]; then | ||
echo '# Errors' | ||
cat "$errors" | ||
fi | ||
report "$warnings" "Warnings" | ||
report "$output" "Status" | ||
) >> "$GITHUB_STEP_SUMMARY" | ||
exit $result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
SCALAFMT_PATH="/tmp/scalafmt/${scalafmt_version}" | ||
mkdir -p "$SCALAFMT_PATH" | ||
( | ||
echo "SCALAFMT_PATH=$SCALAFMT_PATH" | ||
echo "scalafmt_version=$scalafmt_version" | ||
) >> "$GITHUB_ENV" | ||
( | ||
echo "$SCALAFMT_PATH" | ||
echo "$action_path" | ||
) >> "$GITHUB_PATH" |