diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 120332f..584180b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index ff3531e..4b91fbb 100644 --- a/README.md +++ b/README.md @@ -43,18 +43,18 @@ 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' -| `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' | -| `workdir` | The working directory in which to run the Dagger CLI | false | '.' | -| `cloud-token` | Dagger Cloud Token | false | '' | -| `module` | Dagger module to call. Local or Git | false | '' | -| `args` | Arguments to pass to CLI | false | '' | -| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' | -| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' | +| Key | Description | Required | Default | +| --------------- | ----------------------------------------------------------------- | -------- | ------------------ | +| `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' | +| `workdir` | The working directory in which to run the Dagger CLI | false | '.' | +| `cloud-token` | Dagger Cloud Token | false | '' | +| `module` | Dagger module to call. Local or Git | false | '' | +| `args` | Arguments to pass to CLI | false | '' | +| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' | +| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' | ### All output variables diff --git a/action.yml b/action.yml index 9d278ba..784824f 100644 --- a/action.yml +++ b/action.yml @@ -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 != ''