diff --git a/.github/workflows/test-oblt-cli-setup.yml b/.github/workflows/test-oblt-cli-setup.yml index 6811f036..86d0924f 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 00000000..15020207 --- /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 df23d41a..9ffda1d3 100644 --- a/oblt-cli/setup/README.md +++ b/oblt-cli/setup/README.md @@ -9,13 +9,13 @@ Setup oblt-cli for use in GitHub Actions workflows. ## Inputs -| Name | Description | Required | Default | -|-----------------|-------------------------------------------------------------------------------------------------------------------------------|----------|--------------------| -| `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-file` | The file to read the version from. E.g. `.oblt-cli-version` or `.tool-versions`. This option takes precedence over `version`. | `false` | ` ` | +| Name | Description | Required | Default | +|-----------------|--------------------------------------------------------------------------------------------------------------------|----------|--------------------| +| `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. If both `version` and `version-file` are provided, `version` will be used. | `false` | ` ` | +| `version-file` | The file to read the version from. E.g. `.oblt-cli-version` or `.tool-versions` (asdf-vm). | `false` | ` ` | ## Usage diff --git a/oblt-cli/setup/action.yml b/oblt-cli/setup/action.yml index 742279b1..09a9d8df 100644 --- a/oblt-cli/setup/action.yml +++ b/oblt-cli/setup/action.yml @@ -16,11 +16,10 @@ inputs: default: "obltmachine" required: false version: - description: "Install a specific version of oblt-cli" - default: "7.2.2" + description: "Install a specific version of oblt-cli. If both `version` and `version-file` are provided, `version` will be used." 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`." + description: "The file to read the version from. E.g. `.oblt-cli-version` or `.tool-versions` (asdf-vm)." required: false runs: diff --git a/oblt-cli/setup/download.sh b/oblt-cli/setup/download.sh index f43de5cf..83fad576 100755 --- a/oblt-cli/setup/download.sh +++ b/oblt-cli/setup/download.sh @@ -29,26 +29,35 @@ 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 "::warning 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}" \ --output - | tar -xz -C "${BIN_DIR}" - +echo "::notice title=elastic/oblt-actions/oblt-cli/setup::Downloaded oblt-cli version: ${version}" echo "${BIN_DIR}" >> "${GITHUB_PATH}"