Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ lib/**/*
# Ignore Visual Studio Code files
.vscode

# Ignore `dist` folder, it is generated only inside tag's commits
dist

# Ignore coverage folder generated by `c8`
coverage

# Mill binary should only be at repo root, not in dist
dist/mill
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ When it launches it will send PR to update all the repos selected in step (2.2).
# Default: 16384
max-buffer-size: ''

# URL to download the mill wrapper script from.
# If not provided, uses the embedded mill binary.
mill-wrapper-url: ''

# Url to download the coursier linux CLI from.
#
# Default: https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz
Expand Down Expand Up @@ -257,10 +261,8 @@ When it launches it will send PR to update all the repos selected in step (2.2).
# Default: true
ignore-opts-files: ''

# Mill version to install. Take into account this will
# just affect the global `mill` executable. Scala
# Steward will still respect the version specified in
# your repository while updating it.
# Deprecated. This input is no longer used.
# Mill is installed from the embedded binary or mill-wrapper-url.
#
# Default: 1.0.6
mill-version: ''
Expand Down
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ inputs:
in lines. The default is 16384.
default: "16384"
required: false
mill-wrapper-url:
description: |
URL to download the mill wrapper script from.
If not provided, uses the embedded mill binary.
required: false
coursier-cli-url:
description: |
Url to download the coursier linux CLI from.
Expand Down Expand Up @@ -117,12 +122,11 @@ inputs:
required: false
mill-version:
description: |
Mill version to install. Take into account this will
just affect the global `mill` executable. Scala
Steward will still respect the version specified in
your repository while updating it.
Deprecated. This input is no longer used.
Mill is installed from the embedded binary or mill-wrapper-url.
default: "1.0.6"
required: false
deprecated: true
other-args:
description: |
Other Scala Steward arguments not yet supported by
Expand Down
181 changes: 181 additions & 0 deletions mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/usr/bin/env sh

set -e

if [ -z "${DEFAULT_MILL_VERSION}" ] ; then DEFAULT_MILL_VERSION="SNAPSHOT"; fi

if [ -z "${GITHUB_RELEASE_CDN}" ] ; then GITHUB_RELEASE_CDN=""; fi

if [ -z "$MILL_MAIN_CLI" ] ; then MILL_MAIN_CLI="${0}"; fi

MILL_REPO_URL="https://github.com/com-lihaoyi/mill"

MILL_BUILD_SCRIPT=""

if [ -f "build.mill" ] ; then
MILL_BUILD_SCRIPT="build.mill"
elif [ -f "build.mill.scala" ] ; then
MILL_BUILD_SCRIPT="build.mill.scala"
elif [ -f "build.sc" ] ; then
MILL_BUILD_SCRIPT="build.sc"
fi

# `s/.*://`:
# This is a greedy match that removes everything from the beginning of the line up to (and including) the last
# colon (:). This effectively isolates the value part of the declaration.
#
# `s/#.*//`:
# This removes any comments at the end of the line.
#
# `s/['\"]//g`:
# This removes all single and double quotes from the string, wherever they appear (g is for "global").
#
# `s/^[[:space:]]*//; s/[[:space:]]*$//`:
# These two expressions trim any leading or trailing whitespace ([[:space:]] matches spaces and tabs).
TRIM_VALUE_SED="s/.*://; s/#.*//; s/['\"]//g; s/^[[:space:]]*//; s/[[:space:]]*$//"

