diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 777268dbc1d..303e0e87ba4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -154,4 +154,6 @@ jobs: uses: ./.github/workflows/run-mill-action.yml with: java-version: '11' - buildcmd: ./mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources + __.mimaReportBinaryIssues + __.fix --check + buildcmd: | + ci/scalafmt.sh --test + ./mill -i __.mimaReportBinaryIssues + __.fix --check diff --git a/.scalafmt.conf b/.scalafmt.conf index 94752dfaa01..1417b9a7e28 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -22,3 +22,21 @@ project.git = true runner.dialect = scala213 +project.includePaths = [ + "glob:**.scala" + "glob:**.sc" + "glob:**.mill" +] + +project.excludeFilters = [ + # can't get fileOverride to work to specify scala3 as dialect for these + "scalalib/test/resources/hello-dotty/*" + # these have scaladoc comments with a particular shape that we don't want to reformat + "example/*" + # these need to have a wrong format, tests check that Mill can reformat them + "scalalib/test/resources/scalafmt/*" + # these don't parse + "integration/failure/parse-error/*" + # the g8 patterns confuse the scalafmt parser + "scalalib/test/resources/giter8/hello.g8/src/main/g8/build.mill" +] diff --git a/ci/scalafmt.sh b/ci/scalafmt.sh new file mode 100755 index 00000000000..dc583438098 --- /dev/null +++ b/ci/scalafmt.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# This is the launcher script of scalafmt-native-image (https://github.com/VirtusLab/scalafmt-native-image). +# This script downloads and runs scalafmt-native-image version set by SCALAFMT_VERSION below. +# +# Download the latest version of this script at https://github.com/VirtusLab/scalafmt-native-image/raw/main/scalafmt.sh + +set -eu + +DEFAULT_SCALAFMT_VERSION="3.8.3" + +SCALAFMT_VERSION="" +if test -e .scalafmt.conf; then + SCALAFMT_VERSION="$(cat .scalafmt.conf | grep '^version\s*=\s*"[0-9.A-Z-]*"$' | sed 's/^version[ \t]*=[ \t]*"\([0-9.A-Z-]*\)"$/\1/g')" +fi + +if [ "$SCALAFMT_VERSION" == "" ]; then + SCALAFMT_VERSION="$DEFAULT_SCALAFMT_VERSION" + if test -e .scalafmt.conf; then + echo "Warning: no scalafmt version found in .scalafmt.conf, using $SCALAFMT_VERSION" 1>&2 + else + echo "Warning: no .scalafmt.conf found, using scalafmt version $SCALAFMT_VERSION" 1>&2 + fi +fi + +GH_ORG="VirtusLab" +GH_NAME="scalafmt-native-image" + +TAG="v$SCALAFMT_VERSION" + +if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then + arch=$(uname -m) + if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "x86_64" ]]; then + SCALAFMT_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scalafmt-${arch}-pc-linux.gz" + else + echo "scalafmt-native-image is not supported on $arch" 1>&2 + exit 2 + fi + CACHE_BASE="$HOME/.cache/coursier/v1" +elif [ "$(uname)" == "Darwin" ]; then + arch=$(uname -m) + CACHE_BASE="$HOME/Library/Caches/Coursier/v1" + if [[ "$arch" == "x86_64" ]]; then + SCALAFMT_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scalafmt-x86_64-apple-darwin.gz" + elif [[ "$arch" == "arm64" ]]; then + SCALAFMT_URL="https://github.com/$GH_ORG/$GH_NAME/releases/download/$TAG/scalafmt-aarch64-apple-darwin.gz" + else + echo "scalafmt-native-image is not supported on $arch" 1>&2 + exit 2 + fi +else + echo "This standalone scalafmt-native-image launcher is supported only in Linux and macOS." 1>&2 + exit 1 +fi + +CACHE_DEST="$CACHE_BASE/$(echo "$SCALAFMT_URL" | sed 's@://@/@')" +SCALAFMT_BIN_PATH=${CACHE_DEST%.gz} + +if [ ! -f "$CACHE_DEST" ]; then + mkdir -p "$(dirname "$CACHE_DEST")" + TMP_DEST="$CACHE_DEST.tmp-setup" + echo "Downloading $SCALAFMT_URL" 1>&2 + curl -fLo "$TMP_DEST" "$SCALAFMT_URL" + mv "$TMP_DEST" "$CACHE_DEST" +fi + +if [ ! -f "$SCALAFMT_BIN_PATH" ]; then + gunzip -k "$CACHE_DEST" +fi + +if [ ! -x "$SCALAFMT_BIN_PATH" ]; then + chmod +x "$SCALAFMT_BIN_PATH" +fi + +exec "$SCALAFMT_BIN_PATH" "$@" diff --git a/main/package.mill b/main/package.mill index a2696ff9d48..80dcaf5584b 100644 --- a/main/package.mill +++ b/main/package.mill @@ -49,8 +49,8 @@ object `package` extends RootModule with build.MillStableScalaModule with BuildI Some(T.ctx()), build.dist.coursierCacheCustomizer() )._2.minDependencies.toSeq - // change to this when bumping Mill - // ).getOrThrow.minDependencies.toSeq + // change to this when bumping Mill + // ).getOrThrow.minDependencies.toSeq .map(d => s"${d.module.organization.value}:${d.module.name.value}:${d.version}") ) // T.traverse(dev.moduleDeps)(_.publishSelfDependency)() diff --git a/scalalib/test/resources/testrunner/scalatest/src/ScalaTestSpec.scala b/scalalib/test/resources/testrunner/scalatest/src/ScalaTestSpec.scala index 832b3aa8f87..3b2eba3c771 100644 --- a/scalalib/test/resources/testrunner/scalatest/src/ScalaTestSpec.scala +++ b/scalalib/test/resources/testrunner/scalatest/src/ScalaTestSpec.scala @@ -19,7 +19,7 @@ class ScalaTestSpec extends AnyFreeSpec { } } - "should be tagged" taggedAs(TaggedTest) in { + "should be tagged" taggedAs (TaggedTest) in { assert(true) } }