From 65af6e29918e715b6daddccdbd7993887fb2f576 Mon Sep 17 00:00:00 2001 From: Finn Hackett Date: Tue, 3 Jun 2025 02:44:45 +0000 Subject: [PATCH 1/2] add formatter script sanity check to CI --- .devcontainer/devcontainer.json | 2 +- .github/workflows/test.yml | 4 ++++ langs/calc/CalcParser.scala | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d6ece60..6b51e86 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "DCal", + "name": "Forja", "build": { "dockerfile": "Dockerfile" }, diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3958729..b4dc5e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,3 +17,7 @@ jobs: with: jvm: ${{ matrix.jvm }} - run: scala-cli test . + - name: "Check: formatter script shouldn't create a diff on clean tree" + run: | + scala-cli run . --main-class scripts.rewrite_src_sc + [ -n "$(git status --porcelain)" ] diff --git a/langs/calc/CalcParser.scala b/langs/calc/CalcParser.scala index a8ed8fb..7a62926 100644 --- a/langs/calc/CalcParser.scala +++ b/langs/calc/CalcParser.scala @@ -96,6 +96,7 @@ object CalcParser extends PassSeq: object AddSubPass extends Pass: val wellformed = prevWellformed.makeDerived: Node.Top.removeCases(AddOp, SubOp) + Group.removeCases(AddOp, SubOp) Expression.addCases(Add, Sub) Add ::= fields( Expression, From 3f8d4320a27774a0b8da466b379a2b8409594330 Mon Sep 17 00:00:00 2001 From: Finn Hackett Date: Tue, 3 Jun 2025 03:01:29 +0000 Subject: [PATCH 2/2] portable diff check --- .github/workflows/test.yml | 8 ++++---- scripts/check_no_diff.scala | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 scripts/check_no_diff.scala diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4dc5e0..eaa5853 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: with: jvm: ${{ matrix.jvm }} - run: scala-cli test . - - name: "Check: formatter script shouldn't create a diff on clean tree" - run: | - scala-cli run . --main-class scripts.rewrite_src_sc - [ -n "$(git status --porcelain)" ] + - name: "Run all formatters on a clean tree" + run: scala-cli run . --main-class scripts.rewrite_src_sc + - name: "Check: the tree did not change due to the formatters" + run: scala-cli run . --main-class scripts.check_no_diff_sc diff --git a/scripts/check_no_diff.scala b/scripts/check_no_diff.scala new file mode 100644 index 0000000..39913a9 --- /dev/null +++ b/scripts/check_no_diff.scala @@ -0,0 +1,31 @@ +// Copyright 2024-2025 Forja Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package scripts + +@main +def check_no_diff_sc(): Unit = + val result = os + .proc("git", "status", "--porcelain") + .call(cwd = os.pwd, mergeErrIntoOut = true) + val strippedOut = result.out.text().strip() + + if strippedOut.isEmpty + then + println("ok: no diff detected") + sys.exit(0) + else + println("diff detected!") + strippedOut.linesIterator.foreach(println) + sys.exit(1)