if [ -z "${MILL_VERSION}" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(tr '\r' '\n' < .mill-version | head -n 1 2> /dev/null)"
elif [ -f ".config/mill-version" ] ; then
MILL_VERSION="$(tr '\r' '\n' < .config/mill-version | head -n 1 2> /dev/null)"
elif [ -f "build.mill.yaml" ] ; then
MILL_VERSION="$(grep -E "mill-version:" "build.mill.yaml" | sed -E "$TRIM_VALUE_SED")"
elif [ -n "${MILL_BUILD_SCRIPT}" ] ; then
MILL_VERSION="$(grep -E "//\|.*mill-version" "${MILL_BUILD_SCRIPT}" | sed -E "$TRIM_VALUE_SED")"
fi
fi

if [ -z "${MILL_VERSION}" ] ; then MILL_VERSION="${DEFAULT_MILL_VERSION}"; fi

MILL_USER_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/mill"

if [ -z "${MILL_FINAL_DOWNLOAD_FOLDER}" ] ; then MILL_FINAL_DOWNLOAD_FOLDER="${MILL_USER_CACHE_DIR}/download"; fi

MILL_NATIVE_SUFFIX="-native"
MILL_JVM_SUFFIX="-jvm"
FULL_MILL_VERSION=$MILL_VERSION
ARTIFACT_SUFFIX=""
set_artifact_suffix(){
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" = "Linux" ]; then
if [ "$(uname -m)" = "aarch64" ]; then ARTIFACT_SUFFIX="-native-linux-aarch64"
else ARTIFACT_SUFFIX="-native-linux-amd64"; fi
elif [ "$(uname)" = "Darwin" ]; then
if [ "$(uname -m)" = "arm64" ]; then ARTIFACT_SUFFIX="-native-mac-aarch64"
else ARTIFACT_SUFFIX="-native-mac-amd64"; fi
else
echo "This native mill launcher supports only Linux and macOS." 1>&2
exit 1
fi
}

case "$MILL_VERSION" in
*"$MILL_NATIVE_SUFFIX")
MILL_VERSION=${MILL_VERSION%"$MILL_NATIVE_SUFFIX"}
set_artifact_suffix
;;

*"$MILL_JVM_SUFFIX")
MILL_VERSION=${MILL_VERSION%"$MILL_JVM_SUFFIX"}
;;

*)
case "$MILL_VERSION" in
0.1.*) ;;
0.2.*) ;;
0.3.*) ;;
0.4.*) ;;
0.5.*) ;;
0.6.*) ;;
0.7.*) ;;
0.8.*) ;;
0.9.*) ;;
0.10.*) ;;
0.11.*) ;;
0.12.*) ;;
*)
set_artifact_suffix
esac
;;
esac

MILL="${MILL_FINAL_DOWNLOAD_FOLDER}/$MILL_VERSION$ARTIFACT_SUFFIX"

# If not already downloaded, download it
if [ ! -s "${MILL}" ] || [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
case $MILL_VERSION in
0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
MILL_DOWNLOAD_SUFFIX=""
MILL_DOWNLOAD_FROM_MAVEN=0
;;
0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
MILL_DOWNLOAD_SUFFIX="-assembly"
MILL_DOWNLOAD_FROM_MAVEN=0
;;
*)
MILL_DOWNLOAD_SUFFIX="-assembly"
MILL_DOWNLOAD_FROM_MAVEN=1
;;
esac
case $MILL_VERSION in
0.12.0 | 0.12.1 | 0.12.2 | 0.12.3 | 0.12.4 | 0.12.5 | 0.12.6 | 0.12.7 | 0.12.8 | 0.12.9 | 0.12.10 | 0.12.11 )
MILL_DOWNLOAD_EXT="jar"
;;
0.12.* )
MILL_DOWNLOAD_EXT="exe"
;;
0.* )
MILL_DOWNLOAD_EXT="jar"
;;
*)
MILL_DOWNLOAD_EXT="exe"
;;
esac

MILL_TEMP_DOWNLOAD_FILE="${MILL_OUTPUT_DIR:-out}/mill-temp-download"
mkdir -p "$(dirname "${MILL_TEMP_DOWNLOAD_FILE}")"

if [ "$MILL_DOWNLOAD_FROM_MAVEN" = "1" ] ; then
MILL_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist${ARTIFACT_SUFFIX}/${MILL_VERSION}/mill-dist${ARTIFACT_SUFFIX}-${MILL_VERSION}.${MILL_DOWNLOAD_EXT}"
else
MILL_VERSION_TAG=$(echo "$MILL_VERSION" | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="${GITHUB_RELEASE_CDN}${MILL_REPO_URL}/releases/download/${MILL_VERSION_TAG}/${MILL_VERSION}${MILL_DOWNLOAD_SUFFIX}"
unset MILL_VERSION_TAG
fi


if [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
echo $MILL_DOWNLOAD_URL
echo $MILL
exit 0
fi

echo "Downloading mill ${MILL_VERSION} from ${MILL_DOWNLOAD_URL} ..." 1>&2
curl -f -L -o "${MILL_TEMP_DOWNLOAD_FILE}" "${MILL_DOWNLOAD_URL}"

chmod +x "${MILL_TEMP_DOWNLOAD_FILE}"

mkdir -p "${MILL_FINAL_DOWNLOAD_FOLDER}"
mv "${MILL_TEMP_DOWNLOAD_FILE}" "${MILL}"

unset MILL_TEMP_DOWNLOAD_FILE
unset MILL_DOWNLOAD_SUFFIX
fi

MILL_FIRST_ARG=""
if [ "$1" = "--bsp" ] || [ "${1#"-i"}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--no-daemon" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
# Need to preserve the first position of those listed options
MILL_FIRST_ARG=$1
shift
fi

unset MILL_FINAL_DOWNLOAD_FOLDER
unset MILL_OLD_DOWNLOAD_PATH
unset OLD_MILL
unset MILL_VERSION
unset MILL_REPO_URL

# -D mill.main.cli is for compatibility with Mill 0.10.9 - 0.13.0-M2
# We don't quote MILL_FIRST_ARG on purpose, so we can expand the empty value without quotes
# shellcheck disable=SC2086
exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"type": "module",
"scripts": {
"build": "npm run build-pre && npm run build-main && npm run build-post",
"build-pre": "ncc build --target es2022 src/action/pre.ts && mv dist/index.js dist/pre.js",
"build-pre": "ncc build --target es2022 src/action/pre.ts && mv dist/index.js dist/pre.js && rm -f dist/mill",
"build-main": "ncc build --target es2022 src/action/main.ts && mv dist/index.js dist/main.js",
"build-post": "ncc build --target es2022 src/action/post.ts && mv dist/index.js dist/post.js",
"build-post": "ncc build --target es2022 src/action/post.ts && mv dist/index.js dist/post.js && rm -f dist/mill",
"docs": "node --loader ts-node/esm src/utils/docs.ts && markdown-toc-gen update README.md",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
Expand Down
12 changes: 7 additions & 5 deletions src/action/pre.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import * as core from '@actions/core'
import fetch from 'node-fetch'
import * as coursier from '../modules/coursier'
import {HealthCheck} from '../modules/healthcheck'
import * as mill from '../modules/mill'
import {HealthCheck} from '../modules/healthcheck'

/**
* Runs the action prerequisites code. In order it will do the following:
*
* - Check connection with Maven Central
* - Install Coursier
* - Install Scalafmt
* - Install Scalafix
* - Install Mill
* - Install Mill (embedded or from mill-wrapper-url)
* - Install scalafmt
* - Install scalafix
* - Install scala-cli
* - Install sbt
*/
async function run(): Promise<void> {
try {
const healthCheck: HealthCheck = HealthCheck.from(core, {run: async url => fetch(url)})
await healthCheck.mavenCentral()

await coursier.install()
await mill.install()
await mill.install(core.getInput('mill-wrapper-url') || undefined)
} catch (error: unknown) {
core.setFailed(` ✕ ${(error as Error).message}`)
}
Expand Down
8 changes: 8 additions & 0 deletions src/modules/mill.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {existsSync} from 'fs'
import test from 'ava'
import {getBundledMillPath} from './mill'

test('`getBundledMillPath()` → returns path where mill binary exists', t => {
const millPath = getBundledMillPath()
t.true(existsSync(millPath))
})
Loading