Skip to content

Commit

Permalink
Rewrite action
Browse files Browse the repository at this point in the history
* replace docker action with composite github action
* update references
* upgrade actions/checkout to v4

* switch from scalafmt:v2.3.2

* 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)
  • Loading branch information
jsoref committed Jan 25, 2024
1 parent baf6438 commit d82614f
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 65 deletions.
14 changes: 14 additions & 0 deletions .github/regenerate-good.sh
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
6 changes: 4 additions & 2 deletions .github/testdata/.scalafmt.conf
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
1 change: 0 additions & 1 deletion .github/testdata/Bad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ sealed abstract class Formatted {
}

/** Aligned by first asterisk, default ScalaDoc style is second.
*
*/
object Formatted {
case class Success(formattedCode: String) extends Formatted
Expand Down
2 changes: 1 addition & 1 deletion .github/testdata/Good.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ messiness added to it. -mroth */
package org.scalafmt

sealed abstract class Formatted {

def toEither: Either[Throwable, String] = this match {
case Formatted.Success(s) => Right(s)
case Formatted.Failure(e) => Left(e) // too much space before comment
Expand All @@ -15,7 +16,6 @@ sealed abstract class Formatted {
}

/** Aligned by first asterisk, default ScalaDoc style is second.
*
*/
object Formatted {
case class Success(formattedCode: String) extends Formatted
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test-all.yml
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"
12 changes: 12 additions & 0 deletions .github/workflows/test-regenerate-good.yml
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"
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
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"
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

23 changes: 3 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
IMAGE := openlaw/scalafmt-ci
# DEFAULT_ARGS := --list
WORKDIR := /github/workspace
TESTDATA := .github/testdata

.PHONY: test testfail testdata clean

image:
docker build -t $(IMAGE) .

test:
docker run --rm -it \
-w=$(WORKDIR) \
-v "$$(pwd)/$(TESTDATA)":$(WORKDIR) \
$(IMAGE) --list --exclude Bad.scala
act -W .github/workflows/test.yml

# expected failure, to see output
testfail:
docker run --rm -it \
-w=$(WORKDIR) \
-v "$$(pwd)/$(TESTDATA)":$(WORKDIR) \
$(IMAGE) --list
act -W .github/workflows/test-all.yml

# generate the "good" version of the sample file
$(TESTDATA)/Good.scala: $(TESTDATA)/Bad.scala $(TESTDATA)/.scalafmt.conf
docker run --rm -i \
-v "$$(pwd)/$(TESTDATA)":/conf \
mrothy/scalafmt-native:2.2.2 \
--config /conf/.scalafmt.conf \
--stdin --stdout \
< $< > $@
./.github/regenerate-good.sh

testdata: $(TESTDATA)/Good.scala

Expand Down
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Simply add a step such as the following to your your workflow yml file:

```yml
- name: Check for scalafmt conformance
uses: openlawteam/scalafmt-ci@v2
uses: garnercorp/scalafmt-ci@v3
```
Example in the full context of a workflow file, with some optional arguments:
Expand All @@ -24,28 +24,11 @@ jobs:
scalafmt-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Checking your code to see if u r naughty or nice
uses: openlawteam/scalafmt-ci@v2
uses: garnercorp/scalafmt-ci@v3
with:
args: "--exclude=third_party --list"
```
### Installing with GitHub Marketplace
https://github.com/marketplace/actions/scalafmt-action
### (Legacy) HCL Syntax
If you are still using legacy HCL format (from the GitHub Actions Alpha test),
you will need to pin to a previous version of this action.
```hcl
action "lint" {
uses="openlawteam/scalafmt-ci@v0"
# optional additional args
args="--exclude ./vendor"
}
```
33 changes: 28 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Scalafmt Action"
description: "Format Scala code using scalafmt"
author: "Matthew Rothenberg <[email protected]>"
author: "GarnerCorp <[email protected]>"
branding:
icon: "wind"
color: "red"
Expand All @@ -9,8 +9,31 @@ inputs:
description: "Args to pass to scalafmt"
default: "--list"
required: false
version:
description: "Version of scalafmt"
default: "3.7.15"
required: false

runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.args }}
using: "composite"
steps:
- shell: bash
run: |
${{ github.action_path }}/set-path.sh
env:
scalafmt_version: ${{ inputs.version }}
- uses: actions/cache@v3
id: cache
with:
path: ${{ env.SCALAFMT_PATH }}
key: scalafmt-${{ inputs.version }}
- shell: bash
if: ${{ !steps.cache.outputs.cache-hit }}
run: |
curl -sL https://github.com/scalameta/scalafmt/releases/download/v${scalafmt_version}/scalafmt-linux-glibc > "$SCALAFMT_PATH/scalafmt"
chmod +x "$SCALAFMT_PATH/scalafmt"
- shell: bash
run: |
${{ github.action_path }}/run-scalafmt.sh
env:
args: ${{ inputs.args }}
2 changes: 0 additions & 2 deletions entrypoint.sh

This file was deleted.

2 changes: 2 additions & 0 deletions run-scalafmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
scalafmt --non-interactive $args
8 changes: 8 additions & 0 deletions set-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/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" >> "$GITHUB_PATH"

0 comments on commit d82614f

Please sign in to comment.