-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fixes, cleanups, and tweaks (#1)
* Update installation script * Update test workflow to validate package installation * Update README * Set execute permission on `install-brioche.sh` directly * Fix some minor script issues * Fix numbering in README * Update example workflow * Tweak `actions/checkout` verison in example workflow in README * Fix syntax in `action.yml` * Fix `$install_dir` not being set properly in `action.yml` * Fix package install dir not being added to `$PATH` properly
- Loading branch information
Showing
4 changed files
with
112 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,100 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Wrap the installation in a function so it only runs once the | ||
# entire script is downloaded | ||
function install_brioche() { | ||
set -euo pipefail | ||
# Based on the official install script here: | ||
# https://github.com/brioche-dev/brioche.dev/blob/main/public/install.sh | ||
|
||
# Set installation directory from the first argument or default to $HOME/.local/bin | ||
install_dir="${1:-$HOME/.local/bin}" | ||
version="${2:-v0.1.3}" | ||
# Validate environment variables | ||
if [ -z "${HOME:-}" ]; then | ||
echo '::error::$HOME must be set' | ||
exit 1 | ||
fi | ||
if [ -z "${install_dir:-}" -o -z "${version:-}" ]; then | ||
echo '::error::$install_dir and $version must be set' | ||
exit 1 | ||
fi | ||
if [ -z "${GITHUB_PATH:-}" ]; then | ||
echo '::error::$GITHUB_PATH not set! This script should be run in GitHub Actions' | ||
exit 1 | ||
fi | ||
|
||
# Only validate $HOME if using the default installation directory | ||
if [[ "$install_dir" == "$HOME/.local/bin" ]]; then | ||
if [ -z "$HOME" ]; then | ||
echo "::error::$HOME environment variable is not set!" | ||
# If `install_dir` contains a `$` character, then try to expand env vars | ||
case "$install_dir" in | ||
*'$'* ) | ||
# Ensure the `envsubst` command exists | ||
if ! type envsubst >/dev/null; then | ||
echo '::error::envsubst is required to expand env vars in $install_dir' | ||
exit 1 | ||
fi | ||
if [ ! -d "$HOME" ]; then | ||
echo "::error::$HOME does not exist!" | ||
exit 1 | ||
|
||
# Get each referenced env var, and validate each one is not empty | ||
envsubst -v "$install_dir" | while read -r env_var; do | ||
if [ -z "${!env_var:-}" ]; then | ||
echo "::error:env var \$${env_var} is not set (used in \$install_dir)" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Expand each env var | ||
install_dir="$(echo "$install_dir" | envsubst)" | ||
|
||
# Ensure the result is not empty | ||
if [ -z "$install_dir" ]; then | ||
echo '::error:$install_dir expanded to empty string' | ||
fi | ||
fi | ||
|
||
# Get the URL based on the OS and architecture | ||
case "$OSTYPE" in | ||
linux*) | ||
case "$(uname -m)" in | ||
x86_64) | ||
brioche_url="https://releases.brioche.dev/$version/x86_64-linux/brioche" | ||
;; | ||
*) | ||
echo "::error::Sorry, Brioche isn't currently supported on your architecture" | ||
echo " Detected architecture: $(uname -m)" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "::error::Sorry, Brioche isn't currently supported on your operating system" | ||
echo " Detected OS: $OSTYPE" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
esac | ||
|
||
# Get the URL based on the OS and architecture | ||
case "$OSTYPE" in | ||
linux*) | ||
case "$(uname -m)" in | ||
x86_64) | ||
brioche_url="https://releases.brioche.dev/$version/x86_64-linux/brioche" | ||
;; | ||
*) | ||
echo "::error::Sorry, Brioche isn't currently supported on your architecture" | ||
echo " Detected architecture: $(uname -m)" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "::error::Sorry, Brioche isn't currently supported on your operating system" | ||
echo " Detected OS: $OSTYPE" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Create a temporary directory | ||
echo "::group::Setting up temporary directory" | ||
brioche_temp="$(mktemp -d -t brioche-XXXX)" | ||
trap 'rm -rf -- "$brioche_temp"' EXIT | ||
echo "Temporary directory created at $brioche_temp" | ||
echo "::endgroup::" | ||
|
||
echo "::group::Downloading Brioche" | ||
echo "Downloading from $brioche_url" | ||
curl --proto '=https' --tlsv1.2 -fL "$brioche_url" -o "$brioche_temp/brioche" | ||
echo "Download complete" | ||
echo "::endgroup::" | ||
|
||
# Create a temporary directory | ||
echo "::group::Setting up temporary directory" | ||
brioche_temp="$(mktemp -d -t brioche-XXXX)" | ||
trap 'rm -rf -- "$brioche_temp"' EXIT | ||
echo "Temporary directory created at $brioche_temp" | ||
echo "::endgroup::" | ||
echo "::group::Installing Brioche" | ||
mkdir -p "$install_dir" | ||
chmod +x "$brioche_temp/brioche" | ||
mv "$brioche_temp/brioche" "$install_dir/brioche" | ||
echo "Installation complete! Brioche installed to $install_dir/brioche" | ||
echo "::endgroup::" | ||
|
||
echo "::group::Downloading Brioche" | ||
echo "Downloading from $brioche_url" | ||
curl --proto '=https' --tlsv1.2 -fL "$brioche_url" -o "$brioche_temp/brioche" | ||
echo "Download complete" | ||
echo "::endgroup::" | ||
echo '::group::Updating $PATH' | ||
|
||
echo "::group::Installing Brioche" | ||
mkdir -p "$install_dir" | ||
chmod +x "$brioche_temp/brioche" | ||
mv "$brioche_temp/brioche" "$install_dir/brioche" | ||
echo "Installation complete! Brioche installed to $install_dir/brioche" | ||
echo "::endgroup::" | ||
} | ||
# Add Brioche's install directory, plus the installation directory for | ||
# installed packages | ||
new_paths=("$install_dir" "$HOME/.local/share/brioche/installed/bin") | ||
for new_path in "${new_paths[@]}"; do | ||
echo "$new_path" >> "$GITHUB_PATH" | ||
echo "Added to \$PATH: $new_path" | ||
done | ||
|
||
install_brioche "$@" | ||
echo '::endgroup' |