Browse Source

Allow using homebrew to install with the installation script (#244)

remotes/origin/add-simple-redirecting-site
Gal Schlezinger 4 years ago committed by GitHub
parent
commit
44e148e212
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      .ci/get_shell_profile.sh
  2. 44
      .ci/install.sh
  3. 21
      .ci/test_installation_script.sh
  4. 120
      .github/workflows/installation_script.yml

23
.ci/get_shell_profile.sh

@ -0,0 +1,23 @@
#!/bin/bash
OS="$(uname -s)"
case $1 in
"fish")
CONFIG_DIR="$(fish -c 'echo -n $__fish_config_dir')"
echo "${CONFIG_DIR-"$HOME/.config/fish"}/fish.config"
;;
"zsh")
echo "$HOME/.zshrc"
;;
"bash")
if [ "$OS" = "Darwin" ]; then
echo "$HOME/.profile"
else
echo "$HOME/.bashrc"
fi
;;
*)
exit 1
;;
esac

44
.ci/install.sh

@ -20,7 +20,7 @@ parse_args() {
SKIP_SHELL="true" SKIP_SHELL="true"
shift # past argument shift # past argument
;; ;;
--force-install) --force-install | --force-no-brew)
echo "\`--force-install\`: I hope you know what you're doing." >&2 echo "\`--force-install\`: I hope you know what you're doing." >&2
FORCE_INSTALL="true" FORCE_INSTALL="true"
shift shift
@ -47,13 +47,13 @@ set_filename() {
FILENAME="fnm-linux" FILENAME="fnm-linux"
elif [ "$OS" == "Darwin" ] && [ "$FORCE_INSTALL" == "true" ]; then elif [ "$OS" == "Darwin" ] && [ "$FORCE_INSTALL" == "true" ]; then
FILENAME="fnm-macos" FILENAME="fnm-macos"
USE_HOMEBREW="false"
echo "Downloading the latest fnm binary from GitHub..."
echo " Pro tip: it's eaiser to use Homebrew for managing fnm in MacOS."
echo " Remove the \`--force-no-brew\` so it will be easy to upgrade."
elif [ "$OS" == "Darwin" ]; then elif [ "$OS" == "Darwin" ]; then
echo "Hey! Thanks for trying fnm." USE_HOMEBREW="true"
echo "MacOS installation works better using Homebrew." echo "Downloading fnm using Homebrew..."
echo "Please consider installing using:"
echo " $ brew install Schniz/tap/fnm"
echo "or run the script again with the \`--force-install\` option."
exit 1
else else
echo "OS $OS is not supported." echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue to https://github.com/Schniz/fnm/issues" echo "If you think that's a bug - please file an issue to https://github.com/Schniz/fnm/issues"
@ -62,27 +62,31 @@ set_filename() {
} }
download_fnm() { download_fnm() {
if [ "$USE_HOMEBREW" == "true" ]; then
brew install Schniz/tap/fnm > /dev/null
else
if [ "$RELEASE" == "latest" ]; then if [ "$RELEASE" == "latest" ]; then
URL=https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip URL="https://github.com/Schniz/fnm/releases/latest/download/$FILENAME.zip"
else else
URL=https://github.com/Schniz/fnm/releases/download/$RELEASE/$FILENAME.zip URL="https://github.com/Schniz/fnm/releases/download/$RELEASE/$FILENAME.zip"
fi fi
DOWNLOAD_DIR=$(mktemp -d) DOWNLOAD_DIR=$(mktemp -d)
echo "Downloading $URL..." echo "Downloading $URL..."
mkdir -p $INSTALL_DIR &>/dev/null mkdir -p "$INSTALL_DIR" &>/dev/null
curl --progress-bar -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip curl --progress-bar -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"
if [ 0 -ne $? ]; then if [ 0 -ne $? ]; then
echo "Download failed. Check that the release/filename are correct." echo "Download failed. Check that the release/filename are correct."
exit 1 exit 1
fi; fi
unzip -q $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"
mv $DOWNLOAD_DIR/$FILENAME/fnm $INSTALL_DIR/fnm mv "$DOWNLOAD_DIR/$FILENAME/fnm" "$INSTALL_DIR/fnm"
chmod u+x $INSTALL_DIR/fnm chmod u+x "$INSTALL_DIR/fnm"
fi
} }
check_dependencies() { check_dependencies() {
@ -104,6 +108,16 @@ check_dependencies() {
SHOULD_EXIT="true" SHOULD_EXIT="true"
fi fi
if [ "$USE_HOMEBREW" = "true" ]; then
echo -n "Checking availability of Homebrew (brew)... "
if hash brew 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
fi
if [ "$SHOULD_EXIT" = "true" ]; then if [ "$SHOULD_EXIT" = "true" ]; then
exit 1 exit 1
fi fi

21
.ci/test_installation_script.sh

@ -0,0 +1,21 @@
#!/bin/bash
DIRECTORY="$(dirname "$0")"
SHELL_TO_RUN="$1"
PROFILE_FILE="$("$DIRECTORY/get_shell_profile.sh" "$SHELL_TO_RUN")"
echo "Profile is $PROFILE_FILE"
$SHELL_TO_RUN -c '
fnm install 12.5.0
fnm ls | grep 12.5.0
echo "fnm ls worked."
'
$SHELL_TO_RUN -c '
fnm use 12.5.0
node --version | grep 12.5.0
echo "node --version worked."
'

120
.github/workflows/installation_script.yml

@ -1,81 +1,77 @@
name: Installation script name: Installation script
on: on:
pull_request: pull_request:
paths:
- .ci/install.sh
push: push:
branches: branches:
- master - master
paths:
- .ci/install.sh
jobs: jobs:
install_on_linux: test_against_latest_release:
runs-on: ubuntu-latest name: Test against latest release
strategy: strategy:
matrix: matrix:
include: shell: [fish, zsh, bash]
- shell: fish setup:
source: ~/.config/fish/config.fish - os: ubuntu
- shell: zsh script_arguments: ''
source: ~/.zshrc - os: macos
- shell: bash script_arguments: ''
source: ~/.bashrc - os: macos
script_arguments: '--force-no-brew'
runs-on: ${{ matrix.setup.os }}-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- run: "sudo apt-get install -y ${{ matrix.shell }}" - run: "sudo apt-get install -y ${{ matrix.shell }}"
name: Install shell name: Install ${{matrix.shell}} using apt-get
if: matrix.setup.os == 'ubuntu'
- run: "brew install ${{ matrix.shell }}"
name: Install ${{matrix.shell}} using Homebrew
if: matrix.setup.os == 'macos'
- run: "cp ~/.bashrc ~/.bashrc.bak && echo '. ~/.bashrc.bak' > ~/.bashrc" - run: "cp ~/.bashrc ~/.bashrc.bak && echo '. ~/.bashrc.bak' > ~/.bashrc"
name: reset bashrc file name: reset bashrc file
- run: "env SHELL=$(which ${{ matrix.shell }}) bash ./.ci/install.sh" - run: "env SHELL=$(which ${{ matrix.shell }}) bash ./.ci/install.sh ${{ matrix.setup.script_arguments }}"
name: Run the installation script name: Run the installation script
- run: ./.ci/test_installation_script.sh ${{ matrix.shell }}
name: 'Test installation script'
- run: | # install_on_mac_binary:
${{ matrix.shell }} -c ' # runs-on: macos-latest
source ${{ matrix.source }} # strategy:
fnm install 12.5.0 # matrix:
fnm ls | grep 12.5.0 # include:
' # - shell: fish
name: 'Install a Node version with `fnm install`' # source: ~/.config/fish/config.fish
# - shell: zsh
- run: | # source: ~/.zshrc
${{ matrix.shell }} -c ' # - shell: bash
source ${{ matrix.source }} # source: ~/.bashrc
fnm use 12.5.0 # steps:
node --version | grep 12.5.0 # - uses: actions/checkout@v2
' # - run: "brew install ${{ matrix.shell }}"
name: 'Check switching versions with `fnm use`' # name: Install shell
# - name: reset bashrc file
install_on_mac: # run: |
runs-on: macos-latest # cp ~/.bashrc ~/.bashrc.bak
strategy: # echo '. ~/.bashrc.bak' > ~/.bashrc
matrix: # - run: "env SHELL=$(which ${{ matrix.shell }}) bash ./.ci/install.sh --force-install"
include: # name: Run the installation script
- shell: fish
source: ~/.config/fish/config.fish
- shell: zsh
source: ~/.zshrc
- shell: bash
source: ~/.bashrc
steps:
- uses: actions/checkout@v2
- run: "brew install ${{ matrix.shell }}"
name: Install shell
- name: reset bashrc file
run: |
cp ~/.bashrc ~/.bashrc.bak
echo '. ~/.bashrc.bak' > ~/.bashrc
- run: "env SHELL=$(which ${{ matrix.shell }}) bash ./.ci/install.sh --force-install"
name: Run the installation script
- name: 'Install a Node version with `fnm install`' # - name: 'Install a Node version with `fnm install`'
run: | # run: |
${{ matrix.shell }} -c ' # ${{ matrix.shell }} -c '
source ${{ matrix.source }} # source ${{ matrix.source }}
fnm install 12.5.0 # fnm install 12.5.0
fnm ls | grep 12.5.0 # fnm ls | grep 12.5.0
' # '
- name: 'Check switching versions with `fnm use`' # - name: 'Check switching versions with `fnm use`'
run: | # run: |
${{ matrix.shell }} -c ' # ${{ matrix.shell }} -c '
source ${{ matrix.source }} # source ${{ matrix.source }}
fnm use 12.5.0 # fnm use 12.5.0
node --version | grep 12.5.0 # node --version | grep 12.5.0
' # '

Loading…
Cancel
Save