From a0085b088755ab87ddd6b44e1b7610fc393e1716 Mon Sep 17 00:00:00 2001 From: Ashley Hutson Date: Fri, 1 Nov 2024 03:06:13 -0700 Subject: [PATCH] Initial commit --- .github/workflows/publish.yml | 25 +++++ .github/workflows/test.yml | 24 +++++ .gitignore | 180 ++++++++++++++++++++++++++++++++++ LICENSE.md | 23 +++++ README.md | 95 ++++++++++++++++++ VERSION | 1 + action.yml | 19 ++++ install-brioche.sh | 72 ++++++++++++++ 8 files changed, 439 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 VERSION create mode 100644 action.yml create mode 100644 install-brioche.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6e9b9ab --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +name: Publish GitHub Actions + +on: + push: + tags: + - v?[0-9]+.[0-9]+.[0-9]+-?** + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Determine versions + id: versions + run: | + echo "major-version=v$(cat VERSION)" >> "$GITHUB_OUTPUT" + + - name: Debug versions + run: | + echo "${{steps.versions.outputs.major-version}}" + - run: git tag -f "${{ steps.versions.outputs.major-version }}" + if: ${{ ! contains(steps.versions.outputs.full-version,'-') }} + - run: git push -f origin "${{ steps.versions.outputs.major-version }}" + if: ${{ ! contains(steps.versions.outputs.full-version,'-') }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8e0a66a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Test Brioche Setup + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + setup-brioche: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Brioche + uses: brioche-dev/setup-brioche@v1 + with: + 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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8298baa --- /dev/null +++ b/.gitignore @@ -0,0 +1,180 @@ +# Created by https://www.toptal.com/developers/gitignore/api/node,zsh +# Edit at https://www.toptal.com/developers/gitignore?templates=node,zsh + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### Zsh ### +# Zsh compiled script + zrecompile backup +*.zwc +*.zwc.old + +# Zsh completion-optimization dumpfile +*zcompdump* + +# Zsh history +.zsh_history + +# Zsh sessions +.zsh_sessions + +# Zsh zcalc history +.zcalc_history + +# A popular plugin manager's files +._zinit +.zinit_lstupd + +# zdharma/zshelldoc tool's files +zsdoc/data + +# robbyrussell/oh-my-zsh/plugins/per-directory-history plugin's files +# (when set-up to store the history in the local directory) +.directory_history + +# MichaelAquilina/zsh-autoswitch-virtualenv plugin's files +# (for Zsh plugins using Python) +.venv + +# Zunit tests' output +/tests/_output/* +!/tests/_output/.gitkeep + +# End of https://www.toptal.com/developers/gitignore/api/node,zsh \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7d73442 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +MIT License + +Copyright (c) Kyle Lacy + +Copyright (c) Tangram, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9754e30 --- /dev/null +++ b/README.md @@ -0,0 +1,95 @@ +# setup-brioche + +![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. + +## Overview + +`setup-brioche` installs Brioche on GitHub-hosted or self-hosted runners, enabling your workflows to seamlessly use Brioche for managing packages and scripts. This Action sets up the environment quickly, ensuring that Brioche is ready for use in subsequent steps of your workflow. + +## Usage + +Add the `setup-brioche` Action to your workflow to install Brioche: + +```yaml +jobs: + setup-brioche: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Brioche + uses: brioche-dev/setup-brioche@v1 + with: + version: 'v0.1.3' # Optional, specify a version or use the default (v0.1.3) + install-dir: '/custom/install/path' # Optional, specify a custom installation path + + - name: Verify Brioche installation + run: brioche --version # Check that Brioche is available +``` + +## 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`. + +## 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. + +### Example Workflow + +Here's a complete workflow example: + +```yaml +name: CI with Brioche +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Brioche + uses: brioche-dev/setup-brioche@v1 + with: + version: 'v0.1.3' + install-dir: '/custom/install/path' # Optional, specify if needed + + - name: Install Dependencies + run: | + brioche install my-package + brioche update + + - name: Run Build Script + run: ./build.sh +``` + +## Logs and Debugging + +This Action uses GitHub's [logging groups](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines) to make output more readable. You will see collapsible log groups for stages like downloading, validating, and installing Brioche, making it easier to debug if needed. + +## Troubleshooting + +- Ensure the version specified in the `version` input is valid and available. +- If Brioche isn't recognized in your shell, make sure the install path is correctly set in your environment. + +## License + +This project is licensed under the [MIT License](https://github.com/brioche-dev/setup-brioche/blob/main/LICENSE). + +## Support and Contact + +For issues, feature requests, or questions, please open an issue in this repository or visit the [Brioche GitHub page](https://github.com/brioche-dev/brioche). diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..192820b --- /dev/null +++ b/action.yml @@ -0,0 +1,19 @@ +name: 'Setup Brioche' +description: 'GitHub Action to install Brioche on a runner' +author: 'brioche-dev' +inputs: + version: + description: 'Version of Brioche to install' + required: false + default: 'v0.1.3' +runs: + using: 'composite' + steps: + - name: Install Brioche + shell: bash + run: | + chmod +x $GITHUB_ACTION_PATH/install-brioche.sh + $GITHUB_ACTION_PATH/install-brioche.sh ${{ inputs.version }} + + - name: Add Brioche to PATH + run: echo "$HOME/.local/bin" >> $GITHUB_PATH diff --git a/install-brioche.sh b/install-brioche.sh new file mode 100644 index 0000000..46c82ba --- /dev/null +++ b/install-brioche.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# Wrap the installation in a function so it only runs once the +# entire script is downloaded +function install_brioche() { + set -euo pipefail + + # Set installation directory from the first argument or default to $HOME/.local/bin + install_dir="${1:-$HOME/.local/bin}" + version="${2:-v0.1.3}" + + # 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!" + exit 1 + fi + if [ ! -d "$HOME" ]; then + echo "::error::$HOME does not exist!" + exit 1 + 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" + checksum="3aaa66138a595fec42e656a93f9ae4c65d29af8825d665992ca553ff38240692" + ;; + *) + 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::" + + echo "::group::Validating checksum" + echo "$checksum $brioche_temp/brioche" | sha256sum -c - + echo "Checksum validation complete" + 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::" +} + +install_brioche "$@"