feat: add support for specifying plugins and plugin-dir
Signed-off-by: Ganesh Tiwari <ganesht049@gmail.com>
This commit is contained in:
@@ -12,17 +12,32 @@ inputs:
|
|||||||
description: "arch can be amd64, arm64 or arm"
|
description: "arch can be amd64, arm64 or arm"
|
||||||
required: false
|
required: false
|
||||||
deprecationMessage: "No longer required, action will now detect runner arch."
|
deprecationMessage: "No longer required, action will now detect runner arch."
|
||||||
|
plugins:
|
||||||
|
description: >
|
||||||
|
Plugins to install alongside Flux. One per line: `<name>@<version|digest>`. Example: `mirror@0.0.1`
|
||||||
|
required: false
|
||||||
|
plugin-dir:
|
||||||
|
description: >
|
||||||
|
Directory where the plugins should be installed, setups the `FLUXCD_PLUGINS` env variable.
|
||||||
|
defaults to be installed alongside flux installation directory in $RUNNER_TOOL_CACHE in a child dir named `/plugins`
|
||||||
|
required: false
|
||||||
bindir:
|
bindir:
|
||||||
description: "Alternative location for the Flux binary, defaults to path relative to $RUNNER_TOOL_CACHE."
|
description: "Alternative location for the Flux binary, defaults to path relative to $RUNNER_TOOL_CACHE."
|
||||||
required: false
|
required: false
|
||||||
token:
|
token:
|
||||||
description: "Token used to authenticate against the GitHub.com API."
|
description: "Token used to authenticate against the GitHub.com API."
|
||||||
required: false
|
required: false
|
||||||
|
outputs:
|
||||||
|
plugin-dir:
|
||||||
|
description: >
|
||||||
|
Directory where the plugins were installed by the action.
|
||||||
|
value: ${{ steps.set-outputs.outputs.plugin-dir }}
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- name: "Download the binary to the runner's cache dir"
|
- name: "Download the binary to the runner's cache dir"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
id: setup-flux-bin
|
||||||
env:
|
env:
|
||||||
VERSION: "${{ inputs.version }}"
|
VERSION: "${{ inputs.version }}"
|
||||||
FLUX_TOOL_DIR: "${{ inputs.bindir }}"
|
FLUX_TOOL_DIR: "${{ inputs.bindir }}"
|
||||||
@@ -42,11 +57,13 @@ runs:
|
|||||||
if [[ $VERSION = v* ]]; then
|
if [[ $VERSION = v* ]]; then
|
||||||
VERSION="${VERSION:1}"
|
VERSION="${VERSION:1}"
|
||||||
fi
|
fi
|
||||||
|
echo installed-flux-version="$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
OS=$(echo "${RUNNER_OS}" | tr '[:upper:]' '[:lower:]')
|
OS=$(echo "${RUNNER_OS}" | tr '[:upper:]' '[:lower:]')
|
||||||
if [[ "$OS" == "macos" ]]; then
|
if [[ "$OS" == "macos" ]]; then
|
||||||
OS="darwin"
|
OS="darwin"
|
||||||
fi
|
fi
|
||||||
|
echo os="$OS" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
ARCH=$(echo "${RUNNER_ARCH}" | tr '[:upper:]' '[:lower:]')
|
ARCH=$(echo "${RUNNER_ARCH}" | tr '[:upper:]' '[:lower:]')
|
||||||
if [[ "$ARCH" == "x64" ]]; then
|
if [[ "$ARCH" == "x64" ]]; then
|
||||||
@@ -54,6 +71,7 @@ runs:
|
|||||||
elif [[ "$ARCH" == "x86" ]]; then
|
elif [[ "$ARCH" == "x86" ]]; then
|
||||||
ARCH="386"
|
ARCH="386"
|
||||||
fi
|
fi
|
||||||
|
echo arch="$ARCH" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
FLUX_EXEC_FILE="flux"
|
FLUX_EXEC_FILE="flux"
|
||||||
if [[ "$OS" == "windows" ]]; then
|
if [[ "$OS" == "windows" ]]; then
|
||||||
@@ -146,3 +164,65 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
flux -v
|
flux -v
|
||||||
|
|
||||||
|
- name: "Plugin support gate"
|
||||||
|
id: plugin-support-gate
|
||||||
|
shell: bash
|
||||||
|
if: inputs.plugins != ''
|
||||||
|
env:
|
||||||
|
V1: ${{ steps.setup-flux-bin.outputs.installed-flux-version }}
|
||||||
|
run: |
|
||||||
|
if [ "$(printf '%s\n%s' "$V1" "2.9.0" | sort -V | tail -n1)" = "$V1" ]; then
|
||||||
|
echo plugin-support="yes" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo plugin-support="no" >> $GITHUB_OUTPUT
|
||||||
|
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "> Installed flux version: $V1, does not support plugins. needed >= 2.9.0" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "> Requested plugins cannot be installed." >> $GITHUB_STEP_SUMMARY
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: "Setup Plugins Dir"
|
||||||
|
shell: bash
|
||||||
|
if: steps.plugin-support-gate.outputs.plugin-support == 'yes'
|
||||||
|
env:
|
||||||
|
PLUGINS: ${{ inputs.plugins }}
|
||||||
|
FLUXCD_PLUGINS: ${{ inputs.plugin-dir }}
|
||||||
|
VERSION: ${{ steps.setup-flux-bin.outputs.installed-flux-version }}
|
||||||
|
OS: ${{ steps.setup-flux-bin.outputs.os }}
|
||||||
|
ARCH: ${{ steps.setup-flux-bin.outputs.arch }}
|
||||||
|
run: |
|
||||||
|
# if a plugin dir was not provided, create one
|
||||||
|
if [[ -z $FLUXCD_PLUGINS ]] then
|
||||||
|
FLUXCD_PLUGINS="${RUNNER_TOOL_CACHE}/flux2/${VERSION}/${OS}/${ARCH}/plugins/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# set it up as env variable for the subsequent steps as well
|
||||||
|
echo FLUXCD_PLUGINS="$FLUXCD_PLUGINS" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# create the dir if it does not exists
|
||||||
|
mkdir -p $FLUXCD_PLUGINS
|
||||||
|
|
||||||
|
- name: "Install Plugins"
|
||||||
|
shell: bash
|
||||||
|
id: install-plugins
|
||||||
|
if: steps.plugin-support-gate.outputs.plugin-support == 'yes'
|
||||||
|
env:
|
||||||
|
PLUGINS: ${{ inputs.plugins }}
|
||||||
|
run: |
|
||||||
|
# Read line by line
|
||||||
|
echo "$PLUGINS" | while read -r PLUGIN; do
|
||||||
|
# if $PLUGIN contains some string value and is not empty
|
||||||
|
if [[ -n $PLUGIN ]] || [[ $PLUGIN ]]; then
|
||||||
|
echo Installing: "$PLUGIN"
|
||||||
|
flux plugin install "$PLUGIN"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: "Set Output"
|
||||||
|
id: set-outputs
|
||||||
|
if: steps.plugin-support-gate.outputs.plugin-support == 'yes'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "plugin-dir=$FLUXCD_PLUGINS" >> $GITHUB_OUTPUT
|
||||||
|
|||||||
Reference in New Issue
Block a user