Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes, cleanups, and tweaks #1

Merged
merged 11 commits into from
Nov 3, 2024
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test Brioche Setup

on:
on:
push:
branches:
- main
Expand All @@ -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
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
142 changes: 88 additions & 54 deletions install-brioche.sh
100644 → 100755
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'