Skip to content

Commit d913e70

Browse files
authored
avoid downloading dagger if requested version is already installed (#187)
* avoid overwriting existing dagger install unless force-install is true Signed-off-by: kpenfound <[email protected]> * add force-install to version tests Signed-off-by: kpenfound <[email protected]> * only skip install if we requested the same version that we already had Signed-off-by: kpenfound <[email protected]> * fix dagger check logic Signed-off-by: kpenfound <[email protected]> * remove incorrect and unused default for engine-stop Signed-off-by: kpenfound <[email protected]> * add tests for commit and latest Signed-off-by: kpenfound <[email protected]> * wrong commit in commit test Signed-off-by: kpenfound <[email protected]> --------- Signed-off-by: kpenfound <[email protected]>
1 parent 055bb3b commit d913e70

File tree

3 files changed

+94
-17
lines changed

3 files changed

+94
-17
lines changed

.github/workflows/test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,66 @@ jobs:
248248
- name: "Test Install"
249249
run: |
250250
dagger core version
251+
252+
existing-install:
253+
runs-on: "ubuntu-latest"
254+
steps:
255+
- uses: actions/checkout@v4
256+
- name: "preinstall dagger"
257+
run: |
258+
curl -fsS https://dl.dagger.io/dagger/install.sh \
259+
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
260+
- name: "Install with version"
261+
uses: ./
262+
with:
263+
version: "v0.18.16"
264+
- name: "Test Install"
265+
run: |
266+
if [[ "$(dagger core version)" == "v0.18.16" ]]; then
267+
exit 0
268+
else
269+
echo "Existing install was not overridden"
270+
exit 1
271+
fi
272+
273+
commit-install:
274+
runs-on: "ubuntu-latest"
275+
steps:
276+
- uses: actions/checkout@v4
277+
- name: "preinstall dagger"
278+
run: |
279+
curl -fsS https://dl.dagger.io/dagger/install.sh \
280+
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
281+
- name: "Install with version"
282+
uses: ./
283+
with:
284+
commit: "71f2e104b045ddc3b0cc611b81370707bf21bc27"
285+
- name: "Test Install"
286+
run: |
287+
if [[ "$(dagger version)" == *"v0.18.19-250918123923-71f2e104b045"* ]]; then
288+
exit 0
289+
else
290+
echo "Existing install was not overridden"
291+
exit 1
292+
fi
293+
294+
latest-install:
295+
runs-on: "ubuntu-latest"
296+
steps:
297+
- uses: actions/checkout@v4
298+
- name: "preinstall dagger"
299+
run: |
300+
curl -fsS https://dl.dagger.io/dagger/install.sh \
301+
| BIN_DIR=/usr/local/bin DAGGER_VERSION="v0.18.17" sh
302+
- name: "Install with version"
303+
uses: ./
304+
with:
305+
version: "latest"
306+
- name: "Test Install"
307+
run: |
308+
if [[ "$(dagger version)" != "v0.18.17" ]]; then
309+
exit 0
310+
else
311+
echo "Existing install was not overridden with latest"
312+
exit 1
313+
fi

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ By setting the version to `latest`, this action will install the latest version
4343

4444
### All `with:` input parameter options
4545

46-
| Key | Description | Required | Default |
47-
| -------------- | ----------------------------------------------------------- | -------- | ------------------ |
48-
| `version` | Dagger Version | true | n/a use semver x.y.z or 'latest'
49-
| `commit` | Dagger Dev Commit (overrides `version`) | false | '' |
50-
| `dagger-flags` | Dagger CLI Flags | false | '--progress plain' |
51-
| `verb` | CLI verb (call, run, download, up, functions, shell, query) | false | 'call' |
52-
| `workdir` | The working directory in which to run the Dagger CLI | false | '.' |
53-
| `cloud-token` | Dagger Cloud Token | false | '' |
54-
| `module` | Dagger module to call. Local or Git | false | '' |
55-
| `args` | Arguments to pass to CLI | false | '' |
56-
| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' |
57-
| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' |
46+
| Key | Description | Required | Default |
47+
| --------------- | ----------------------------------------------------------------- | -------- | ------------------ |
48+
| `version` | Dagger Version. Use semver vX.Y.Z or 'latest' | true | 'latest' |
49+
| `commit` | Dagger Dev Commit (overrides `version`) | false | '' |
50+
| `dagger-flags` | Dagger CLI Flags | false | '--progress plain' |
51+
| `verb` | CLI verb (call, run, download, up, functions, shell, query) | false | 'call' |
52+
| `workdir` | The working directory in which to run the Dagger CLI | false | '.' |
53+
| `cloud-token` | Dagger Cloud Token | false | '' |
54+
| `module` | Dagger module to call. Local or Git | false | '' |
55+
| `args` | Arguments to pass to CLI | false | '' |
56+
| `call` | Arguments to pass to CLI (Alias for args with verb:call) | false | '' |
57+
| `shell` | Arguments to pass to CLI (Alias for args with verb:shell) | false | '' |
5858

5959
### All output variables
6060

action.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: "Dagger for GitHub"
22
description: "Run dagger commands in Github Actions"
33
inputs:
44
version:
5-
description: "Dagger Version"
6-
required: true
5+
description: "Dagger Version. Use semver vX.Y.Z or 'latest'"
6+
required: false
7+
default: "latest"
78
commit:
89
description: "Dagger Dev Commit"
910
required: false
@@ -72,12 +73,25 @@ runs:
7273
if [[ "$VERSION" == "latest" ]]; then
7374
VERSION=
7475
fi
76+
latest=$(curl https://dl.dagger.io/dagger/versions/latest)
7577
7678
COMMIT=${{ inputs.commit }}
7779
78-
# The install.sh script creates path ${prefix_dir}/bin
79-
curl -fsS https://dl.dagger.io/dagger/install.sh \
80-
| BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
80+
if [[ -x "$(command -v dagger)" ]]; then
81+
echo "::group::Checking dagger"
82+
version="$(dagger --silent version | cut --fields 2 --delimiter ' ')"
83+
echo "Found existing dagger version: $version"
84+
if [[ "$version" == "$VERSION" ]] || [[ "$version" == "$latest" ]]; then
85+
echo "dagger ${version} is already installed, skipping installation"
86+
exit 0
87+
fi
88+
echo "::endgroup::"
89+
fi
90+
91+
echo "::group::Installing dagger"
92+
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
93+
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
94+
echo "::endgroup::"
8195
8296
- id: assemble
8397
if: inputs.call != '' || inputs.shell != '' || inputs.args != ''

0 commit comments

Comments
 (0)