Skip to content

Commit f9dfe7e

Browse files
committed
Cache & restore the archive
1 parent 456fc3a commit f9dfe7e

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

action.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ inputs:
5757
description: "Whether to write summary to GITHUB_STEP_SUMMARY"
5858
required: false
5959
default: "false"
60+
cache-binary:
61+
description: "Use actions/cache to cache the downloaded dagger binary"
62+
required: false
63+
default: "false"
6064
outputs:
6165
output:
6266
description: "Job output"
@@ -67,7 +71,17 @@ outputs:
6771
runs:
6872
using: "composite"
6973
steps:
74+
- id: dagger-cache-restore
75+
if: inputs.cache-binary == 'true'
76+
uses: actions/cache/restore@v4
77+
with:
78+
path: ${{ runner.temp }}/dagger-cache
79+
key: dagger-${{ runner.os }}-${{ inputs.version }}-${{ inputs.commit }}
80+
7081
- shell: bash
82+
env:
83+
CACHE_BINARY: ${{ inputs.cache-binary }}
84+
CACHE_HIT: ${{ steps.dagger-cache-restore.outputs.cache-hit }}
7185
run: |
7286
set -o pipefail
7387
# Fallback to /usr/local for backwards compatability
@@ -103,11 +117,37 @@ runs:
103117
echo "::endgroup::"
104118
fi
105119
120+
cache_dir="${RUNNER_TEMP:-/tmp}/dagger-cache"
121+
if [[ "$CACHE_BINARY" == "true" && "$CACHE_HIT" == "true" && -x "${cache_dir}/bin/dagger" ]]; then
122+
echo "::group::Installing dagger (from cache)"
123+
mkdir -p "${prefix_dir}/bin"
124+
cp "${cache_dir}/bin/dagger" "${prefix_dir}/bin/dagger"
125+
chmod +x "${prefix_dir}/bin/dagger"
126+
echo "Restored dagger from cache"
127+
echo "::endgroup::"
128+
exit 0
129+
fi
130+
106131
echo "::group::Installing dagger"
107-
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
108-
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
132+
if [[ "$CACHE_BINARY" == "true" ]]; then
133+
mkdir -p "${cache_dir}/bin" "${prefix_dir}/bin"
134+
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
135+
BIN_DIR="${cache_dir}/bin" DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
136+
cp "${cache_dir}/bin/dagger" "${prefix_dir}/bin/dagger"
137+
chmod +x "${prefix_dir}/bin/dagger"
138+
else
139+
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
140+
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
141+
fi
109142
echo "::endgroup::"
110143
144+
- id: dagger-cache-save
145+
if: inputs.cache-binary == 'true' && steps.dagger-cache-restore.outputs.cache-hit != 'true'
146+
uses: actions/cache/save@v4
147+
with:
148+
path: ${{ runner.temp }}/dagger-cache
149+
key: dagger-${{ runner.os }}-${{ inputs.version }}-${{ inputs.commit }}
150+
111151
- id: should-exec
112152
shell: bash
113153
env:

0 commit comments

Comments
 (0)