From bba6df0274ec06f257cc1fe74aa2e94dac4e11d7 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:18:05 -0700 Subject: [PATCH 01/11] Update installation script --- action.yml | 11 ++-- install-brioche.sh | 140 ++++++++++++++++++++++++++++----------------- 2 files changed, 91 insertions(+), 60 deletions(-) diff --git a/action.yml b/action.yml index d96ff74..e53f7db 100644 --- a/action.yml +++ b/action.yml @@ -16,9 +16,8 @@ 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 + chmod +x "$GITHUB_ACTION_PATH"/install-brioche.sh + "$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 index 6b0ea99..1db5760 100644 --- a/install-brioche.sh +++ b/install-brioche.sh @@ -1,66 +1,98 @@ #!/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' +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' +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") +for new_path in "${new_paths[@]}"; do + echo "$new_path" >> "$GITHUB_PATH" + echo "Added to \$PATH: $new_path" +done -install_brioche "$@" +echo '::endgroup' From dd7b0b6a86e7fd30c7d30d178fb8c144061ceacd Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:18:21 -0700 Subject: [PATCH 02/11] Update test workflow to validate package installation --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 From 8c848cf3fdf783429d506adc2ad16aaef438bb99 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:18:27 -0700 Subject: [PATCH 03/11] Update README --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9754e30..cedcca1 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`). +4. Updates `$PATH` so Brioche and any installed packages are available in subsequent steps. ### Example Workflow @@ -65,8 +64,8 @@ jobs: - name: Setup Brioche uses: brioche-dev/setup-brioche@v1 with: - version: 'v0.1.3' - install-dir: '/custom/install/path' # Optional, specify if needed + version: 'v0.1.3' # Optional + install-dir: '$HOME/custom/install/path' # Optional - name: Install Dependencies run: | From 799961e987b3a8463024774835095285eeb79000 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:19:46 -0700 Subject: [PATCH 04/11] Set execute permission on `install-brioche.sh` directly --- action.yml | 4 +--- install-brioche.sh | 0 2 files changed, 1 insertion(+), 3 deletions(-) mode change 100644 => 100755 install-brioche.sh diff --git a/action.yml b/action.yml index e53f7db..2322475 100644 --- a/action.yml +++ b/action.yml @@ -15,9 +15,7 @@ runs: steps: - name: Install Brioche shell: bash - run: | - chmod +x "$GITHUB_ACTION_PATH"/install-brioche.sh - "$GITHUB_ACTION_PATH"/install-brioche.sh + run: "$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 From 26ddb4187dabed59313083b3f2468625d6da94e1 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:22:08 -0700 Subject: [PATCH 05/11] Fix some minor script issues --- install-brioche.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install-brioche.sh b/install-brioche.sh index 1db5760..78ee1a3 100755 --- a/install-brioche.sh +++ b/install-brioche.sh @@ -7,6 +7,7 @@ set -euo pipefail # 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' @@ -14,11 +15,12 @@ if [ -z "${install_dir:-}" -o -z "${version:-}" ]; then fi if [ -z "${GITHUB_PATH:-}" ]; then echo '::error::$GITHUB_PATH not set! This script should be run in GitHub Actions' + exit 1 fi # 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' From 9f3f01f95ebe0d429715c093d1d7f9ce7a692fef Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:26:32 -0700 Subject: [PATCH 06/11] Fix numbering in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cedcca1..3c2e6ac 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ This Action runs a shell script that: 1. Downloads the specified version of Brioche based on the runner's OS and architecture. 2. Installs Brioche into the install directory (defaults to `$HOME/.local/bin`). -4. Updates `$PATH` so Brioche and any installed packages are available in subsequent steps. +3. Updates `$PATH` so Brioche and any installed packages are available in subsequent steps. ### Example Workflow From 4efda3444080153eeb445b2cb094175aaff0435e Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:27:56 -0700 Subject: [PATCH 07/11] Update example workflow --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3c2e6ac..2eb49a3 100644 --- a/README.md +++ b/README.md @@ -63,17 +63,17 @@ jobs: - name: Setup Brioche uses: brioche-dev/setup-brioche@v1 - with: - version: 'v0.1.3' # Optional - install-dir: '$HOME/custom/install/path' # Optional + # 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 From 29b677c30ac156d8fd4e2759bd729958f87a3884 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Fri, 1 Nov 2024 22:28:37 -0700 Subject: [PATCH 08/11] Tweak `actions/checkout` verison in example workflow in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2eb49a3..d916937 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ 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 From f754579794a0f10df6b5aa2852125f669048a33f Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Sun, 3 Nov 2024 03:12:21 -0800 Subject: [PATCH 09/11] Fix syntax in `action.yml` --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2322475..4be638f 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,8 @@ runs: steps: - name: Install Brioche shell: bash - run: "$GITHUB_ACTION_PATH"/install-brioche.sh + run: | + "$GITHUB_ACTION_PATH"/install-brioche.sh env: install_dir: ${{ inputs.install_dir }} version: ${{ inputs.version }} From 9b1da79b0f9f34fcdbc55c80f8532e1f093655fd Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Sun, 3 Nov 2024 03:14:24 -0800 Subject: [PATCH 10/11] Fix `$install_dir` not being set properly in `action.yml` --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 4be638f..b2266bc 100644 --- a/action.yml +++ b/action.yml @@ -18,5 +18,5 @@ runs: run: | "$GITHUB_ACTION_PATH"/install-brioche.sh env: - install_dir: ${{ inputs.install_dir }} + install_dir: ${{ inputs.install-dir }} version: ${{ inputs.version }} From 983745540b84f217c871574e3948358f1f61ace3 Mon Sep 17 00:00:00 2001 From: Kyle Lacy Date: Sun, 3 Nov 2024 03:15:46 -0800 Subject: [PATCH 11/11] Fix package install dir not being added to `$PATH` properly --- install-brioche.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-brioche.sh b/install-brioche.sh index 78ee1a3..3b18a92 100755 --- a/install-brioche.sh +++ b/install-brioche.sh @@ -91,7 +91,7 @@ echo '::group::Updating $PATH' # Add Brioche's install directory, plus the installation directory for # installed packages -new_paths=("$install_dir" "$HOME/.local/share/brioche/installed") +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"