diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d70a211..0fe0ca1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Test Brioche Setup -on: +on: push: branches: - main @@ -21,4 +21,7 @@ jobs: version: 'v0.1.3' # Optional, defaults to v0.1.3 - name: Verify Brioche installation - run: brioche --version # Verifies that Brioche is available in the PATH + run: | + brioche --version + brioche install -r hello_world + hello-world diff --git a/README.md b/README.md index 9754e30..d916937 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![GitHub release (latest by date)](https://img.shields.io/github/v/release/brioche-dev/setup-brioche) ![GitHub](https://img.shields.io/github/license/brioche-dev/setup-brioche) -A GitHub Action to install [Brioche](https://brioche.dev/), a package manager designed for developers seeking efficient, streamlined software installation and dependency management. +Official GitHub Action to install [Brioche](https://brioche.dev/), a delicious package manager. ## Overview @@ -32,17 +32,16 @@ jobs: ## Inputs -- `version`: (Optional) The version of Brioche to install. Defaults to `v0.1.3`. -- `install-dir`: (Optional) The directory where Brioche should be installed. Defaults to `${{ github.home }}/.local/bin`. +- `version`: (Optional) The version of Brioche to install. Defaults to `v0.1.3` (the latest version). +- `install-dir`: (Optional) The directory where Brioche should be installed. Defaults to `$HOME/.local/bin`. ## How It Works This Action runs a shell script that: 1. Downloads the specified version of Brioche based on the runner's OS and architecture. -2. Verifies the integrity of the download using a SHA-256 checksum. -3. Installs Brioche into the specified or default directory. -4. Adds the install directory to the `PATH` for use in subsequent steps. +2. Installs Brioche into the install directory (defaults to `$HOME/.local/bin`). +3. Updates `$PATH` so Brioche and any installed packages are available in subsequent steps. ### Example Workflow @@ -60,21 +59,21 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Brioche uses: brioche-dev/setup-brioche@v1 - with: - version: 'v0.1.3' - install-dir: '/custom/install/path' # Optional, specify if needed + # with: + # version: 'v0.1.3' # Optional + # install-dir: '$HOME/custom/install/path' # Optional - - name: Install Dependencies - run: | - brioche install my-package - brioche update + - name: Build package + run: brioche build -o output - - name: Run Build Script - run: ./build.sh + - name: Install "Hello world" + run: | + brioche install -r hello_world + hello-world ``` ## Logs and Debugging diff --git a/action.yml b/action.yml index d96ff74..b2266bc 100644 --- a/action.yml +++ b/action.yml @@ -16,9 +16,7 @@ runs: - name: Install Brioche shell: bash run: | - chmod +x $GITHUB_ACTION_PATH/install-brioche.sh - $GITHUB_ACTION_PATH/install-brioche.sh "${{ inputs.install-dir }}" ${{ inputs.version }} - - - name: Add Brioche to PATH - shell: bash - run: echo "${{ inputs.install-dir }}" >> $GITHUB_PATH + "$GITHUB_ACTION_PATH"/install-brioche.sh + env: + install_dir: ${{ inputs.install-dir }} + version: ${{ inputs.version }} diff --git a/install-brioche.sh b/install-brioche.sh old mode 100644 new mode 100755 index 6b0ea99..3b18a92 --- a/install-brioche.sh +++ b/install-brioche.sh @@ -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'