From e547c9c7ba96813f8c16490bd7b544927ddca21a Mon Sep 17 00:00:00 2001 From: Rolandas Valteris Date: Wed, 2 Dec 2020 02:31:55 -0500 Subject: [PATCH 1/2] Allow building from a release source archive Add support for `RELEASE_ARCHIVE_VERSION` environment variable to `build.sc`. If `RELEASE_ARCHIVE_VERSION` is set, it assumes, that build is performed from the release source archive and does not invoke `git` command, which otherwise would result in `fatal: not a git repository` error. `RELEASE_ARCHIVE_VERSION` should be set to the source archive version, e.g: ``` $ RELEASE_ARCHIVE_VERSION=2.3.8 mill -i amm[2.13.3].assembly ``` --- build.sc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/build.sc b/build.sc index dcae58a7d..0b87906a7 100644 --- a/build.sc +++ b/build.sc @@ -8,12 +8,19 @@ val isMasterCommit = sys.env.get("GITHUB_REPOSITORY") == Some("lihaoyi/Ammonite") && sys.env.get("GITHUB_REF").exists(x => x.endsWith("/master")) -val latestTaggedVersion = os.proc('git, 'describe, "--abbrev=0", "--tags").call().out.trim +val releaseArchiveVersion = sys.env.get("RELEASE_ARCHIVE_VERSION") -val gitHead = os.proc('git, "rev-parse", "HEAD").call().out.trim +val latestTaggedVersion = releaseArchiveVersion + .getOrElse(os.proc('git, 'describe, "--abbrev=0", "--tags").call().out.trim) -val commitsSinceTaggedVersion = { - os.proc('git, "rev-list", gitHead, "--not", latestTaggedVersion, "--count") +val gitHead = releaseArchiveVersion match { + case Some(ver) => ver + case None => os.proc('git, "rev-parse", "HEAD").call().out.trim +} + +val commitsSinceTaggedVersion = releaseArchiveVersion match { + case Some(_) => 0 + case None => os.proc('git, "rev-list", gitHead, "--not", latestTaggedVersion, "--count") .call() .out .trim @@ -35,10 +42,13 @@ val latestAssemblies = binCrossScalaVersions.map(amm(_).assembly) println("GITHUB REF " + sys.env.get("GITHUB_REF")) val (buildVersion, unstable) = scala.util.Try( - os.proc('git, 'describe, "--exact-match", "--tags", "--always", gitHead) - .call() - .out - .trim + releaseArchiveVersion match { + case Some(ver) => ver + case None => os.proc('git, 'describe, "--exact-match", "--tags", "--always", gitHead) + .call() + .out + .trim + } ).toOption match{ case None => val gitHash = os.proc("git", "rev-parse", "--short", "HEAD").call().out.trim From b11817ed109f2a27fa6db0935a010ec77ee18f6c Mon Sep 17 00:00:00 2001 From: Rolandas Valteris Date: Wed, 2 Dec 2020 02:36:54 -0500 Subject: [PATCH 2/2] Allow echo command to be located in /usr/bin/echo as well in test assertion In some Linux distros (e.g., Arch Linux), `/bin` is just a symlink to `/usr/bin` and `PATH` does not contain `/bin`. In this case `which echo` returns `/usr/bin/echo` and not `/bin/echo`. --- ops/src/test/scala/test/ammonite/ops/ShelloutTests.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/src/test/scala/test/ammonite/ops/ShelloutTests.scala b/ops/src/test/scala/test/ammonite/ops/ShelloutTests.scala index a90c34689..b757fcd88 100644 --- a/ops/src/test/scala/test/ammonite/ops/ShelloutTests.scala +++ b/ops/src/test/scala/test/ammonite/ops/ShelloutTests.scala @@ -63,7 +63,7 @@ object ShelloutTests extends TestSuite{ if(Unix()){ val res = %%('which, 'echo) val echoRoot = Path(res.out.string.trim) - assert(echoRoot == root/'bin/'echo) + assert(echoRoot == root/'bin/'echo || echoRoot == root/'usr/'bin/'echo) assert(%%(echoRoot, 'HELLO).out.lines == Seq("HELLO")) }