Improve install script (#847)

- Allow passing `--target` to select target
- Guess target from OS and architecture
This commit is contained in:
Casey Rodarmor 2021-05-27 23:16:45 -07:00 committed by GitHub
parent 98c8911f85
commit acc7494268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 33 deletions

View File

@ -10,6 +10,10 @@ on:
branches:
- master
defaults:
run:
shell: bash
jobs:
all:
name: All
@ -118,6 +122,22 @@ jobs:
sudo apt-get install ripgrep
./bin/forbid
- name: Test Install Script With Explicit Target
if: matrix.os != 'windows-2016'
run: |
cd `mktemp -d`
cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --target ${{ matrix.target }} --to .
if [[ ${{ matrix.native }} == true ]]; then
./just --version
fi
- name: Test Install Script Without Explicit Target
if: matrix.os != 'windows-2016'
run: |
cd `mktemp -d`
cat $GITHUB_WORKSPACE/docs/install.sh | bash -s -- --to .
./just --version
- name: Package
id: package
if: startsWith(github.ref, 'refs/tags/')

View File

@ -1,19 +1,26 @@
#!/usr/bin/env bash
set -eu
set -euo pipefail
if [ ! -z ${GITHUB_ACTIONS-} ]; then
set -x
fi
help() {
cat <<'EOF'
Install a binary release of a just hosted on GitHub
Usage:
USAGE:
install [options]
Options:
FLAGS:
-h, --help Display this message
-f, --force Force overwriting an existing binary
--tag TAG Tag (version) of the crate to install (default <latest release>)
--to LOCATION Where to install the binary (default ~/.cargo/bin)
OPTIONS:
--tag TAG Tag (version) of the crate to install, defaults to latest release
--to LOCATION Where to install the binary [default: ~/.cargo/bin]
--target TARGET
EOF
}
@ -22,18 +29,12 @@ crate=just
url=https://github.com/casey/just
releases=$url/releases
case `uname -s` in
Darwin) target=x86_64-apple-darwin;;
Linux) target=x86_64-unknown-linux-musl;;
*) target=x86_64-pc-windows-msvc;;
esac
say() {
echo "install: $1"
echo "install: $@"
}
say_err() {
say "$1" >&2
say "$@" >&2
}
err() {
@ -41,7 +42,7 @@ err() {
rm -rf $td
fi
say_err "ERROR $1"
say_err "error: $@"
exit 1
}
@ -65,6 +66,10 @@ while test $# -gt 0; do
tag=$2
shift
;;
--target)
target=$2
shift
;;
--to)
dest=$2
shift
@ -97,6 +102,20 @@ if [ -z ${tag-} ]; then
tag=$(curl -s "$releases/latest" | cut -d'"' -f2 | rev | cut -d'/' -f1 | rev)
fi
if [ -z ${target-} ]; then
uname_target=`uname -m`-`uname -s`
case $uname_target in
aarch64-Linux) target=aarch64-unknown-linux-gnu;;
x86_64-Darwin) target=x86_64-apple-darwin;;
x86_64-Linux) target=x86_64-unknown-linux-musl;;
x86_64-Windows_NT) target=x86_64-pc-windows-msvc;;
*)
err 'Could not determine target from output of `uname -m`-`uname -s`, please use `--target`:' $uname_target
;;
esac
fi
archive="$releases/download/$tag/$crate-$tag-$target.tar.gz"
say_err "Repository: $url"

View File

@ -139,7 +139,6 @@ test! {
shell: false,
}
#[cfg(unix)]
test! {
name: set_shell,
justfile: "
@ -156,21 +155,3 @@ test! {
stderr: "echo bar\necho foo\n",
shell: false,
}
#[cfg(windows)]
test! {
name: set_shell,
justfile: "
set shell := ['echo', '-n']
x := `bar`
foo:
echo {{x}}
echo foo
",
args: (),
stdout: "-n echo -n bar\r\r\n-n echo foo\r\n",
stderr: "echo -n bar\r\necho foo\n",
shell: false,
}