Skip to content

Commit 2135090

Browse files
authored
Merge pull request #1530 from wleczny/scala-experimental-brew-formula
Automate deploy of scala-experimental brew formula
2 parents fcb6877 + effad69 commit 2135090

File tree

3 files changed

+107
-24
lines changed

3 files changed

+107
-24
lines changed

.github/scripts/scala.rb.template

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# typed: false
2+
# frozen_string_literal: true
3+
4+
# Experimental Scala Formula
5+
class Scala < Formula
6+
desc "Experimental launcher for Scala"
7+
homepage "https://virtuslab.github.io/scala-cli/"
8+
url (RUBY_PLATFORM.include? "arm64") ?
9+
"@ARM64_LAUNCHER_URL@" :
10+
"@X86_LAUNCHER_URL@"
11+
version "@LAUNCHER_VERSION@"
12+
sha256 (RUBY_PLATFORM.include? "arm64") ?
13+
"@ARM64_LAUNCHER_SHA256@" :
14+
"@X86_LAUNCHER_SHA256@"
15+
license "Apache-2.0"
16+
17+
def install
18+
if (RUBY_PLATFORM.include? "arm64")
19+
bin.install "scala-cli-aarch64-apple-darwin" => "scala-cli"
20+
else
21+
bin.install "scala-cli-x86_64-apple-darwin" => "scala-cli"
22+
end
23+
bin.install_symlink "scala-cli" => "scala"
24+
end
25+
26+
test do
27+
(testpath / "Hello.scala").write "object Hello {
28+
def main(args: Array[String]): Unit =
29+
println(\"Hello from Scala\")
30+
}"
31+
output = shell_output("#{bin}/scala-cli Hello.scala")
32+
assert_equal ["Hello from Scala\n"], output.lines
33+
end
34+
end

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,10 @@ jobs:
969969
ssh-private-key: |
970970
${{ secrets.SCALA_CLI_PACKAGES_KEY }}
971971
${{ secrets.HOMEBREW_SCALA_CLI_KEY }}
972+
${{ secrets.HOMEBREW_SCALA_EXPERIMENTAL_KEY }}
972973
${{ secrets.SCALA_CLI_SETUP_KEY }}
973974
- run: ./mill -i ci.updateInstallationScript
974-
- run: ./mill -i ci.updateBrewFormula
975+
- run: ./mill -i ci.updateScalaCliBrewFormula
975976
- name: GPG setup
976977
run: .github/scripts/gpg-setup.sh
977978
env:
@@ -996,6 +997,7 @@ jobs:
996997
SDKMAN_KEY: ${{ secrets.SDKMAN_KEY }}
997998
SDKMAN_TOKEN: ${{ secrets.SDKMAN_TOKEN }}
998999
- run: ./mill -i ci.updateScalaCliSetup
1000+
- run: ./mill -i ci.updateScalaExperimentalBrewFormula
9991001

10001002
update-windows-packages:
10011003
name: Update Windows packages

