Skip to content

Commit

Permalink
Bleep can now build and publish Bleep! 🎆
Browse files Browse the repository at this point in the history
- drops sbt build
- new publishing scheme for compiled binaries
- publish bleep-cli to maven so coursier can provide a slow version for non-common platforms
  • Loading branch information
oyvindberg committed Jun 25, 2022
1 parent f022ac3 commit 509d556
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 291 deletions.
21 changes: 12 additions & 9 deletions .github/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/bash
mkdir -p work/release
chmod 755 artifacts/linux-binary/bleep-linux
chmod 755 artifacts/macos-binary/bleep-macos

mv artifacts/linux-binary/bleep-linux "work/release/bleep-$VERSION-x86-64-pc-linux"
mv artifacts/macos-binary/bleep-macos "work/release/bleep-$VERSION-x86-64-apple-darwin"
mv artifacts/windows-binary/bleep-windows.exe artifacts/windows-binary/bleep.exe
set -e

mkdir -p work/release

gzip "work/release/bleep-$VERSION-x86-64-pc-linux"
gzip "work/release/bleep-$VERSION-x86-64-apple-darwin"
CWD=$(pwd -P)
(cd artifacts/windows-binary && zip -r "$CWD/work/release/bleep-$VERSION-x86-64-pc-win32.zip" *.exe)

chmod +x artifacts/bleep-x86_64-pc-linux/bleep
(cd artifacts/bleep-x86_64-pc-linux && tar cvfz "$CWD/work/release/bleep-x86_64-pc-linux.tar.gz" bleep)

chmod +x artifacts/bleep-x86_64-apple-darwin/bleep
(cd artifacts/bleep-x86_64-apple-darwin && tar cvfz "$CWD/work/release/bleep-x86_64-apple-darwin.tar.gz" bleep)

(cd artifacts/bleep-x86_64-pc-win32 && zip -r "$CWD/work/release/bleep-x86_64-pc-win32.zip" bleep.exe)

143 changes: 60 additions & 83 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,122 +15,107 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: graalvm/setup-graalvm@v1
with:
version: '22.1.0'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: coursier/setup-action@v1
- uses: coursier/[email protected]
with:
apps: sbt
apps: scalafmt
- uses: coursier/cache-action@v6
- name: Scalafmt Check
if: ${{ matrix.os != 'windows-latest' }}
shell: bash
run: sbt --client scalafmtCheckAll
- name: "Test"
shell: bash
run: sbt --client "test"
- name: "Assembly"
shell: bash
run: sbt --client "bleep-cli/assembly"
- name: Temporarily save package
uses: actions/upload-artifact@v2
with:
name: java-binary
path: |
${{ github.workspace }}/bleep-cli/target/jvm-2.13/bleep-cli-assembly.jar
retention-days: 1
- name: Cleanup before cache
shell: bash
extraFiles: bleep.yaml

- name: Scalafmt Check
run: scalafmt -c .scalafmt.conf --check

- name: Install bleep stable
run: cs install --channel channel bleep:0.0.1-M7 --verbose

- name: Run tests
run: |
rm -rf "$HOME/.ivy2/local" || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
bleep generate-resources
bleep test
build-native-image:
name: Native image build on ${{ matrix.os }}
needs: [ build ]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
file_name: bleep-linux
artifact_name: linux-binary
file_name: bleep
artifact_name: bleep-x86_64-pc-linux
- os: macos-latest
file_name: bleep-macos
artifact_name: macos-binary
file_name: bleep
artifact_name: bleep-x86_64-apple-darwin
- os: windows-latest
file_name: bleep-windows
artifact_name: windows-binary
file_name: bleep.exe
artifact_name: bleep-x86_64-pc-win32
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Download application package
uses: actions/download-artifact@v2
with:
name: java-binary
- uses: graalvm/setup-graalvm@v1
with:
version: '22.1.0'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: coursier/[email protected]
- uses: coursier/cache-action@v6
with:
extraFiles: bleep.yaml

