1
0
mirror of synced 2026-06-29 23:00:48 +00:00

Add docs and tests for plugins setup

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
Matheus Pimenta
2026-06-29 10:44:24 +01:00
parent bbf064e4fc
commit 4b7e9eef43
3 changed files with 68 additions and 10 deletions
+38
View File
@@ -27,3 +27,41 @@ jobs:
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup flux - name: Setup flux
uses: ./action uses: ./action
plugins:
runs-on: ubuntu-latest
name: action plugins on ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Build flux
shell: bash
run: |
set -euo pipefail
mkdir -p cmd/flux/manifests "$RUNNER_TEMP/flux-bin"
printf "apiVersion: v1\nkind: List\nitems: []\n" > cmd/flux/manifests/dummy.yaml
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=0.0.0-pr" -o "$RUNNER_TEMP/flux-bin/flux" ./cmd/flux
- name: Setup flux with plugin
id: setup
uses: ./action
with:
version: 0.0.0-pr
bindir: ${{ runner.temp }}/flux-bin
plugins: |
mirror@sha256:91a1e04c2015ee66b1633e362cdb6d4550891b91bf3391a83414b9e9912e53f1
- name: Assert plugin installation
shell: bash
env:
ACTION_PLUGIN_DIR: ${{ steps.setup.outputs['plugin-dir'] }}
run: |
set -euo pipefail
test -n "${FLUXCD_PLUGINS:-}"
test "$ACTION_PLUGIN_DIR" = "$FLUXCD_PLUGINS"
test -x "$FLUXCD_PLUGINS/flux-mirror"
flux plugin list
flux mirror --help
+19
View File
@@ -12,6 +12,25 @@ steps:
run: flux version --client run: flux version --client
``` ```
To install Flux plugins alongside the CLI:
```yaml
steps:
- name: Setup Flux CLI
uses: fluxcd/flux2/action@main
with:
plugins: |
mirror@0.0.1
- name: Run Flux plugin
run: flux mirror --help
```
Installing plugins requires a Flux version with plugin support (v2.9.0 or later).
The `plugins` input accepts one plugin per line in `<name>@<version|digest>`
format. The `plugin-dir` input is only used when `plugins` is set; when
plugins are installed, the action exports `FLUXCD_PLUGINS` for subsequent
steps.
The Flux GitHub Action can be used to automate various tasks in CI, such as: The Flux GitHub Action can be used to automate various tasks in CI, such as:
- [Automate Flux upgrades on clusters via Pull Requests](https://fluxcd.io/flux/flux-gh-action/#automate-flux-updates) - [Automate Flux upgrades on clusters via Pull Requests](https://fluxcd.io/flux/flux-gh-action/#automate-flux-updates)
+11 -10
View File
@@ -18,9 +18,10 @@ inputs:
required: false required: false
plugin-dir: plugin-dir:
description: > description: >
Directory where requested plugins are installed. When plugins are installed, Directory where requested plugins are installed. This input is only used when
the action exports `FLUXCD_PLUGINS` for subsequent steps. Defaults to a `plugins` is set. When plugins are installed, the action exports
`plugins` directory alongside the Flux binary in $RUNNER_TOOL_CACHE. `FLUXCD_PLUGINS` for subsequent steps. Defaults to a `plugins` directory
alongside the Flux binary in $RUNNER_TOOL_CACHE.
required: false 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."
@@ -58,13 +59,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 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 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
@@ -72,7 +73,7 @@ runs:
elif [[ "$ARCH" == "x86" ]]; then elif [[ "$ARCH" == "x86" ]]; then
ARCH="386" ARCH="386"
fi fi
echo arch="$ARCH" >> $GITHUB_OUTPUT echo "arch=$ARCH" >> "$GITHUB_OUTPUT"
FLUX_EXEC_FILE="flux" FLUX_EXEC_FILE="flux"
if [[ "$OS" == "windows" ]]; then if [[ "$OS" == "windows" ]]; then
@@ -82,7 +83,7 @@ runs:
if [[ -z "$FLUX_TOOL_DIR" ]]; then if [[ -z "$FLUX_TOOL_DIR" ]]; then
FLUX_TOOL_DIR="${RUNNER_TOOL_CACHE}/flux2/${VERSION}/${OS}/${ARCH}" FLUX_TOOL_DIR="${RUNNER_TOOL_CACHE}/flux2/${VERSION}/${OS}/${ARCH}"
fi fi
if [[ ! -x "$FLUX_TOOL_DIR/FLUX_EXEC_FILE" ]]; then if [[ ! -x "$FLUX_TOOL_DIR/$FLUX_EXEC_FILE" ]]; then
DL_DIR="$(mktemp -dt flux2-XXXXXX)" DL_DIR="$(mktemp -dt flux2-XXXXXX)"
trap 'rm -rf $DL_DIR' EXIT trap 'rm -rf $DL_DIR' EXIT
@@ -173,10 +174,10 @@ runs:
run: | run: |
flux_version="$(flux -v 2>/dev/null | awk '{print $3}')" flux_version="$(flux -v 2>/dev/null | awk '{print $3}')"
if flux plugin --help >/dev/null 2>&1; then if flux plugin --help >/dev/null 2>&1; then
echo plugin-support="yes" >> $GITHUB_OUTPUT echo "plugin-support=yes" >> "$GITHUB_OUTPUT"
exit 0 exit 0
else else
echo plugin-support="no" >> $GITHUB_OUTPUT echo "plugin-support=no" >> "$GITHUB_OUTPUT"
msg="Installed Flux version ${flux_version:-unknown} does not support plugins; need >= 2.9.0. Requested plugins cannot be installed." msg="Installed Flux version ${flux_version:-unknown} does not support plugins; need >= 2.9.0. Requested plugins cannot be installed."
echo "::error title=Unsupported Flux version::$msg" echo "::error title=Unsupported Flux version::$msg"
echo "> [!CAUTION]" >> $GITHUB_STEP_SUMMARY echo "> [!CAUTION]" >> $GITHUB_STEP_SUMMARY
@@ -224,4 +225,4 @@ runs:
if: steps.plugin-support-gate.outputs.plugin-support == 'yes' if: steps.plugin-support-gate.outputs.plugin-support == 'yes'
shell: bash shell: bash
run: | run: |
echo "plugin-dir=$FLUXCD_PLUGINS" >> $GITHUB_OUTPUT echo "plugin-dir=$FLUXCD_PLUGINS" >> "$GITHUB_OUTPUT"