Skip to content

Commit fb4a8ca

Browse files
Initial commit
0 parents  commit fb4a8ca

File tree

7 files changed

+322
-0
lines changed

7 files changed

+322
-0
lines changed

Diff for: .github/workflows/launchers.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Launchers
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
generate-launchers:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest, windows-2016, macos-latest]
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
submodules: true
19+
- uses: coursier/[email protected]
20+
- uses: coursier/setup-action@v1
21+
with:
22+
jvm: 8
23+
- run: |
24+
./mill -i "native.writeNativeImageScript" generate.sh && \
25+
./generate.sh && \
26+
./mill -i "native.copyToArtifacts" artifacts/
27+
if: runner.os != 'Windows'
28+
- run: |
29+
@call ./mill.bat -i "native.writeNativeImageScript" generate.bat
30+
@call generate.bat
31+
@call ./mill.bat -i "native.copyToArtifacts" artifacts/
32+
shell: cmd
33+
if: runner.os == 'Windows'
34+
- uses: actions/[email protected]
35+
with:
36+
name: launcher-${{ matrix.os }}
37+
path: artifacts/
38+
if-no-files-found: error
39+
retention-days: 1
40+
- run: ./mill -i upload artifacts/
41+
if: github.event_name == 'push'
42+
env:
43+
UPLOAD_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out/

Diff for: .mill-jvm-opts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-Xmx256m
2+
-Xms128m

Diff for: .mill-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.9.8

