1
+ # This is a wrapper script, that automatically download mill from GitHub release pages
2
+ # You can give the required mill version with --mill-version parameter
3
+ # If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
4
+ #
5
+ # Project page: https://github.com/lefou/millw
6
+ # Script Version: 0.4.12
7
+ #
8
+ # If you want to improve this script, please also contribute your changes back!
9
+ #
10
+ # Licensed under the Apache License, Version 2.0
11
+
12
+ [CmdletBinding (PositionalBinding = $false )]
13
+
14
+ param (
15
+ [Parameter (ValueFromRemainingArguments = $true , Position = 0 )]
16
+ [string []] $remainingArgs
17
+ )
18
+
19
+ $DEFAULT_MILL_VERSION = $Env: DEFAULT_MILL_VERSION ?? ' 0.11.6'
20
+
21
+ $GITHUB_RELEASE_CDN = $Env: GITHUB_RELEASE_CDN ?? ' '
22
+
23
+ $MILL_REPO_URL = ' https://github.com/com-lihaoyi/mill'
24
+
25
+ $MILL_VERSION = $null
26
+
27
+ if ($null -ne $remainingArgs ) {
28
+ if ($remainingArgs [0 ] -eq ' --mill-version' ) {
29
+ $remainingArgs = Select-Object - InputObject $remainingArgs - Skip 1
30
+ if ($null -ne $remainingArgs ) {
31
+ $MILL_VERSION = $remainingArgs [0 ]
32
+ $remainingArgs = Select-Object - InputObject $remainingArgs - Skip 1
33
+ }
34
+ else {
35
+ Write-Error - Message " Please provide a version that matches one provided on $MILL_REPO_URL /releases"
36
+ throw [System.ArgumentNullException ] ' --mill-version'
37
+ }
38
+ }
39
+ }
40
+
41
+ if ($null -eq $MILL_VERSION ) {
42
+ if (Test-Path - Path ' .mill-version' - PathType Leaf) {
43
+ $MILL_VERSION = Get-Content - Path ' .mill-version' - TotalCount 1
44
+ }
45
+ elseif (Test-Path - Path ' .config/mill-version' - PathType Leaf) {
46
+ $MILL_VERSION = Get-Content - Path ' .config/mill-version' - TotalCount 1
47
+ }
48
+ }
49
+
50
+ $MILL_USER_CACHE_DIR = Join-Path - Path $Env: LOCALAPPDATA - ChildPath ' mill'
51
+
52
+ $MILL_DOWNLOAD_PATH = $Env: MILL_DOWNLOAD_PATH ?? @ (Join-Path - Path ${MILL_USER_CACHE_DIR} - ChildPath ' download' )
53
+
54
+ if (-not (Test-Path - Path $MILL_DOWNLOAD_PATH )) {
55
+ New-Item - Path $MILL_DOWNLOAD_PATH - ItemType Directory | Out-Null
56
+ }
57
+
58
+ if ($null -eq $MILL_VERSION ) {
59
+ Write-Warning - Message ' No mill version specified.'
60
+ Write-Warning - Message " You should provide a version via '.mill-version' file or --mill-version option."
61
+
62
+ if (-not (Test-Path - Path " $MILL_DOWNLOAD_PATH " - PathType Container)) {
63
+ New-Item " $MILL_DOWNLOAD_PATH " - ItemType Directory | Out-Null
64
+ }
65
+
66
+ $MILL_LATEST_PATH = Join-Path - Path $MILL_DOWNLOAD_PATH - ChildPath ' .latest'
67
+
68
+ if (Test-Path - Path $MILL_LATEST_PATH - PathType Leaf) {
69
+ if ($ (Get-Item - Path $MILL_LATEST_PATH ).LastWriteTime -lt $ (Get-Date ).AddHours(-1 )) {
70
+ $MILL_VERSION = Get-Content - Path $MILL_LATEST_PATH - TotalCount 1
71
+ }
72
+ }
73
+
74
+ if ($null -eq $MILL_VERSION ) {
75
+ Write-Output ' Retrieving latest mill version ...'
76
+
77
+ # https://github.com/PowerShell/PowerShell/issues/20964
78
+ $targetUrl = try {
79
+ Invoke-WebRequest - Uri " $MILL_REPO_URL /releases/latest" - MaximumRedirection 0
80
+ }
81
+ catch {
82
+ $_.Exception.Response.Headers.Location.AbsoluteUri
83
+ }
84
+
85
+ $targetUrl -match " ^$MILL_REPO_URL /releases/tag/(.+)$" | Out-Null
86
+
87
+ $MILL_VERSION = $Matches.1
88
+
89
+ if ($null -ne $MILL_VERSION ) {
90
+ Set-Content - Path $MILL_LATEST_PATH - Value $MILL_VERSION
91
+ }
92
+ }
93
+
94
+ if ($null -eq $MILL_VERSION ) {
95
+ $MILL_VERSION = $DEFAULT_MILL_VERSION
96
+ Write-Warning " Falling back to hardcoded mill version $MILL_VERSION "
97
+ }
98
+ else {
99
+ Write-Output " Using mill version $MILL_VERSION "
100
+ }
101
+ }
102
+
103
+ $MILL = " $MILL_DOWNLOAD_PATH /$MILL_VERSION .bat"
104
+
105
+ if (-not (Test-Path - Path $MILL - PathType Leaf)) {
106
+ $DOWNLOAD_SUFFIX , $DOWNLOAD_FROM_MAVEN = switch - Regex ($MILL_VERSION ) {
107
+ ' ^0\.[0-4]\..*$' { ' ' , $false }
108
+ ' 0\.(?:[5-9]\.|10\.|11\.0-M).*' { ' -assembly' , $false }
109
+ Default { ' -assembly' , $true }
110
+ }
111
+
112
+ if ($DOWNLOAD_FROM_MAVEN ) {
113
+ $DOWNLOAD_URL = " https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/$MILL_VERSION /mill-dist-$MILL_VERSION .jar"
114
+ }
115
+ else {
116
+ $MILL_VERSION -match ' (\d+\.\d+\.\d+(?:-M\d+)?)' | Out-Null
117
+ $MILL_VERSION_TAG = $Matches.1
118
+ $DOWNLOAD_URL = " $GITHUB_RELEASE_CDN$MILL_REPO_URL /releases/download/$MILL_VERSION_TAG /$MILL_VERSION$DOWNLOAD_SUFFIX "
119
+ }
120
+ Write-Output " Downloading mill $MILL_VERSION from $DOWNLOAD_URL ..."
121
+
122
+ Invoke-WebRequest - Uri $DOWNLOAD_URL - OutFile $MILL
123
+ }
124
+
125
+ $MILL_MAIN_CLI = $Env: MILL_MAIN_CLI ?? $PSCommandPath
126
+
127
+ $MILL_FIRST_ARG = $null
128
+ $REMAINING_ARGUMENTS = $remainingArgs
129
+
130
+ if ($null -ne $remainingArgs ) {
131
+ if ($remainingArgs [0 ] -eq ' --bsp' -or $remainingArgs -eq ' -i' -or $remainingArgs -eq ' --interactive' -or $remainingArgs -eq ' --no-server' ) {
132
+ $MILL_FIRST_ARG = $remainingArgs [0 ]
133
+ $REMAINING_ARGUMENTS = Select-Object - InputObject $remainingArgs - Skip 1
134
+ }
135
+ }
136
+
137
+ & $MILL $MILL_FIRST_ARG - D " mill.main.cli=$MILL_MAIN_CLI " $REMAINING_ARGUMENTS
0 commit comments