Skip to content

Commit bc924b0

Browse files
authored
Merge pull request #5975 from somaz94/action-version-file
Add version-file input to the Flux CLI action
2 parents c590241 + 31bdd6e commit bc924b0

5 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/action.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ jobs:
2828
- name: Setup flux
2929
uses: ./action
3030

31+
version-file:
32+
runs-on: ubuntu-latest
33+
name: action version-file on ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
37+
- name: Setup flux from a plain version file
38+
uses: ./action
39+
with:
40+
version-file: action/testdata/.flux-version
41+
- name: Assert plain version file
42+
shell: bash
43+
run: |
44+
set -euo pipefail
45+
flux -v
46+
flux -v | grep -q '2.8.8'
47+
- name: Setup flux from a .tool-versions file
48+
uses: ./action
49+
with:
50+
version-file: action/testdata/.tool-versions
51+
- name: Assert .tool-versions file
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
flux -v
56+
flux -v | grep -q '2.9.2'
57+
3158
plugins:
3259
runs-on: ubuntu-latest
3360
name: action plugins on ubuntu-latest

action/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ steps:
1212
run: flux version --client
1313
```
1414
15+
To pin the Flux version from a file instead of hardcoding it in the workflow:
16+
17+
```yaml
18+
steps:
19+
- name: Setup Flux CLI
20+
uses: fluxcd/flux2/action@main
21+
with:
22+
version-file: .flux-version
23+
- name: Run Flux CLI
24+
run: flux version --client
25+
```
26+
27+
The `version-file` input accepts a `.tool-versions` file (asdf format, reads the
28+
`flux` entry) or a plain text file containing a single version such as `2.0.0`.
29+
It is ignored when `version` is set.
30+
1531
To install Flux plugins alongside the CLI:
1632

1733
```yaml

action/action.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ inputs:
88
version:
99
description: "Flux version e.g. 2.0.0 (defaults to latest stable release)"
1010
required: false
11+
version-file:
12+
description: >
13+
Path to a file specifying the Flux version to install. Accepts a
14+
`.tool-versions` file (asdf format, reads the `flux` entry) or a plain
15+
text file containing a single version such as `2.0.0`. Ignored when
16+
`version` is set.
17+
required: false
1118
arch:
1219
description: "arch can be amd64, arm64 or arm"
1320
required: false
@@ -44,9 +51,26 @@ runs:
4451
id: setup-flux-bin
4552
env:
4653
VERSION: "${{ inputs.version }}"
54+
VERSION_FILE: "${{ inputs.version-file }}"
4755
FLUX_TOOL_DIR: "${{ inputs.bindir }}"
4856
TOKEN: "${{ inputs.token }}"
4957
run: |
58+
if [[ -z "$VERSION" ]] && [[ -n "$VERSION_FILE" ]]; then
59+
if [[ ! -f "$VERSION_FILE" ]]; then
60+
echo "version-file '$VERSION_FILE' not found"
61+
exit 1
62+
fi
63+
if [[ "$(basename "$VERSION_FILE")" == ".tool-versions" ]]; then
64+
VERSION=$(grep -E '^[[:space:]]*flux2?[[:space:]]' "$VERSION_FILE" | head -n1 | awk '{print $2}' | tr -d '[:space:]')
65+
else
66+
VERSION=$(grep -vE '^[[:space:]]*(#|$)' "$VERSION_FILE" | head -n1 | tr -d '[:space:]')
67+
fi
68+
if [[ -z "$VERSION" ]]; then
69+
echo "Unable to read Flux version from '$VERSION_FILE'"
70+
exit 1
71+
fi
72+
fi
73+
5074
if [[ -z "$VERSION" ]] || [[ "$VERSION" = "latest" ]]; then
5175
if [[ "${TOKEN}" != '' ]]; then
5276
VERSION=$(curl -fsSL -H "Authorization: token ${TOKEN}" https://api.github.com/repos/fluxcd/flux2/releases/latest | grep tag_name | cut -d '"' -f 4)

action/testdata/.flux-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.8.8

action/testdata/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flux 2.9.2

0 commit comments

Comments
 (0)