Diff for: build.sc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import $ivy.`io.github.alexarchambault.mill::mill-native-image_mill0.9:0.1.10`
2+
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.10`
3+
4+
import io.github.alexarchambault.millnativeimage.NativeImage
5+
import io.github.alexarchambault.millnativeimage.upload.Upload
6+
import mill._
7+
import mill.scalalib._
8+
9+
def scalafmtVersion = "3.0.0"
10+
11+
object native extends ScalaModule with NativeImage {
12+
def scalaVersion = "2.13.6"
13+
def nativeImagePersist = System.getenv("CI") != null
14+
def nativeImageGraalVmJvmId = "graalvm-java11:21.2.0"
15+
def nativeImageName = "scalafmt"
16+
def ivyDeps = super.ivyDeps() ++ Seq(
17+
ivy"org.scalameta::scalafmt-cli:$scalafmtVersion"
18+
)
19+
def nativeImageClassPath = T{
20+
runClasspath()
21+
}
22+
def nativeImageMainClass = "org.scalafmt.cli.Cli"
23+
24+
def copyToArtifacts(directory: String = "artifacts/") = T.command {
25+
val _ = Upload.copyLauncher(
26+
nativeImage().path,
27+
directory,
28+
s"scalafmt-$scalafmtVersion",
29+
compress = true
30+
)
31+
}
32+
}
33+
34+
def upload(directory: String = "artifacts/") = T.command {
35+
val version = scalafmtVersion
36+
37+
val path = os.Path(directory, os.pwd)
38+
val launchers = os.list(path).filter(os.isFile(_)).map { path =>
39+
path.toNIO -> path.last
40+
}
41+
val ghToken = Option(System.getenv("UPLOAD_GH_TOKEN")).getOrElse {
42+
sys.error("UPLOAD_GH_TOKEN not set")
43+
}
44+
val (tag, overwriteAssets) = ("launchers", false)
45+
Upload.upload("alexarchambault", "scalafmt-native-image", ghToken, tag, dryRun = false, overwrite = overwriteAssets)(launchers: _*)
46+
}

Diff for: mill

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env sh
2+
3+
# This is a wrapper script, that automatically download mill from GitHub release pages
4+
# You can give the required mill version with --mill-version parameter
5+
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
6+
#
7+
# Project page: https://github.com/lefou/millw
8+
#
9+
# If you want to improve this script, please also contribute your changes back!
10+
#
11+
# Licensed under the Apache License, Version 2.0
12+
13+
14+
DEFAULT_MILL_VERSION=0.9.5
15+
16+
set -e
17+
18+
MILL_REPO_URL="https://github.com/com-lihaoyi/mill"
19+
20+
# Explicit commandline argument takes precedence over all other methods
21+
if [ "x$1" = "x--mill-version" ] ; then
22+
shift
23+
if [ "x$1" != "x" ] ; then
24+
MILL_VERSION="$1"
25+
shift
26+
else
27+
echo "You specified --mill-version without a version."
28+
echo "Please provide a version that matches one provided on"
29+
echo "${MILL_REPO_URL}/releases"
30+
false
31+
fi
32+
fi
33+
34+
# Please note, that if a MILL_VERSION is already set in the environment,
35+
# We reuse it's value and skip searching for a value.
36+
37+
# If not already set, read .mill-version file
38+
if [ "x${MILL_VERSION}" = "x" ] ; then
39+
if [ -f ".mill-version" ] ; then
40+
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
41+
fi
42+
fi
43+
44+
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
45+
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
46+
else
47+
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
48+
fi
49+
50+
# If not already set, try to fetch newest from Github
51+
if [ "x${MILL_VERSION}" = "x" ] ; then
52+
# TODO: try to load latest version from release page
53+
echo "No mill version specified."
54+
echo "You should provide a version via '.mill-version' file or --mill-version option."
55+
56+
mkdir -p "${MILL_DOWNLOAD_PATH}"
57+
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
58+
if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
59+
# we know a current latest version
60+
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
61+
fi
62+
63+
if [ "x${MILL_VERSION}" = "x" ] ; then
64+
# we don't know a current latest version
65+
echo "Retrieving latest mill version ..."
66+
LANG=C curl -s -i -f -I ${MILL_REPO_URL}/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest"
67+
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
68+
fi
69+
70+
if [ "x${MILL_VERSION}" = "x" ] ; then
71+
# Last resort
72+
MILL_VERSION="${DEFAULT_MILL_VERSION}"
73+
echo "Falling back to hardcoded mill version ${MILL_VERSION}"
74+
else
75+
echo "Using mill version ${MILL_VERSION}"
76+
fi
77+
fi
78+
79+
MILL="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"
80+
81+
# If not already downloaded, download it
82+
if [ ! -s "${MILL}" ] ; then
83+
84+
# support old non-XDG download dir
85+
MILL_OLD_DOWNLOAD_PATH="${HOME}/.mill/download"
86+
OLD_MILL="${MILL_OLD_DOWNLOAD_PATH}/${MILL_VERSION}"
87+
if [ -x "${OLD_MILL}" ] ; then
88+
MILL="${OLD_MILL}"
89+
else
90+
VERSION_PREFIX="$(echo -n $MILL_VERSION | cut -b -4)"
91+
case $VERSION_PREFIX in
92+
0.0. | 0.1. | 0.2. | 0.3. | 0.4. )
93+
DOWNLOAD_SUFFIX=""
94+
;;
95+
*)
96+
DOWNLOAD_SUFFIX="-assembly"
97+
;;
98+
esac
99+
unset VERSION_PREFIX
100+
101+
DOWNLOAD_FILE=$(mktemp mill.XXXX)
102+
# TODO: handle command not found
103+
echo "Downloading mill ${MILL_VERSION} from ${MILL_REPO_URL}/releases ..."
104+
curl -L -o "${DOWNLOAD_FILE}" "${MILL_REPO_URL}/releases/download/${MILL_VERSION%%-*}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
105+
chmod +x "${DOWNLOAD_FILE}"
106+
mkdir -p "${MILL_DOWNLOAD_PATH}"
107+
mv "${DOWNLOAD_FILE}" "${MILL}"
108+
109+
unset DOWNLOAD_FILE
110+
unset DOWNLOAD_SUFFIX
111+
fi
112+
fi
113+
114+
unset MILL_DOWNLOAD_PATH
115+
unset MILL_OLD_DOWNLOAD_PATH
116+
unset OLD_MILL
117+
unset MILL_VERSION
118+
unset MILL_REPO_URL
119+
120+
exec $MILL "$@"

Diff for: mill.bat

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
@echo off
2+
3+
rem This is a wrapper script, that automatically download mill from GitHub release pages
4+
rem You can give the required mill version with --mill-version parameter
5+
rem If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
6+
rem
7+
rem Project page: https://github.com/lefou/millw
8+
rem
9+
rem If you want to improve this script, please also contribute your changes back!
10+
rem
11+
rem Licensed under the Apache License, Version 2.0
12+
13+
rem setlocal seems to be unavailable on Windows 95/98/ME
14+
rem but I don't think we need to support them in 2019
15+
setlocal enabledelayedexpansion
16+
17+
set "DEFAULT_MILL_VERSION=0.9.5"
18+
19+
set "MILL_REPO_URL=https://github.com/com-lihaoyi/mill"
20+
21+
rem %~1% removes surrounding quotes
22+
if [%~1%]==[--mill-version] (
23+
rem shift command doesn't work within parentheses
24+
if not [%~2%]==[] (
25+
set MILL_VERSION=%~2%
26+
set "STRIP_VERSION_PARAMS=true"
27+
) else (
28+
echo You specified --mill-version without a version.
29+
echo Please provide a version that matches one provided on
30+
echo %MILL_REPO_URL%/releases
31+
exit /b 1
32+
)
33+
)
34+
35+
if [!MILL_VERSION!]==[] (
36+
if exist .mill-version (
37+
set /p MILL_VERSION=<.mill-version
38+
)
39+
)
40+
41+
if [!MILL_VERSION!]==[] (
42+
set MILL_VERSION=%DEFAULT_MILL_VERSION%
43+
)
44+
45+
set MILL_DOWNLOAD_PATH=%USERPROFILE%\.mill\download
46+
47+
rem without bat file extension, cmd doesn't seem to be able to run it
48+
set MILL=%MILL_DOWNLOAD_PATH%\!MILL_VERSION!.bat
49+
50+
if not exist "%MILL%" (
51+
set VERSION_PREFIX=%MILL_VERSION:~0,4%
52+
set DOWNLOAD_SUFFIX=-assembly
53+
if [!VERSION_PREFIX!]==[0.0.] set DOWNLOAD_SUFFIX=
54+
if [!VERSION_PREFIX!]==[0.1.] set DOWNLOAD_SUFFIX=
55+
if [!VERSION_PREFIX!]==[0.2.] set DOWNLOAD_SUFFIX=
56+
if [!VERSION_PREFIX!]==[0.3.] set DOWNLOAD_SUFFIX=
57+
if [!VERSION_PREFIX!]==[0.4.] set DOWNLOAD_SUFFIX=
58+
set VERSION_PREFIX=
59+
60+
for /F "delims=-" %%A in ("!MILL_VERSION!") do (
61+
set MILL_BASE_VERSION=%%A
62+
)
63+
64+
rem there seems to be no way to generate a unique temporary file path (on native Windows)
65+
set DOWNLOAD_FILE=%MILL%.tmp
66+
67+
set DOWNLOAD_URL=%MILL_REPO_URL%/releases/download/!MILL_BASE_VERSION!/!MILL_VERSION!!DOWNLOAD_SUFFIX!
68+
69+
echo Downloading mill %MILL_VERSION% from %MILL_REPO_URL%/releases ...
70+
71+
if not exist "%MILL_DOWNLOAD_PATH%" mkdir "%MILL_DOWNLOAD_PATH%"
72+
rem curl is bundled with recent Windows 10
73+
rem but I don't think we can expect all the users to have it in 2019
74+
where /Q curl
75+
if %ERRORLEVEL% EQU 0 (
76+
curl -L "!DOWNLOAD_URL!" -o "!DOWNLOAD_FILE!"
77+
) else (
78+
rem bitsadmin seems to be available on Windows 7
79+
rem without /dynamic, github returns 403
80+
rem bitsadmin is sometimes needlessly slow but it looks better with /priority foreground
81+
bitsadmin /transfer millDownloadJob /dynamic /priority foreground "!DOWNLOAD_URL!" "!DOWNLOAD_FILE!"
82+
)
83+
if not exist "!DOWNLOAD_FILE!" (
84+
echo Could not download mill %MILL_VERSION%
85+
exit /b 1
86+
)
87+
88+
move /y "!DOWNLOAD_FILE!" "%MILL%"
89+
90+
set DOWNLOAD_FILE=
91+
set DOWNLOAD_SUFFIX=
92+
)
93+
94+
set MILL_DOWNLOAD_PATH=
95+
set MILL_VERSION=
96+
set MILL_REPO_URL=
97+
98+
set MILL_PARAMS=%*
99+
100+
if defined STRIP_VERSION_PARAMS (
101+
for /f "tokens=1-2*" %%a in ("%*") do (
102+
rem strip %%a - It's the "--mill-version" option.
103+
rem strip %%b - it's the version number that comes after the option.
104+
rem keep %%c - It's the remaining options.
105+
set MILL_PARAMS=%%c
106+
)
107+
)
108+
109+
"%MILL%" %MILL_PARAMS%

0 commit comments

Comments
 (0)