From ebcfe0b2036f2a0046d1a11b23e200ac11c01430 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 1 Jul 2024 22:50:48 +0200 Subject: [PATCH] oblt-cli/setup: version input precedence --- .github/workflows/test-oblt-cli-setup.yml | 38 ++++++++++++++++++++++- oblt-cli/setup/.default-oblt-cli-version | 1 + oblt-cli/setup/README.md | 2 +- oblt-cli/setup/action.yml | 1 - oblt-cli/setup/download.sh | 31 +++++++++++------- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 oblt-cli/setup/.default-oblt-cli-version diff --git a/.github/workflows/test-oblt-cli-setup.yml b/.github/workflows/test-oblt-cli-setup.yml index 6811f03..86d0924 100644 --- a/.github/workflows/test-oblt-cli-setup.yml +++ b/.github/workflows/test-oblt-cli-setup.yml @@ -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 @@ -36,6 +39,7 @@ jobs: run: | version=$(oblt-cli version 2>&1) [[ "$version" == *"version 7.2.2"* ]] + version-file: runs-on: ubuntu-latest steps: @@ -51,6 +55,7 @@ jobs: run: | version=$(oblt-cli version 2>&1) [[ "$version" == *"version 7.2.5"* ]] + default-version: runs-on: ubuntu-latest steps: @@ -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 @@ -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"* ]] diff --git a/oblt-cli/setup/.default-oblt-cli-version b/oblt-cli/setup/.default-oblt-cli-version new file mode 100644 index 0000000..1502020 --- /dev/null +++ b/oblt-cli/setup/.default-oblt-cli-version @@ -0,0 +1 @@ +7.3.0 diff --git a/oblt-cli/setup/README.md b/oblt-cli/setup/README.md index df23d41..8881f2a 100644 --- a/oblt-cli/setup/README.md +++ b/oblt-cli/setup/README.md @@ -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` | ` ` | diff --git a/oblt-cli/setup/action.yml b/oblt-cli/setup/action.yml index 742279b..c7ab17c 100644 --- a/oblt-cli/setup/action.yml +++ b/oblt-cli/setup/action.yml @@ -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`." diff --git a/oblt-cli/setup/download.sh b/oblt-cli/setup/download.sh index f43de5c..3e80d5c 100755 --- a/oblt-cli/setup/download.sh +++ b/oblt-cli/setup/download.sh @@ -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}" \