From acc7494268edd22f152890bea6dd746f512a1817 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 27 May 2021 23:16:45 -0700 Subject: [PATCH] Improve install script (#847) - Allow passing `--target` to select target - Guess target from OS and architecture --- .github/workflows/build.yaml | 20 +++++++++++++++ docs/install.sh | 47 +++++++++++++++++++++++++----------- tests/shell.rs | 19 --------------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 036f0460..b5ce735d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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/') diff --git a/docs/install.sh b/docs/install.sh index fdaa189f..416ba5e6 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -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 ) - --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" diff --git a/tests/shell.rs b/tests/shell.rs index 2e526d25..412cb886 100644 --- a/tests/shell.rs +++ b/tests/shell.rs @@ -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, -}