Skip to content

Commit d0a456f

Browse files
committed
update install scripts & ci action
1 parent 8698823 commit d0a456f

File tree

5 files changed

+130
-10
lines changed

5 files changed

+130
-10
lines changed

.github/workflows/install_ci.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# test that install scripts work on all operating systems
2+
# currently only triggered manually, could be added to the main `ci.yaml`
3+
# and use a filter to only run jobs if any scripts under `./scripts/install`
4+
# have been modified.
5+
name: install_ci
6+
7+
on:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macOS-latest]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: tests shell
20+
shell: bash
21+
run: ./scripts/install/install_test.sh
22+
- name: tests powershell
23+
if: matrix.os == 'windows-latest'
24+
shell: powershell
25+
run: ./scripts/install/install_test.ps1
26+
- name: tests powershell core
27+
if: matrix.os == 'windows-latest'
28+
shell: pwsh
29+
run: ./scripts/install/install_test.ps1

scripts/install/install.ps1

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env pwsh
2+
# Inspired by https://github.com/denoland/deno_install
3+
4+
$ErrorActionPreference = 'Stop'
5+
6+
if ($v) {
7+
$Version = "v${v}"
8+
}
9+
if ($Args.Length -eq 1) {
10+
$Version = $Args.Get(0)
11+
}
12+
13+
$ErgomaticInstall = $env:ERGOMATIC_INSTALL
14+
$BinDir = if ($ErgomaticInstall) {
15+
"${ErgomaticInstall}\bin"
16+
} else {
17+
"${Home}\.ergomatic\bin"
18+
}
19+
20+
$ErgomaticExe = "$BinDir\ergomatic.exe"
21+
$Target = 'x86_64-pc-windows-msvc'
22+
23+
$DownloadUrl = if (!$Version) {
24+
"https://github.com/nautls/ergomatic/releases/latest/download/ergomatic-${Target}.exe"
25+
} else {
26+
"https://github.com/nautls/ergomatic/releases/download/${Version}/ergomatic-${Target}.exe"
27+
}
28+
29+
if (!(Test-Path $BinDir)) {
30+
New-Item $BinDir -ItemType Directory | Out-Null
31+
}
32+
33+
curl.exe -Lo $ErgomaticExe $DownloadUrl
34+
35+
$User = [System.EnvironmentVariableTarget]::User
36+
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User)
37+
if (!(";${Path};".ToLower() -like "*;${BinDir};*".ToLower())) {
38+
[System.Environment]::SetEnvironmentVariable('Path', "${Path};${BinDir}", $User)
39+
$Env:Path += ";${BinDir}"
40+
}
41+
42+
Write-Output "Ergomatic was installed successfully to ${ErgomaticExe}"
43+
Write-Output "Run 'ergomatic --help' to get started"
44+
echo "Stuck? Join the Ergo Platform discord https://discord.gg/ergo-platform-668903786361651200"

scripts/install/install.sh

100644100755
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#!/bin/sh
2+
# Inspired by https://github.com/denoland/deno_install
23

34
set -e
45

5-
if ! command -v unzip >/dev/null; then
6-
echo "Error: unzip is required to install Ergomatic" 1>&2
7-
exit 1
8-
fi
9-
106
if [ "$OS" = "Windows_NT" ]; then
117
target="x86_64-pc-windows-msvc"
128
else
@@ -21,10 +17,16 @@ else
2117
esac
2218
fi
2319

20+
if [ "$OS" = "Windows_NT" ]; then
21+
ext=".exe"
22+
else
23+
ext=""
24+
fi
25+
2426
if [ $# -eq 0 ]; then
25-
ergomatic_uri="https://github.com/nautls/ergomatic/releases/latest/download/ergomatic-${target}.zip"
27+
ergomatic_uri="https://github.com/nautls/ergomatic/releases/latest/download/ergomatic-${target}${ext}"
2628
else
27-
ergomatic_uri="https://github.com/nautls/ergomatic/releases/download/${1}/ergomatic-${target}.zip"
29+
ergomatic_uri="https://github.com/nautls/ergomatic/releases/download/${1}/ergomatic-${target}${ext}"
2830
fi
2931

3032
ergomatic_install="${ERGOMATIC_INSTALL:-$HOME/.ergomatic}"
@@ -35,10 +37,8 @@ if [ ! -d "$bin_dir" ]; then
3537
mkdir -p "$bin_dir"
3638
fi
3739

38-
curl --fail --location --progress-bar --output "$exe.zip" "$ergomatic_uri"
39-
unzip -d "$bin_dir" -o "$exe.zip"
40+
curl --fail --location --progress-bar --output "$exe" "$ergomatic_uri"
4041
chmod +x "$exe"
41-
rm "$exe.zip"
4242

4343
echo "Ergomatic was installed successfully to $exe"
4444
if command -v ergomatic >/dev/null; then

scripts/install/install_test.ps1

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env pwsh
2+
3+
$ErrorActionPreference = 'Stop'
4+
5+
# Test that we can install the latest version at the default location.
6+
Remove-Item "~\.ergomatic" -Recurse -Force -ErrorAction SilentlyContinue
7+
$env:ERGOMATIC_INSTALL = ""
8+
$v = $null; .\scripts\install\install.ps1
9+
~\.ergomatic\bin\ergomatic.exe --version
10+
11+
# Test that we can install a specific version at a custom location.
12+
Remove-Item "~\ergomatic-0.0.1" -Recurse -Force -ErrorAction SilentlyContinue
13+
$env:ERGOMATIC_INSTALL = "$Home\ergomatic-0.0.1"
14+
$v = "0.0.1"; .\scripts\install\install.ps1
15+
$ErgomaticVersion = ~\ergomatic-0.0.1\bin\ergomatic.exe --version
16+
if (!($ErgomaticVersion -like '*0.0.1*')) {
17+
throw $ErgomaticVersion
18+
}
19+
20+
# Test that we can install at a relative custom location.
21+
Remove-Item "bin" -Recurse -Force -ErrorAction SilentlyContinue
22+
$env:ERGOMATIC_INSTALL = "."
23+
$v = "0.0.1"; .\install.ps1
24+
$ErgomaticVersion = bin\ergomatic.exe --version
25+
if (!($ErgomaticVersion -like '*0.0.1*')) {
26+
throw $ErgomaticVersion
27+
}

scripts/install/install_test.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Test that we can install the latest version at the default location.
6+
rm -f ~/.ergomatic/bin/ergomatic
7+
unset ERGOMATIC_INSTALL
8+
sh ./scripts/install/install.sh
9+
~/.ergomatic/bin/ergomatic --version
10+
11+
# Test that we can install a specific version at a custom location.
12+
rm -rf ~/ergomatic-0.0.1
13+
export ERGOMATIC_INSTALL="$HOME/ergomatic-0.0.1"
14+
./scripts/install/install.sh v0.0.1
15+
~/ergomatic-0.0.1/bin/ergomatic --version | grep 0.0.1
16+
17+
# Test that we can install at a relative custom location.
18+
export ERGOMATIC_INSTALL="."
19+
./scripts/install/install.sh v0.0.1
20+
bin/ergomatic --version | grep 0.0.1

0 commit comments

Comments
 (0)