diff --git a/.github/workflows/test-oblt-cli-setup.yml b/.github/workflows/test-oblt-cli-setup.yml index c3f3d0f9..6811f036 100644 --- a/.github/workflows/test-oblt-cli-setup.yml +++ b/.github/workflows/test-oblt-cli-setup.yml @@ -12,13 +12,73 @@ permissions: jobs: test: + needs: + - version + - version-file + - default-version + runs-on: ubuntu-latest + steps: + - id: check + uses: elastic/oblt-actions/check-dependent-jobs@v1 + with: + jobs: ${{ toJSON(needs) }} + - run: ${{ steps.check.outputs.is-success }} + + version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./oblt-cli/setup + with: + version: 7.2.2 + github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }} + - name: Verify oblt-cli version + run: | + version=$(oblt-cli version 2>&1) + [[ "$version" == *"version 7.2.2"* ]] + version-file: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup version file + run: | + echo "7.2.5" > .oblt-cli-version - uses: ./oblt-cli/setup with: github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }} + version-file: .oblt-cli-version + - name: Verify oblt-cli version + run: | + version=$(oblt-cli version 2>&1) + [[ "$version" == *"version 7.2.5"* ]] + default-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./oblt-cli/setup + with: + github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }} + - name: Verify oblt-cli version + run: | + oblt-cli version + + tools-versions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup version file + run: | + cat < .tool-versions + oblt-cli 7.2.5 # This is a comment that contains oblt-cli + # This is another comment that contains oblt-cli + ruby 2.5.3 + nodejs 10.15.0 + EOF - uses: ./oblt-cli/setup with: github-token: ${{ secrets.OBLT_CLI_GITHUB_TOKEN }} - - run: oblt-cli version + version-file: .tool-versions + - name: Verify oblt-cli version + run: | + version=$(oblt-cli version 2>&1) + [[ "$version" == *"version 7.2.5"* ]] diff --git a/oblt-cli/setup/README.md b/oblt-cli/setup/README.md index 14ccc920..df23d41a 100644 --- a/oblt-cli/setup/README.md +++ b/oblt-cli/setup/README.md @@ -9,12 +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` | +| 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` | ` ` | ## Usage diff --git a/oblt-cli/setup/action.yml b/oblt-cli/setup/action.yml index 119feca3..742279b1 100644 --- a/oblt-cli/setup/action.yml +++ b/oblt-cli/setup/action.yml @@ -19,6 +19,9 @@ inputs: 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`." + required: false runs: using: composite @@ -28,6 +31,7 @@ runs: env: GH_TOKEN: ${{ inputs.github-token }} OBLT_CLI_VERSION: ${{ inputs.version }} + OBLT_CLI_VERSION_FILE: ${{ inputs.version-file }} shell: bash - name: Configure oblt-cli run: > diff --git a/oblt-cli/setup/download.sh b/oblt-cli/setup/download.sh index e7e2da6e..f43de5cf 100755 --- a/oblt-cli/setup/download.sh +++ b/oblt-cli/setup/download.sh @@ -29,6 +29,21 @@ else exit 1 fi +OBLT_CLI_VERSION_FILE=${OBLT_CLI_VERSION_FILE:-} + +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 + else + echo "[ERROR] ${OBLT_CLI_VERSION_FILE} file not found." + exit 1 + fi +fi + # Downloads the latest release if OBLT_CLI_VERSION is not set gh release download "${OBLT_CLI_VERSION}" \ --skip-existing \