Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oblt-cli/setup: Add version-file input #69

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion .github/workflows/test-oblt-cli-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > .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"* ]]
13 changes: 7 additions & 6 deletions oblt-cli/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ Setup oblt-cli for use in GitHub Actions workflows.

## Inputs
<!--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` | ` ` |
<!--/inputs-->

## Usage
Expand Down
4 changes: 4 additions & 0 deletions oblt-cli/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: >
Expand Down
15 changes: 15 additions & 0 deletions oblt-cli/setup/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Loading