Skip to content

Commit

Permalink
new: Update proto install script to support new shim file. (#1238)
Browse files Browse the repository at this point in the history
* Update bash.

* Update pwsh.

* Update pr.
  • Loading branch information
milesj authored Dec 19, 2023
1 parent 24ff692 commit b6c153d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: PR
on:
pull_request:
# env:
# MOON_DEBUG: 'true'
# PROTO_DEBUG: 'true'
env:
MOON_DEBUG: 'true'
PROTO_DEBUG: 'true'
jobs:
version:
name: Version check
Expand Down Expand Up @@ -45,6 +45,8 @@ jobs:
if: ${{ runner.os != 'Windows' }}
- run: bash ./website/static/install/proto.sh 0.19.0
if: ${{ runner.os != 'Windows' }}
- run: bash ./website/static/install/proto.sh 0.26.0-rc.1
if: ${{ runner.os != 'Windows' }}
# Windows
- run: pwsh.exe ./website/static/install/moon.ps1
if: ${{ runner.os == 'Windows' }}
Expand All @@ -54,3 +56,5 @@ jobs:
if: ${{ runner.os == 'Windows' }}
- run: pwsh.exe ./website/static/install/proto.ps1 0.19.0
if: ${{ runner.os == 'Windows' }}
- run: pwsh.exe ./website/static/install/proto.ps1 0.26.0-rc.1
if: ${{ runner.os == 'Windows' }}
8 changes: 7 additions & 1 deletion website/static/install/proto.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ $InstallDir = if ($env:PROTO_INSTALL_DIR) {
}

$BinPath = "${InstallDir}\proto.exe"
$ShimPath = "${InstallDir}\proto-shim.exe"

# Download and unpack in temp dir

if (!(Test-Path $TempDir)) {
New-Item $TempDir -ItemType Directory | Out-Null
}

# curl.exe -Lo $DownloadFile $DownloadUrl
$wc = New-Object Net.Webclient
$wc.downloadFile($DownloadUrl, $DownloadFile)

Expand All @@ -53,6 +53,11 @@ if (!(Test-Path $InstallDir)) {
}

Copy-Item "${TempDir}\proto.exe" -Destination $BinPath -Force

if (Test-Path "${TempDir}\proto-shim.exe") {
Copy-Item "${TempDir}\proto-shim.exe" -Destination $ShimPath -Force
}

Remove-Item $TempDir -Recurse -Force
Remove-Item $DownloadFile -Force

Expand All @@ -71,4 +76,5 @@ if ($env:PROTO_DEBUG -eq "true") {
Write-Output "target=${Target}"
Write-Output "download_url=${DownloadUrl}"
Write-Output "bin_path=${BinPath}"
Write-Output "shim_path=${ShimPath}"
}
18 changes: 14 additions & 4 deletions website/static/install/proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
set -eo pipefail

bin="proto"
shim_bin="proto-shim"
arch=$(uname -sm)
version="${1:-latest}"
ext=".tar.xz"

if [[ "$OS" == "Windows_NT" ]]; then
target="proto_cli-x86_64-pc-windows-msvc"
bin="proto.exe"
shim_bin="proto-shim.exe"
ext=".zip"
else
case "$arch" in
Expand Down Expand Up @@ -54,17 +56,18 @@ fi
temp_dir="$HOME/.proto/temp/proto/$target"
download_file="$temp_dir$ext"

if [ -z "$PROTO_INSTALL_DIR" ]; then
if [[ -z "$PROTO_INSTALL_DIR" ]]; then
install_dir="$HOME/.proto/bin"
else
install_dir="$PROTO_INSTALL_DIR"
fi

bin_path="$install_dir/$bin"
shim_path="$install_dir/$shim_bin"

# Download and unpack in temp dir

if [ ! -d "$temp_dir" ]; then
if [[ ! -d "$temp_dir" ]]; then
mkdir -p "$temp_dir"
fi

Expand All @@ -81,20 +84,26 @@ fi

# Move to bin dir and clean up

if [ ! -d "$install_dir" ]; then
if [[ ! -d "$install_dir" ]]; then
mkdir -p "$install_dir"
fi

mv "$temp_dir/$bin" "$bin_path"
chmod +x "$bin_path"

if [[ -f "$temp_dir/$shim_bin" ]]; then
mv "$temp_dir/$shim_bin" "$shim_path"
chmod +x "$shim_path"
fi

rm -rf "$download_file" "$temp_dir"

# Run setup script to update shells

export PROTO_LOG=error
profile_path=$($bin_path setup --profile)

if [ -z "$profile_path" ]; then
if [[ -z "$profile_path" ]]; then
echo "Successfully installed proto to $bin_path"
else
echo "Successfully installed proto to $bin_path and updated $profile_path"
Expand All @@ -110,6 +119,7 @@ if [[ "$PROTO_DEBUG" == "true" ]]; then
echo "target=$target"
echo "download_url=$download_url"
echo "bin_path=$bin_path"
echo "shim_path=$shim_path"
echo "is_wsl=$is_wsl"
echo "deps=$deps"
fi

0 comments on commit b6c153d

Please sign in to comment.