avoid downloading dagger if requested version is already installed (#187)

* avoid overwriting existing dagger install unless force-install is true

Signed-off-by: kpenfound <kyle@dagger.io>

* add force-install to version tests

Signed-off-by: kpenfound <kyle@dagger.io>

* only skip install if we requested the same version that we already had

Signed-off-by: kpenfound <kyle@dagger.io>

* fix dagger check logic

Signed-off-by: kpenfound <kyle@dagger.io>

* remove incorrect and unused default for engine-stop

Signed-off-by: kpenfound <kyle@dagger.io>

* add tests for commit and latest

Signed-off-by: kpenfound <kyle@dagger.io>

* wrong commit in commit test

Signed-off-by: kpenfound <kyle@dagger.io>

---------

Signed-off-by: kpenfound <kyle@dagger.io>
This commit is contained in:
Kyle Penfound 2025-09-22 12:04:05 -04:00 committed by GitHub
parent 055bb3b2af
commit d913e70051
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 94 additions and 17 deletions

View file

@ -248,3 +248,66 @@ jobs:
- name: "Test Install"
run: |
dagger core version
existing-install:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "preinstall dagger"
run: |
curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
- name: "Install with version"
uses: ./
with:
version: "v0.18.16"
- name: "Test Install"
run: |
if [[ "$(dagger core version)" == "v0.18.16" ]]; then
exit 0
else
echo "Existing install was not overridden"
exit 1
fi
commit-install:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "preinstall dagger"
run: |
curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
- name: "Install with version"
uses: ./
with:
commit: "71f2e104b045ddc3b0cc611b81370707bf21bc27"
- name: "Test Install"
run: |
if [[ "$(dagger version)" == *"v0.18.19-250918123923-71f2e104b045"* ]]; then
exit 0
else
echo "Existing install was not overridden"
exit 1
fi
latest-install:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: "preinstall dagger"
run: |
curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
- name: "Install with version"
uses: ./
with:
version: "latest"
- name: "Test Install"
run: |
if [[ "$(dagger version)" != "v0.18.17" ]]; then
exit 0
else
echo "Existing install was not overridden with latest"
exit 1
fi

View file

@ -44,8 +44,8 @@ By setting the version to `latest`, this action will install the latest version
### All `with:` input parameter options
| Key | Description | Required | Default |
| -------------- | ----------------------------------------------------------- | -------- | ------------------ |
| `version` | Dagger Version | true | n/a use semver x.y.z or 'latest'
| --------------- | ----------------------------------------------------------------- | -------- | ------------------ |
| `version` | Dagger Version. Use semver vX.Y.Z or 'latest' | true | 'latest' |
| `commit` | Dagger Dev Commit (overrides `version`) | false | '' |
| `dagger-flags` | Dagger CLI Flags | false | '--progress plain' |
| `verb` | CLI verb (call, run, download, up, functions, shell, query) | false | 'call' |

View file

@ -2,8 +2,9 @@ name: "Dagger for GitHub"
description: "Run dagger commands in Github Actions"
inputs:
version:
description: "Dagger Version"
required: true
description: "Dagger Version. Use semver vX.Y.Z or 'latest'"
required: false
default: "latest"
commit:
description: "Dagger Dev Commit"
required: false
@ -72,12 +73,25 @@ runs:
if [[ "$VERSION" == "latest" ]]; then
VERSION=
fi
latest=$(curl https://dl.dagger.io/dagger/versions/latest)
COMMIT=${{ inputs.commit }}
# The install.sh script creates path ${prefix_dir}/bin
curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
if [[ -x "$(command -v dagger)" ]]; then
echo "::group::Checking dagger"
version="$(dagger --silent version | cut --fields 2 --delimiter ' ')"
echo "Found existing dagger version: $version"
if [[ "$version" == "$VERSION" ]] || [[ "$version" == "$latest" ]]; then
echo "dagger ${version} is already installed, skipping installation"
exit 0
fi
echo "::endgroup::"
fi
echo "::group::Installing dagger"
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
echo "::endgroup::"
- id: assemble
if: inputs.call != '' || inputs.shell != '' || inputs.args != ''