build.sc

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,31 @@ object ci extends Module {
13731373
os.proc("gh", "pr", "create", "--fill", "--base", "main", "--head", targetBranch)
13741374
.call(cwd = scalaCliDir)
13751375
}
1376-
def updateBrewFormula() = T.command {
1376+
def brewLaunchersSha(x86LauncherPath: os.Path, arm64LauncherPath: os.Path, targetDir: os.Path) = {
1377+
val x86BinarySha256 = os.proc("openssl", "dgst", "-sha256", "-binary")
1378+
.call(
1379+
cwd = targetDir,
1380+
stdin = os.read.stream(x86LauncherPath)
1381+
).out.bytes
1382+
val arm64BinarySha256 = os.proc("openssl", "dgst", "-sha256", "-binary")
1383+
.call(
1384+
cwd = targetDir,
1385+
stdin = os.read.stream(arm64LauncherPath)
1386+
).out.bytes
1387+
val x86Sha256 = os.proc("xxd", "-p", "-c", "256")
1388+
.call(
1389+
cwd = targetDir,
1390+
stdin = x86BinarySha256
1391+
).out.trim()
1392+
val arm64Sha256 = os.proc("xxd", "-p", "-c", "256")
1393+
.call(
1394+
cwd = targetDir,
1395+
stdin = arm64BinarySha256
1396+
).out.trim()
1397+
1398+
(x86Sha256, arm64Sha256)
1399+
}
1400+
def updateScalaCliBrewFormula() = T.command {
13771401
val version = cli.publishVersion()
13781402

13791403
val targetDir = os.pwd / "target"
@@ -1391,33 +1415,14 @@ object ci extends Module {
13911415
gitClone(repo, branch, targetDir)
13921416
setupGithubRepo(homebrewFormulaDir)
13931417

1394-
val x86LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-x86_64-apple-darwin.gz"
1395-
val arm64LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-aarch64-apple-darwin.gz"
13961418
val x86LauncherURL =
13971419
s"https://github.com/Virtuslab/scala-cli/releases/download/v$version/scala-cli-x86_64-apple-darwin.gz"
13981420
val arm64LauncherURL =
13991421
s"https://github.com/Virtuslab/scala-cli/releases/download/v$version/scala-cli-aarch64-apple-darwin.gz"
14001422

1401-
val x86BinarySha256 = os.proc("openssl", "dgst", "-sha256", "-binary")
1402-
.call(
1403-
cwd = targetDir,
1404-
stdin = os.read.stream(x86LauncherPath)
1405-
).out.bytes
1406-
val arm64BinarySha256 = os.proc("openssl", "dgst", "-sha256", "-binary")
1407-
.call(
1408-
cwd = targetDir,
1409-
stdin = os.read.stream(arm64LauncherPath)
1410-
).out.bytes
1411-
val x86Sha256 = os.proc("xxd", "-p", "-c", "256")
1412-
.call(
1413-
cwd = targetDir,
1414-
stdin = x86BinarySha256
1415-
).out.trim()
1416-
val arm64Sha256 = os.proc("xxd", "-p", "-c", "256")
1417-
.call(
1418-
cwd = targetDir,
1419-
stdin = arm64BinarySha256
1420-
).out.trim()
1423+
val x86LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-x86_64-apple-darwin.gz"
1424+
val arm64LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-aarch64-apple-darwin.gz"
1425+
val (x86Sha256, arm64Sha256) = brewLaunchersSha(x86LauncherPath, arm64LauncherPath, targetDir)
14211426

14221427
val templateFormulaPath = os.pwd / ".github" / "scripts" / "scala-cli.rb.template"
14231428
val template = os.read(templateFormulaPath)
@@ -1434,6 +1439,48 @@ object ci extends Module {
14341439

14351440
commitChanges(s"Update for $version", branch, homebrewFormulaDir)
14361441
}
1442+
def updateScalaExperimentalBrewFormula() = T.command {
1443+
val version = cli.publishVersion()
1444+
1445+
val targetDir = os.pwd / "target"
1446+
val homebrewFormulaDir = targetDir / "homebrew-scala-experimental"
1447+
1448+
// clean target directory
1449+
if (os.exists(targetDir)) os.remove.all(targetDir)
1450+
1451+
os.makeDir.all(targetDir)
1452+
1453+
val branch = "main"
1454+
val repo = s"[email protected]:VirtusLab/homebrew-scala-experimental.git"
1455+
1456+
// Cloning
1457+
gitClone(repo, branch, targetDir)
1458+
setupGithubRepo(homebrewFormulaDir)
1459+
1460+
val x86LauncherURL =
1461+
s"https://github.com/Virtuslab/scala-cli/releases/download/v$version/scala-cli-x86_64-apple-darwin.gz"
1462+
val arm64LauncherURL =
1463+
s"https://github.com/Virtuslab/scala-cli/releases/download/v$version/scala-cli-aarch64-apple-darwin.gz"
1464+
1465+
val x86LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-x86_64-apple-darwin.gz"
1466+
val arm64LauncherPath = os.Path("artifacts", os.pwd) / "scala-cli-aarch64-apple-darwin.gz"
1467+
val (x86Sha256, arm64Sha256) = brewLaunchersSha(x86LauncherPath, arm64LauncherPath, targetDir)
1468+
1469+
val templateFormulaPath = os.pwd / ".github" / "scripts" / "scala.rb.template"
1470+
val template = os.read(templateFormulaPath)
1471+
1472+
val updatedFormula = template
1473+
.replace("@X86_LAUNCHER_URL@", x86LauncherURL)
1474+
.replace("@ARM64_LAUNCHER_URL@", arm64LauncherURL)
1475+
.replace("@X86_LAUNCHER_SHA256@", x86Sha256)
1476+
.replace("@ARM64_LAUNCHER_SHA256@", arm64Sha256)
1477+
.replace("@LAUNCHER_VERSION@", version)
1478+
1479+
val formulaPath = homebrewFormulaDir / "scala.rb"
1480+
os.write.over(formulaPath, updatedFormula)
1481+
1482+
commitChanges(s"Update for $version", branch, homebrewFormulaDir)
1483+
}
14371484
def updateInstallationScript() = T.command {
14381485
val version = cli.publishVersion()
14391486

0 commit comments

Comments
 (0)