Skip to content

Instantly share code, notes, and snippets.

@wsargent
Forked from retronym/doc.md
Created June 8, 2017 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsargent/c56fd34078a23fb86e42bf3e326d93a6 to your computer and use it in GitHub Desktop.
Save wsargent/c56fd34078a23fb86e42bf3e326d93a6 to your computer and use it in GitHub Desktop.
Scripts for convenient access to Scala pre-release builds

Install Coursier

https://github.com/coursier/coursier#command-line-1

Add the following functions to your shell

Generate a read-only, personal access token for GitHub.

export GITHUB_TOKEN=XXXXXXX

That gives you 5000 API calls per hour.

_scala_launch() {
  RUNNER=$1
  shift
  VERSION=$1
  shift
  java $JAVA_OPTS -classpath $(coursier fetch -q -p -r https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots -r https://scala-ci.typesafe.com/artifactory/scala-integration "org.scala-lang:scala-compiler:$VERSION") "$RUNNER" "$@"
}

scalac-launch() {
  V=$1
  shift
  _scala_launch scala.tools.nsc.Main $V -usejavacp "$@"
}

scala-launch() {
  V=$1
  shift
  _scala_launch scala.tools.nsc.MainGenericRunner $V -usejavacp "$@"
}

scala-pr() {
  PR=$1
  shift
  scala-launch $(scala-pr-version $PR) "$@"
}

scalac-pr() {
  PR=$1
  shift
  scalac-launch $(scala-pr-version $PR) "$@"
}

scala-ref() {
  PR=$1
  shift
  scala-launch $(scala-ref-version $PR) "$@"
}

scalac-ref() {
  PR=$1
  shift
  scalac-launch $(scala-ref-version $PR) "$@"
}

scala-pr-version() {
  PR=$1
  scala-ref-version pull/$PR/head
}

scala-ref-version() {
  REF=$1
  shift
  SHORT_SHA=$(curl -H "Authorization: token $GITHUB_TOKEN" --silent https://api.github.com/repos/scala/scala/git/refs/$REF | jq -r '.object.sha[0:7]')
  BASE_VERSION=$(curl --silent -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.VERSION.raw"  https://api.github.com/repos/scala/scala/contents/build.sbt?ref=$REF | grep 'baseVersion in Global' | sed -r 's/.*"(.*)".*/\1/')
  CROSS="-bin"
  (echo $BASE_VERSION | grep -q -E '\d+\.\d+.0') && CROSS="-pre"
  VERSION="$BASE_VERSION$CROSS-$SHORT_SHA-SNAPSHOT"
  echo $VERSION
}

Enjoy

% scala-pr 5785
Welcome to Scala 2.12.2-20170327-120916-64ae5a2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.

% scalac-ref heads/2.13.x -version
Scala compiler version 2.13.0-20170530-172738-1521e00 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment