Add caching for the Mill build tool

This commit is contained in:
clintval 2025-05-05 12:15:38 -10:00
commit 18d114c65a
No known key found for this signature in database
9 changed files with 214 additions and 7 deletions

View file

@ -201,6 +201,48 @@ describe('dependency cache', () => {
expect(firstCall).not.toBe(thirdCall);
});
});
describe('for mill', () => {
it('throws error if no build.sc found', async () => {
await expect(restore('mill', '')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/build.sc,**/*.sc,**/mill,**/.mill-version,**/.config/mill-version], make sure you have checked out the target repository`
);
});
it('downloads cache', async () => {
createFile(join(workspace, 'build.sc'));
await restore('mill', '');
expect(spyCacheRestore).toHaveBeenCalled();
expect(spyGlobHashFiles).toHaveBeenCalledWith(
'**/build.sc\n**/*.sc\n**/mill\n**/.mill-version\n**/.config/mill-version'
);
expect(spyWarning).not.toHaveBeenCalled();
expect(spyInfo).toHaveBeenCalledWith('mill cache is not found');
});
it('detects scala and mill changes under **/mill-build/ folder', async () => {
createFile(join(workspace, 'build.sc'));
createDirectory(join(workspace, 'project'));
createFile(join(workspace, '.config/mill-version'));
await restore('mill', '');
const firstCall = spySaveState.mock.calls.toString();
spySaveState.mockClear();
await restore('mill', '');
const secondCall = spySaveState.mock.calls.toString();
// Make sure multiple restores produce the same cache
expect(firstCall).toBe(secondCall);
spySaveState.mockClear();
createFile(join(workspace, '.mill-version'));
await restore('mill', '');
const thirdCall = spySaveState.mock.calls.toString();
expect(firstCall).not.toBe(thirdCall);
});
});
it('downloads cache based on versions.properties', async () => {
createFile(join(workspace, 'versions.properties'));

1
__tests__/cache/mill/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
out/

1
__tests__/cache/mill/.mill-version vendored Normal file
View file

@ -0,0 +1 @@
0.12.3

12
__tests__/cache/mill/build.sc vendored Normal file
View file

@ -0,0 +1,12 @@
package build
import mill._, scalalib._
object MyProject extends ScalaModule {
def scalaVersion = "2.13.11"
def ivyDeps = Agg(ivy"com.lihaoyi::mainargs:0.6.2")
object test extends ScalaTests {
def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.8.5")
def testFramework = "utest.runner.Framework"
}
}

26
__tests__/cache/mill/mill vendored Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env sh
# This is a wrapper script that automatically downloads Mill from GitHub.
set -e
if [ -z "$MILL_VERSION" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
fi
MILL_DOWNLOAD_PATH="$HOME/.cache/mill/download"
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION"
if [ ! -x "$MILL_EXEC_PATH" ] ; then
mkdir -p "${MILL_DOWNLOAD_PATH}"
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION-assembly"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
unset DOWNLOAD_FILE
unset MILL_DOWNLOAD_URL
fi
unset MILL_DOWNLOAD_PATH
unset MILL_VERSION
exec "${MILL_EXEC_PATH}" "$@"