Skip to content

Commit

Permalink
oblt-cli/setup: version input precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek committed Jul 1, 2024
1 parent d530b3e commit ebcfe0b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
38 changes: 37 additions & 1 deletion .github/workflows/test-oblt-cli-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- version
- version-file
- default-version
- tools-versions
- non-existing-file
- both-version-and-version-file
runs-on: ubuntu-latest
steps:
- id: check
Expand All @@ -36,6 +39,7 @@ jobs:
run: |
version=$(oblt-cli version 2>&1)
[[ "$version" == *"version 7.2.2"* ]]
version-file:
runs-on: ubuntu-latest
steps:
Expand All @@ -51,6 +55,7 @@ jobs:
run: |
version=$(oblt-cli version 2>&1)
[[ "$version" == *"version 7.2.5"* ]]
default-version:
runs-on: ubuntu-latest
steps:
Expand All @@ -60,7 +65,9 @@ jobs:
github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }}
- name: Verify oblt-cli version
run: |
oblt-cli version
version=$(oblt-cli version 2>&1)
default_version=$(cat ./oblt-cli/setup/.default-oblt-cli-version)
[[ "$version" == *"version ${default_version}"* ]]
tools-versions:
runs-on: ubuntu-latest
Expand All @@ -82,3 +89,32 @@ jobs:
run: |
version=$(oblt-cli version 2>&1)
[[ "$version" == *"version 7.2.5"* ]]
non-existing-file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./oblt-cli/setup
id: oblt-cli-setup
continue-on-error: true
with:
github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }}
version-file: non-existing-file
- name: Verify step failed
if: steps.oblt-cli-setup.outcome != 'failure'
run: exit 1

both-version-and-version-file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./oblt-cli/setup
id: oblt-cli-setup
with:
github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }}
version: 7.3.0
version-file: non-existing-file
- name: Verify oblt-cli version
run: |
version=$(oblt-cli version 2>&1)
[[ "$version" == *"version 7.3.0"* ]]
1 change: 1 addition & 0 deletions oblt-cli/setup/.default-oblt-cli-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.3.0
2 changes: 1 addition & 1 deletion oblt-cli/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Setup oblt-cli for use in GitHub Actions workflows.
| `github-token` | The GitHub access token. | `true` | ` ` |
| `slack-channel` | The slack channel to notify the status. | `false` | `#observablt-bots` |
| `username` | Username to show in the deployments with oblt-cli, format: [a-z0-9] | `false` | `obltmachine` |
| `version` | Install a specific version of oblt-cli | `false` | `7.2.2` |
| `version` | Install a specific version of oblt-cli | `false` | ` ` |
| `version-file` | The file to read the version from. E.g. `.oblt-cli-version` or `.tool-versions`. This option takes precedence over `version`. | `false` | ` ` |
<!--/inputs-->

Expand Down
1 change: 0 additions & 1 deletion oblt-cli/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ inputs:
required: false
version:
description: "Install a specific version of oblt-cli"
default: "7.2.2"
required: false
version-file:
description: "The file to read the version from. E.g. `.oblt-cli-version` or `.tool-versions`. This option takes precedence over `version`."
Expand Down
31 changes: 20 additions & 11 deletions oblt-cli/setup/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,32 @@ else
exit 1
fi

OBLT_CLI_VERSION_FILE=${OBLT_CLI_VERSION_FILE:-}
input_version="${OBLT_CLI_VERSION:-}"
version_file="${OBLT_CLI_VERSION_FILE:-"${GITHUB_ACTION_PATH}/.default-oblt-cli-version"}"

if [[ -n "${OBLT_CLI_VERSION_FILE}" ]]; then
if [[ -f "${OBLT_CLI_VERSION_FILE}" ]]; then
if [[ "$(basename "$OBLT_CLI_VERSION_FILE")" == ".tool-versions" ]]; then
OBLT_CLI_VERSION=$(grep "^oblt-cli" "${OBLT_CLI_VERSION_FILE}" | awk '{ print $2 }')
else
OBLT_CLI_VERSION=$(< "${OBLT_CLI_VERSION_FILE}" tr -d '[:space:]')
fi
if [[ -n "${version_file}" && -n "${input_version}" ]]; then
echo "::notice title=elastic/oblt-actions/oblt-cli/setup::Both version and version-file are provided. Using version: ${input_version}."
fi

if [[ -n "${input_version}" ]]; then
version="${OBLT_CLI_VERSION}"
else
if [[ -f "${version_file}" ]]; then
case $(basename "$version_file") in
".tool-versions")
version=$(grep "^oblt-cli" "${version_file}" | awk '{ printf $2 }')
;;
*)
version=$(tr -d '[:space:]' <"${version_file}")
;;
esac
else
echo "[ERROR] ${OBLT_CLI_VERSION_FILE} file not found."
echo "::error title=elastic/oblt-actions/oblt-cli/setup::version-file not found: ${version_file}"
exit 1
fi
fi

# Downloads the latest release if OBLT_CLI_VERSION is not set
gh release download "${OBLT_CLI_VERSION}" \
gh release download "${version}" \
--skip-existing \
--repo elastic/observability-test-environments \
-p "${PATTERN}" \
Expand Down

0 comments on commit ebcfe0b

Please sign in to comment.