From 6d96be84dc47dadce6c387c0136b1c05eb9d422d Mon Sep 17 00:00:00 2001 From: Nils Wistoff Date: Thu, 13 Apr 2023 14:47:40 +0200 Subject: [PATCH] Add install-bender action (#3) * Add install-bender action Installs the specified or latest version of bender. Signed-off-by: Nils Wistoff * bender-install: Rename from install-bender Signed-off-by: Nils Wistoff * bender-install: Handle existing installations Signed-off-by: Nils Wistoff * bender-install.sh: Propagate errors Signed-off-by: Nils Wistoff * bender-install.sh: Take bender version as argument Signed-off-by: Nils Wistoff * bender-install: Unify capitalization Signed-off-by: Nils Wistoff --------- Signed-off-by: Nils Wistoff --- bender-install/README.md | 22 ++++++++++++++++++++++ bender-install/action.yml | 23 +++++++++++++++++++++++ bender-install/bender-install.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 bender-install/README.md create mode 100644 bender-install/action.yml create mode 100755 bender-install/bender-install.sh diff --git a/bender-install/README.md b/bender-install/README.md new file mode 100644 index 0000000..440825a --- /dev/null +++ b/bender-install/README.md @@ -0,0 +1,22 @@ +# Bender Install + +This action installs the specified or latest version of Bender. + +## Action usage + +Simply add the action to your desired upstream workflow. Indicate the desired version with the `version` argument, or omit it to install the latest version. If no version is specified and bender is already installed, the existing version will be used. For example: + +```yaml +name: bender-install + +on: [ push, pull_request, workflow_dispatch ] + +jobs: + bender-install: + runs-on: ubuntu-latest + steps: + - name: bender install + uses: pulp-platform/pulp-actions/bender-install@v2 + with: + version: 0.27.1 +``` diff --git a/bender-install/action.yml b/bender-install/action.yml new file mode 100644 index 0000000..577f311 --- /dev/null +++ b/bender-install/action.yml @@ -0,0 +1,23 @@ +# Copyright 2023 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +# Author: Nils Wistoff + +name: 'Bender Install' +description: 'Install the specified or latest version of Bender.' + +inputs: + # Optional argument + version: + description: 'Bender version to install (default: latest)' + required: false + default: '' + +runs: + using: "composite" + steps: + - name: Bender install + shell: bash + run: | + ${{ github.action_path }}/bender-install.sh ${{ inputs.version }} diff --git a/bender-install/bender-install.sh b/bender-install/bender-install.sh new file mode 100755 index 0000000..2da130d --- /dev/null +++ b/bender-install/bender-install.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright 2023 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Nils Wistoff + +set -e + +# Parse args +VERSION="" +if [ $# -eq 1 ]; then + VERSION=$1 +fi + +# Check for existing bender installation +if [ -x "$(command -v bender)" ]; then + if [[ $VERSION = "" ]] || [[ "$(bender --version)" = "bender $VERSION" ]]; then + echo "bender-install: $(bender --version) already installed." + exit 0 + else + echo "bender-install: bender $VERSION requested but $(bender --version) is already installed. Aborting." + exit 1 + fi +fi + +# Install bender +sudo mkdir -p /tools/bender && sudo chmod 777 /tools/bender +cd /tools/bender && curl --proto '=https' --tlsv1.2 -sSf https://pulp-platform.github.io/bender/init | bash -s -- $VERSION +echo "PATH=/tools/bender:$PATH" >> ${GITHUB_ENV}