Skip to content
Open
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
44 changes: 42 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ inputs:
description: "Whether to write summary to GITHUB_STEP_SUMMARY"
required: false
default: "false"
cache-binary:
description: "Use actions/cache to cache the downloaded dagger binary"
required: false
default: "false"
outputs:
output:
description: "Job output"
Expand All @@ -67,7 +71,17 @@ outputs:
runs:
using: "composite"
steps:
- id: dagger-cache-restore
if: inputs.cache-binary == 'true'
uses: actions/cache/restore@v4
with:
path: ${{ runner.temp }}/dagger-cache
key: dagger-${{ runner.os }}-${{ inputs.version }}-${{ inputs.commit }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering what happens if version and commit both are specified?

For key should it be that OS + commit used if commit is specified, or OS + version if commit is not specified?
I could not find any checks that commit matches version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing:

  • What if version is "latest"
  • And commit is not specified

Does this means that we will use a cached latest version? Which will not be updated if latest changes?


- shell: bash
env:
CACHE_BINARY: ${{ inputs.cache-binary }}
CACHE_HIT: ${{ steps.dagger-cache-restore.outputs.cache-hit }}
run: |
set -o pipefail
# Fallback to /usr/local for backwards compatability
Expand Down Expand Up @@ -103,11 +117,37 @@ runs:
echo "::endgroup::"
fi

cache_dir="${RUNNER_TEMP:-/tmp}/dagger-cache"
if [[ "$CACHE_BINARY" == "true" && "$CACHE_HIT" == "true" && -x "${cache_dir}/bin/dagger" ]]; then
echo "::group::Installing dagger (from cache)"
mkdir -p "${prefix_dir}/bin"
cp "${cache_dir}/bin/dagger" "${prefix_dir}/bin/dagger"
chmod +x "${prefix_dir}/bin/dagger"
echo "Restored dagger from cache"
echo "::endgroup::"
exit 0
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
if [[ "$CACHE_BINARY" == "true" ]]; then
mkdir -p "${cache_dir}/bin" "${prefix_dir}/bin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to ensure these directories does not already exists? We could add a rm before just in case.

curl -fsSL https://dl.dagger.io/dagger/install.sh | \
BIN_DIR="${cache_dir}/bin" DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
cp "${cache_dir}/bin/dagger" "${prefix_dir}/bin/dagger"
chmod +x "${prefix_dir}/bin/dagger"
else
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
fi
echo "::endgroup::"

- id: dagger-cache-save
if: inputs.cache-binary == 'true' && steps.dagger-cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ runner.temp }}/dagger-cache
key: dagger-${{ runner.os }}-${{ inputs.version }}-${{ inputs.commit }}

- id: should-exec
shell: bash
env:
Expand Down