- name: Build native image on Linux
run: mkdir dist && native-image --enable-url-protocols=https -jar bleep-*.jar dist/${{ matrix.file_name }} && chmod 755 dist/${{ matrix.file_name }}
if: runner.os == 'Linux'
- name: Install bleep stable
run: cs install --channel channel bleep:0.0.1-M7 --verbose

- name: Build native image on Mac OS X
run: mkdir dist && native-image --enable-url-protocols=https -jar bleep-*.jar dist/${{ matrix.file_name }} && chmod 755 dist/${{ matrix.file_name }}
if: runner.os == 'macOS'
- name: Build native image (non-windows)
# todo: output should be parameter to native-image after next release
run: |
bleep generate-resources
bleep native-image
mv bleep-cli/target/native-image/bleep-cli ./${{ matrix.file_name }}
if: runner.os != 'Windows'

- name: Test binary after build (non-windows)
run: ./${{ matrix.file_name }} --ignore-version-in-build-file test --no-color jvm213
if: runner.os != 'Windows'

- name: Build native image on Windows
run: >-
mkdir dist && "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && native-image --native-image-info --verbose --enable-url-protocols=https -jar bleep-*.jar dist/${{ matrix.file_name }}
- name: generate resources (windows)
# note: yaml multiline syntax doesn't seem to work (cmd only runs first command).
# that's why this is split in generate resources and build native image below
run: bleep generate-resources
# shell is important here. default is powershell and things do not work there
# see https://github.com/dirs-dev/directories-jvm/issues/49
shell: cmd
if: runner.os == 'Windows'

- name: Test binary after build on Windows
- name: Build native image (windows)
# todo: output should be parameter to native-image after next release
run: bleep native-image
shell: cmd
run: |
.\dist\${{ matrix.file_name }}.exe --ignore-version-in-build-file generate-resources
.\dist\${{ matrix.file_name }}.exe --ignore-version-in-build-file compile --no-color jvm213
if: runner.os == 'Windows'

- name: Test binary after build on Linux
run: |
chmod 755 dist/${{ matrix.file_name }}
./dist/${{ matrix.file_name }} --ignore-version-in-build-file generate-resources
./dist/${{ matrix.file_name }} --ignore-version-in-build-file compile --no-color jvm213
if: runner.os == 'Linux'
- name: Rename native image (windows)
run: move bleep-cli\target\native-image\bleep-cli.exe ${{ matrix.file_name }}
shell: cmd
if: runner.os == 'Windows'

- name: Test binary after build on Macos
run: |
chmod 755 dist/${{ matrix.file_name }}
./dist/${{ matrix.file_name }} --ignore-version-in-build-file generate-resources
./dist/${{ matrix.file_name }} --ignore-version-in-build-file compile --no-color jvm213
if: runner.os == 'macOS'
- name: Test binary after build (windows)
shell: cmd
# todo: fix tests on windows
run: .\${{ matrix.file_name }} --ignore-version-in-build-file compile --no-color jvm213
if: runner.os == 'Windows'

- name: Temporarily save package
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}
path: |
dist/bleep-*
path: ${{ matrix.file_name }}
retention-days: 1

