Skip to content

Commit 3b2a096

Browse files
authored
Add standalone launcher for Scala CLI - MacOs/Linux (#185)
* Add standalone launcher for Scala CLI - macOs/linux
1 parent 3e95e74 commit 3b2a096

File tree

5 files changed

+109
-9
lines changed

5 files changed

+109
-9
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ jobs:
340340
KEYGRIP: ${{ secrets.KEYGRIP }}
341341
PGP_SECRET: ${{ secrets.PGP_SECRET }}
342342
GPG_EMAIL: ${{ secrets.GPG_EMAIL }}
343+
- run: ./mill -i ci.updateStandaloneLauncher
344+
if: env.SHOULD_PUBLISH == 'true'
345+
env:
346+
UPLOAD_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
347+
343348

344349
website-nightly:
345350
needs: [jvm-tests, format, checks, reference-doc]

build.sc

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,11 @@ def uploadLaunchers(directory: String = "artifacts") = T.command {
595595
val launchers = os.list(path).filter(os.isFile(_)).map { path =>
596596
path.toNIO -> path.last
597597
}
598-
val ghToken = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
599-
sys.error("UPLOAD_GH_TOKEN not set")
600-
}
601598
val (tag, overwriteAssets) =
602599
if (version.endsWith("-SNAPSHOT")) ("nightly", true)
603600
else ("v" + version, false)
604601
System.err.println(s"Uploading to tag $tag (overwrite assets: $overwriteAssets)")
605-
Upload.upload(ghOrg, ghName, ghToken, tag, dryRun = false, overwrite = overwriteAssets)(
602+
Upload.upload(ghOrg, ghName, ghToken(), tag, dryRun = false, overwrite = overwriteAssets)(
606603
launchers: _*
607604
)
608605
}
@@ -652,7 +649,9 @@ def copyStaticLauncher(directory: String = "artifacts") = T.command {
652649
suffix = "-static"
653650
)
654651
}
655-
652+
private def ghToken(): String = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
653+
sys.error("UPLOAD_GH_TOKEN not set")
654+
}
656655
private def gitClone(repo: String, branch: String, workDir: os.Path) =
657656
os.proc("git", "clone", repo, "-q", "-b", branch).call(cwd = workDir)
658657
private def setupGithubRepo(repoDir: os.Path) = {
@@ -677,6 +676,32 @@ private def commitChanges(name: String, branch: String, repoDir: os.Path): Unit
677676

678677
// TODO Move most CI-specific tasks there
679678
object ci extends Module {
679+
def updateStandaloneLauncher() = T.command {
680+
val version = cli.publishVersion()
681+
682+
val targetDir = os.pwd / "target"
683+
val scalaCliDir = targetDir / "scala-cli"
684+
val standaloneLauncherPath = scalaCliDir / "scala-cli.sh"
685+
686+
// clean target directory
687+
if (os.exists(targetDir)) os.remove.all(targetDir)
688+
os.makeDir.all(targetDir)
689+
690+
val branch = "master"
691+
val repo = s"https://oauth2:${ghToken()}@github.com/VirtusLab/scala-cli.git"
692+
693+
// Cloning
694+
gitClone(repo, branch, targetDir)
695+
setupGithubRepo(scalaCliDir)
696+
697+
val launcherScript = os.read(standaloneLauncherPath)
698+
val scalaCliVersionRegex = "SCALA_CLI_VERSION=\".*\"".r
699+
val updatedLauncherScript =
700+
scalaCliVersionRegex.replaceFirstIn(launcherScript, s"SCALA_CLI_VERSION=$version")
701+
os.write.over(standaloneLauncherPath, updatedLauncherScript)
702+
703+
commitChanges(s"Update scala-cli.sh launcher for $version", branch, scalaCliDir)
704+
}
680705
def updateBrewFormula() = T.command {
681706
val version = cli.publishVersion()
682707

scala-cli.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# This is the launcher script of Scala CLI (https://github.com/VirtusLab/scala-cli).
4+
# This script downloads and runs the Scala CLI version set by VERSION below.
5+
#
6+
# Download the latest version of this script at https://github.com/VirtusLab/scala-cli/raw/master/scala-cli.sh
7+
8+
set -eu
9+
10+
SCALA_CLI_VERSION="0.0.4"
11+
12+
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then
13+
SCALA_CLI_URL="https://github.com/VirtusLab/scala-cli/releases/download/v$SCALA_CLI_VERSION/scala-cli-x86_64-pc-linux.gz"
14+
CACHE_BASE="$HOME/.cache/coursier/v1"
15+
elif [ "$(uname)" == "Darwin" ]; then
16+
SCALA_CLI_URL="https://github.com/VirtusLab/scala-cli/releases/download/v$SCALA_CLI_VERSION/scala-cli-x86_64-apple-darwin.gz"
17+
CACHE_BASE="$HOME/Library/Caches/Coursier/v1"
18+
else
19+
echo "This standalone scala-cli launcher is supported only in Linux and Darwin OS. If you are using Windows, please use the dedicated launcher scala-cli.bat"
20+
exit 1
21+
fi
22+
23+
CACHE_DEST="$CACHE_BASE/$(echo "$SCALA_CLI_URL" | sed 's@://@/@')"
24+
SCALA_CLI_BIN_PATH=${CACHE_DEST%.gz}
25+
26+
if [ ! -f "$CACHE_DEST" ]; then
27+
mkdir -p "$(dirname "$CACHE_DEST")"
28+
TMP_DEST="$CACHE_DEST.tmp-setup"
29+
echo "Downloading $SCALA_CLI_URL"
30+
curl -fLo "$TMP_DEST" "$SCALA_CLI_URL"
31+
mv "$TMP_DEST" "$CACHE_DEST"
32+
gunzip -k "$CACHE_DEST"
33+
chmod +x "$SCALA_CLI_BIN_PATH"
34+
fi
35+
36+
exec "$SCALA_CLI_BIN_PATH" "$@"

website/docs/_advanced_install.mdx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ move scala-cli.exe "%USERPROFILE%/scala-cli"
183183

184184
Download MSI installer with Scala CLI for Windows
185185

186-
<DownloadButton desc= 'Scala CLI for Windows' href='https://github.com/Virtuslab/scala-cli/releases/download/nightly/scala-cli-x86_64-pc-win32.msi'></DownloadButton>
186+
<DownloadButton desc= 'Scala CLI for Windows' href='https://github.com/Virtuslab/scala-cli/releases/download/nightly/scala-cli-x86_64-pc-win32.msi' width = '190px'></DownloadButton>
187187

188188
</TabItem>
189189
</Tabs>
@@ -238,6 +238,35 @@ brew install Virtuslab/scala-cli/scala-cli
238238

239239
</div></div>
240240

241+
242+
<SectionAbout title="Standalone launcher">
243+
<div class="margin--lg"/>
244+
<Tabs
245+
defaultValue="macOS/Linux"
246+
groupId="standalone-launcher"
247+
values={[
248+
{label: 'macOS/Linux', value: 'macOS/Linux'},
249+
]}
250+
/>
251+
</SectionAbout>
252+
253+
<div className="row"><div className="col col--9 col--offset-1 padding--lg advanced_install_methods">
254+
255+
Script to automatically download and cache standalone scala-cli launcher.
256+
257+
<Tabs groupId="launcher"
258+
defaultValue="macOS/Linux"
259+
values={[
260+
{label: 'macOS/Linux', value: 'macOS/Linux'},
261+
]}>
262+
<TabItem value="macOS/Linux">
263+
264+
<DownloadButton desc= 'ScalaCLI launcher for macOs/Linux' href='https://github.com/VirtusLab/scala-cli/blob/master/scala-cli.sh' width = '250px' ></DownloadButton>
265+
</TabItem>
266+
</Tabs>
267+
</div></div>
268+
269+
241270
<SectionAbout title="Shell completions">
242271
<div class="margin--lg"/>
243272
<Tabs
@@ -266,8 +295,13 @@ scala-cli install completions
266295

267296
If any of the `scala-cli install completions` command complained that your shell cannot be determined, specify it
268297
with `--shell`
269-
<Tabs groupId="shell-specific" defaultValue="bash">
270-
<TabItem value="bash">
298+
<Tabs groupId="shell-specific"
299+
defaultValue="bash"
300+
values={[
301+
{label: 'Bash', value: 'bash'},
302+
{label: 'zsh', value: 'zsh'},
303+
]}>
304+
<TabItem value="bash">
271305

272306
```bash
273307
scala-cli install completions --shell bash

website/src/components/DownloadButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DownloadButton extends React.Component {
1515
render() {
1616
return (
1717
<button
18-
style={{height: '55px', width : '190px', fontSize: 15, borderRadius: '3px', color: '#fff', background: '#DC332D', borderColor: '#DC332D', fontWeight: 500 }}
18+
style={{height: '55px', width : this.props.width, fontSize: 15, borderRadius: '3px', color: '#fff', background: '#DC332D', borderColor: '#DC332D', fontWeight: 500 }}
1919
onClick={this.handleClick}
2020
>
2121
{this.props.desc}

0 commit comments

Comments
 (0)