From e60d476d443d81bd4321b483ff47037a608d8475 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Wed, 24 Mar 2021 14:14:40 +0100 Subject: [PATCH] Reintroduce support for Scala 2.11 - Add Github actions - Use VcsVersion to derive version from tag - Update mill and add script --- .github/workflows/actions.yml | 51 ++++++++++++++++++++ .travis.yml | 14 ------ acyclic/src-2.11/acyclic/plugin/Compat.scala | 24 +++++++++ build.sc | 10 ++-- mill | 48 ++++++++++++++++++ 5 files changed, 129 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/actions.yml delete mode 100644 .travis.yml create mode 100644 acyclic/src-2.11/acyclic/plugin/Compat.scala create mode 100755 mill diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..4e877ce --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,51 @@ +name: ci + +on: + push: + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Run tests + run: ./mill -i -j $(nproc) __.publishArtifacts __.test + + publish-sonatype: + if: github.repository == 'com-lihaoyi/acyclic' && contains(github.ref, 'refs/tags/') + needs: test + runs-on: ubuntu-latest + env: + SONATYPE_PGP_PRIVATE_KEY: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY }} + SONATYPE_PGP_PRIVATE_KEY_PASSWORD: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY_PASSWORD }} + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + LANG: "en_US.UTF-8" + LC_MESSAGES: "en_US.UTF-8" + LC_ALL: "en_US.UTF-8" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Publish to Maven Central + run: | + if [[ $(git tag --points-at HEAD) != '' ]]; then + echo $SONATYPE_PGP_PRIVATE_KEY | base64 --decode > gpg_key + gpg --import --no-tty --batch --yes gpg_key + rm gpg_key + ./mill -i mill.scalalib.PublishModule/publishAll \ + --sonatypeCreds $SONATYPE_USER:$SONATYPE_PASSWORD \ + --gpgArgs --passphrase=$SONATYPE_PGP_PRIVATE_KEY_PASSWORD,--no-tty,--pinentry-mode,loopback,--batch,--yes,-a,-b \ + --publishArtifacts __.publishArtifacts \ + --readTimeout 600000 \ + --awaitTimeout 600000 \ + --release true \ + --signed true + fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fac3891..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: scala -jdk: -- oraclejdk8 - -before_install: - - git fetch --tags - -script: - - curl -L -o ~/bin/mill https://github.com/lihaoyi/mill/releases/download/0.4.0/0.4.0-12-102ddf && chmod +x ~/bin/mill - - export PATH=~/bin/mill:$PATH - - mill -i __.test.test - -sudo: false - diff --git a/acyclic/src-2.11/acyclic/plugin/Compat.scala b/acyclic/src-2.11/acyclic/plugin/Compat.scala new file mode 100644 index 0000000..b421a78 --- /dev/null +++ b/acyclic/src-2.11/acyclic/plugin/Compat.scala @@ -0,0 +1,24 @@ +package acyclic.plugin + +import acyclic.file + +import scala.collection.{SortedSet, SortedSetLike} +import scala.collection.mutable.Builder +import scala.collection.generic.{CanBuildFrom, SortedSetFactory} +import scala.language.implicitConversions + +object Compat { + + // from https://github.com/scala/scala-collection-compat/blob/746a7de28223812b19d0d9f68d2253e0c5f655ca/compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala#L8-L11 + private def simpleCBF[A, C](f: => Builder[A, C]): CanBuildFrom[Any, A, C] = new CanBuildFrom[Any, A, C] { + def apply(from: Any): Builder[A, C] = apply() + def apply(): Builder[A, C] = f + } + + // from https://github.com/scala/scala-collection-compat/blob/746a7de28223812b19d0d9f68d2253e0c5f655ca/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala#L46-L49 + implicit def sortedSetCompanionToCBF[A: Ordering, + CC[X] <: SortedSet[X] with SortedSetLike[X, CC[X]]]( + fact: SortedSetFactory[CC]): CanBuildFrom[Any, A, CC[A]] = + simpleCBF(fact.newBuilder[A]) + +} \ No newline at end of file diff --git a/build.sc b/build.sc index 63a3002..3d765e3 100644 --- a/build.sc +++ b/build.sc @@ -1,9 +1,11 @@ import mill._, scalalib._, publish._ +import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.9:0.1.1` +import de.tobiasroeser.mill.vcs.version.VcsVersion -object acyclic extends Cross[AcyclicModule]("2.12.8", "2.13.0") +object acyclic extends Cross[AcyclicModule]("2.11.12", "2.12.8", "2.13.0") class AcyclicModule(val crossScalaVersion: String) extends CrossScalaModule with PublishModule { def artifactName = "acyclic" - def publishVersion = "0.2.0" + def publishVersion = VcsVersion.vcsState().format() def pomSettings = PomSettings( description = artifactName(), @@ -24,8 +26,8 @@ class AcyclicModule(val crossScalaVersion: String) extends CrossScalaModule with def testFrameworks = Seq("utest.runner.Framework") def sources = T.sources(millSourcePath / "src", millSourcePath / "resources") def ivyDeps = Agg( - ivy"com.lihaoyi::utest:0.6.9", + ivy"com.lihaoyi::utest:0.7.7", ivy"org.scala-lang:scala-compiler:$crossScalaVersion" ) } -} \ No newline at end of file +} diff --git a/mill b/mill new file mode 100755 index 0000000..cc56cc8 --- /dev/null +++ b/mill @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +# This is a wrapper script, that automatically download mill from GitHub release pages +# You can give the required mill version with MILL_VERSION env variable +# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION +DEFAULT_MILL_VERSION=0.9.5-52-ef6d5d + +set -e + +if [ -z "$MILL_VERSION" ] ; then + if [ -f ".mill-version" ] ; then + MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)" + elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then + MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2) + else + MILL_VERSION=$DEFAULT_MILL_VERSION + fi +fi + +if [ "x${XDG_CACHE_HOME}" != "x" ] ; then + MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download" +else + MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download" +fi +MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}" + +version_remainder="$MILL_VERSION" +MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}" +MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}" + +if [ ! -x "$MILL_EXEC_PATH" ] ; then + mkdir -p $MILL_DOWNLOAD_PATH + if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then + ASSEMBLY="-assembly" + fi + DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download + MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION${ASSEMBLY}" + curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL" + chmod +x "$DOWNLOAD_FILE" + mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH" + unset DOWNLOAD_FILE + unset MILL_DOWNLOAD_URL +fi + +unset MILL_DOWNLOAD_PATH +unset MILL_VERSION + +exec $MILL_EXEC_PATH "$@"