release:
timeout-minutes: 15
runs-on: ubuntu-latest
needs: [ build-native-image ]
needs: [ build, build-native-image ]
if: "startsWith(github.ref, 'refs/tags/v')"
steps:
- uses: actions/checkout@v2
Expand All @@ -144,20 +129,12 @@ jobs:
path: artifacts
- name: Display structure of downloaded files
run: find artifacts
- uses: graalvm/setup-graalvm@v1
with:
version: '22.1.0'
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Release
run: |
chmod +x ./artifacts/linux-binary/bleep-linux
./artifacts/linux-binary/bleep-linux generate-resources
./artifacts/linux-binary/bleep-linux publish
chmod +x ./artifacts/bleep-x86_64-pc-linux/bleep
./artifacts/bleep-x86_64-pc-linux/bleep generate-resources
./artifacts/bleep-x86_64-pc-linux/bleep publish
env:
CI_RELEASE: ${{ secrets.CI_RELEASE }}
CI_SNAPSHOT_RELEASE: ${{ secrets.CI_SNAPSHOT_RELEASE }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ Args = --no-fallback \
-H:+ReportExceptionStackTraces \
--initialize-at-build-time=scala.runtime.Statics$VM \
--initialize-at-build-time=scala.Symbol \
--initialize-at-build-time=scala.Symbol$
--initialize-at-build-time=scala.Symbol$ \
--native-image-info \
--verbose
5 changes: 1 addition & 4 deletions bleep-cli/src/main/scala/bleep/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ object Main {
FetchBleepRelease(wantedVersion, logger, ExecutionContext.global) match {
case Left(buildException) =>
fatal("", logger, buildException)
case Right(path) if JvmIndex.currentOs.contains("windows") =>
// for linux/mac the `path` comes back pointing at the binary,
// while on windows it points to a directory which corresponds to the unzipped file
val binaryPath = path / "bleep.exe"
case Right(binaryPath) if JvmIndex.currentOs.contains("windows") =>
val status = scala.sys.process.Process(binaryPath.toString :: args.toList, Os.cwd.toFile, sys.env.toSeq: _*).!<
sys.exit(status)
case Right(path) =>
Expand Down
79 changes: 55 additions & 24 deletions bleep-cli/src/main/scala/bleep/internal/FetchBleepRelease.scala
Original file line number Diff line number Diff line change
@@ -1,48 +1,79 @@
package bleep.internal
package bleep
package internal

import bleep.logging.Logger
import bleep.{model, BuildException}
import coursier.cache.{ArchiveCache, FileCache}
import coursier.cache.{ArchiveCache, ArtifactError, FileCache}
import coursier.jvm.JvmIndex
import coursier.util.{Artifact, Task}

import java.io.File
import java.nio.file.Path
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.{Await, ExecutionContext, Future}

object FetchBleepRelease {
def apply(wanted: model.Version, logger: Logger, executionContext: ExecutionContext): Either[BuildException, Path] = {
// file names were changed in 0.0.1-M8
val oldLayouts: Set[model.Version] = Range.inclusive(1, 7).toSet.map((n: Int) => model.Version(s"0.0.1-M$n"))

def findExecutable(file: File): Either[String, File] =
if (file.isDirectory) {
file.list().toList match {
case Nil => Left(s"no files found in directory $file")
case List(one) => findExecutable(new File(file, one))
case more => Left(s"expected one file inside $file, got ${more.mkString(", ")}")
}
} else Right(file)

def apply(wanted: model.Version, logger: Logger, executionContext: ExecutionContext): Either[BuildException, Path] =
apply(wanted, logger, executionContext, JvmIndex.currentArchitecture, JvmIndex.currentOs)

def apply(
wanted: model.Version,
logger: Logger,
executionContext: ExecutionContext,
arch: Either[String, String],
os: Either[String, String]
): Either[BuildException, Path] = {
val base = s"https://github.com/oyvindberg/bleep/releases/download/v${wanted.value}"

val isOldLayout = oldLayouts(wanted)

val maybeUrl: Either[String, String] =
(JvmIndex.currentArchitecture, JvmIndex.currentOs) match {
case (Right("amd64"), Right("darwin")) => Right(s"$base/bleep-${wanted.value}-x86-64-apple-darwin.gz")
case (Right("amd64"), Right("linux")) => Right(s"$base/bleep-${wanted.value}-x86-64-pc-linux.gz")
case (Right("amd64"), Right("windows")) => Right(s"$base/bleep-${wanted.value}-x86-64-pc-win32.zip")
case (Right(arch), Right(os)) => Left(s"Unsupported combination of architecture $arch and os $os")
case (Left(unsupported), _) => Left(unsupported)
case (_, Left(unsupported)) => Left(unsupported)
(arch, os) match {
case (Right("amd64"), Right("darwin")) if isOldLayout => Right(s"$base/bleep-${wanted.value}-x86-64-apple-darwin.gz")
case (Right("amd64"), Right("linux")) if isOldLayout => Right(s"$base/bleep-${wanted.value}-x86-64-pc-linux.gz")
case (Right("amd64"), Right("windows")) if isOldLayout => Right(s"$base/bleep-${wanted.value}-x86-64-pc-win32.zip")
case (Right("amd64"), Right("darwin")) => Right(s"$base/bleep-x86_64-apple-darwin.tar.gz")
case (Right("amd64"), Right("linux")) => Right(s"$base/bleep-x86_64-pc-linux.tar.gz")
case (Right("amd64"), Right("windows")) => Right(s"$base/bleep-x86_64-pc-win32.zip")
case (Right(arch), Right(os)) => Left(s"Unsupported combination of architecture $arch and os $os")
case (Left(unsupported), _) => Left(unsupported)
case (_, Left(unsupported)) => Left(unsupported)
}

maybeUrl match {
case Left(msg) => Left(new BuildException.Text(msg))
case Right(uri) =>
Await.result(
ArchiveCache[Task]()
.withCache(FileCache().withLogger(new CoursierLogger(logger)))
.get(Artifact(uri))
.value(executionContext),
Duration.Inf
) match {
val fetching: Future[Either[ArtifactError, File]] = ArchiveCache[Task]()
.withCache(FileCache().withLogger(new CoursierLogger(logger)))
.get(Artifact(uri))
.value(executionContext)

Await.result(fetching, Duration.Inf) match {
case Left(artifactError) =>
Left(new BuildException.ArtifactResolveError(artifactError, s"bleep version ${wanted.value}"))
case Right(file) =>
JvmIndex.currentOs match {
case Right("darwin" | "linux") =>
file.setExecutable(true)
case _ => ()
findExecutable(file) match {
case Left(msg) =>
Left(new BuildException.Text(msg))
case Right(executable) =>
JvmIndex.currentOs match {
case Right("darwin" | "linux") =>
file.setExecutable(true)
case _ => ()
}
Right(executable.toPath)
}
Right(file.toPath)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bleep-core/src/main/scala/bleep/bsp/BloopLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class BloopLogger(logger: Logger) extends BloopRifleLogger {
override def info(msg: => String): Unit = logger.info(s"bloop: $msg")
override def debug(msg: => String): Unit = logger.debug(s"bloop: $msg")
override def error(msg: => String, ex: Throwable): Unit = logger.error(s"bloop: $msg")
override val bloopCliInheritStdout: Boolean = false
override val bloopCliInheritStderr: Boolean = false
override val bloopCliInheritStdout: Boolean = true
override val bloopCliInheritStderr: Boolean = true
override def bloopBspStdout: Option[OutputStream] = Some(new BloopLogger.Log(debug(_)))
override def bloopBspStderr: Option[OutputStream] = Some(new BloopLogger.Log(info(_)))
}
Expand Down
2 changes: 1 addition & 1 deletion bleep-core/src/main/scala/bleep/commands/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ case class Run(

maybeMain.flatMap { main =>
val params = new RunParams(buildTarget(started.buildPaths, project))
val mainClass = new ScalaMainClass(main, args.asJava, List(s"-Duser.dir=${started.prebootstrapped.buildPaths.cwd}").asJava)
val mainClass = new ScalaMainClass(main, args.asJava, util.List.of())
mainClass.setEnvironmentVariables(util.List.of())
params.setData(mainClass)
params.setDataKind("scala-main-class")
Expand Down
Loading

0 comments on commit 509d556

Please sign in to comment.