From 9bd1d0d01a5dabf8d933a960ca60702dc15ae0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Estev=C3=A3o?= Date: Mon, 7 Apr 2025 18:33:25 +0100 Subject: [PATCH 1/3] feat: add local cache storage --- action.yml | 42 +++++++++++++++++++++--------------------- localcache.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 21 deletions(-) create mode 100755 localcache.sh diff --git a/action.yml b/action.yml index a510371..c4576b6 100644 --- a/action.yml +++ b/action.yml @@ -77,31 +77,18 @@ runs: elixir-version: ${{ inputs.elixir-version }} otp-version: ${{ inputs.otp-version }} - - name: Get deps cache - uses: actions/cache@v4 - with: - path: deps/ - key: deps-${{ inputs.cache-key }}-${{ runner.os }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - deps-${{ inputs.cache-key }}-${{ runner.os }}- + # Restore cache before building + - name: Restore local cache + shell: bash + run: ${{ github.action_path }}/localcache.sh restore deps-${{ inputs.cache-key }}-${{ runner.os }} deps/ - name: Get build cache - uses: actions/cache@v4 - id: build-cache - with: - path: _build/${{env.MIX_ENV}}/ - key: build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}- + shell: bash + run: ${{ github.action_path }}/localcache.sh restore build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }} _build/${{env.MIX_ENV}}/ - name: Get Hex cache - uses: actions/cache@v4 - id: hex-cache - with: - path: ~/.hex - key: build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}- + shell: bash + run: ${{ github.action_path }}/localcache.sh restore hex-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }} ~/.hex # In my experience, I have issues with incremental builds maybe 1 in 100 # times that are fixed by doing a full recompile. @@ -145,6 +132,19 @@ runs: shell: sh if: inputs.build-app == 'true' + # Save cache after the build is done + - name: Save local deps cache + shell: bash + run: ${{ github.action_path }}/localcache.sh save deps-${{ inputs.cache-key }}-${{ runner.os }} deps/ + + - name: Save local build cache + shell: bash + run: ${{ github.action_path }}/localcache.sh save build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }} _build/${{env.MIX_ENV}}/ + + - name: Save local Hex cache + shell: bash + run: ${{ github.action_path }}/localcache.sh save hex-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }} ~/.hex + # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones # Cache key based on Elixir & Erlang version (also useful when running in matrix) - name: Restore PLT cache diff --git a/localcache.sh b/localcache.sh new file mode 100755 index 0000000..8475c5a --- /dev/null +++ b/localcache.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +MODE=$1 # "save" or "restore" +KEY=$2 # unique key for the cache (e.g. node_modules_hash123) +TARGET=$3 # path to directory to cache (e.g. node_modules/) +CACHE_DIR=/home/runner/cache + +if [[ -z "$MODE" || -z "$KEY" || -z "$TARGET" ]]; then + echo "Usage: $0 [save|restore] " + exit 1 +fi + +CACHE_PATH="$CACHE_DIR/$KEY" + +mkdir -p "$CACHE_DIR" + +if [ "$MODE" == "restore" ]; then + if [ -d "$CACHE_PATH" ]; then + echo "✅ Restoring cache from $CACHE_PATH → $TARGET" + mkdir -p "$TARGET" + cp -r "$CACHE_PATH/"* "$TARGET/" || true + else + echo "⚠️ No cache found for key: $KEY" + fi + +elif [ "$MODE" == "save" ]; then + echo "📦 Saving cache from $TARGET → $CACHE_PATH" + mkdir -p "$CACHE_PATH" + cp -r "$TARGET/"* "$CACHE_PATH/" || true +else + echo "❌ Invalid mode: $MODE" + exit 1 +fi From 24d40ac1e9e88a3c3576205840b5493762338e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Estev=C3=A3o?= Date: Tue, 8 Apr 2025 09:22:07 +0100 Subject: [PATCH 2/3] Revert "feat: add local cache storage" This reverts commit 9bd1d0d01a5dabf8d933a960ca60702dc15ae0e5. --- action.yml | 42 +++++++++++++++++++++--------------------- localcache.sh | 35 ----------------------------------- 2 files changed, 21 insertions(+), 56 deletions(-) delete mode 100755 localcache.sh diff --git a/action.yml b/action.yml index c4576b6..a510371 100644 --- a/action.yml +++ b/action.yml @@ -77,18 +77,31 @@ runs: elixir-version: ${{ inputs.elixir-version }} otp-version: ${{ inputs.otp-version }} - # Restore cache before building - - name: Restore local cache - shell: bash - run: ${{ github.action_path }}/localcache.sh restore deps-${{ inputs.cache-key }}-${{ runner.os }} deps/ + - name: Get deps cache + uses: actions/cache@v4 + with: + path: deps/ + key: deps-${{ inputs.cache-key }}-${{ runner.os }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + deps-${{ inputs.cache-key }}-${{ runner.os }}- - name: Get build cache - shell: bash - run: ${{ github.action_path }}/localcache.sh restore build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }} _build/${{env.MIX_ENV}}/ + uses: actions/cache@v4 + id: build-cache + with: + path: _build/${{env.MIX_ENV}}/ + key: build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}- - name: Get Hex cache - shell: bash - run: ${{ github.action_path }}/localcache.sh restore hex-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }} ~/.hex + uses: actions/cache@v4 + id: hex-cache + with: + path: ~/.hex + key: build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}- # In my experience, I have issues with incremental builds maybe 1 in 100 # times that are fixed by doing a full recompile. @@ -132,19 +145,6 @@ runs: shell: sh if: inputs.build-app == 'true' - # Save cache after the build is done - - name: Save local deps cache - shell: bash - run: ${{ github.action_path }}/localcache.sh save deps-${{ inputs.cache-key }}-${{ runner.os }} deps/ - - - name: Save local build cache - shell: bash - run: ${{ github.action_path }}/localcache.sh save build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }} _build/${{env.MIX_ENV}}/ - - - name: Save local Hex cache - shell: bash - run: ${{ github.action_path }}/localcache.sh save hex-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }} ~/.hex - # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones # Cache key based on Elixir & Erlang version (also useful when running in matrix) - name: Restore PLT cache diff --git a/localcache.sh b/localcache.sh deleted file mode 100755 index 8475c5a..0000000 --- a/localcache.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -e - -MODE=$1 # "save" or "restore" -KEY=$2 # unique key for the cache (e.g. node_modules_hash123) -TARGET=$3 # path to directory to cache (e.g. node_modules/) -CACHE_DIR=/home/runner/cache - -if [[ -z "$MODE" || -z "$KEY" || -z "$TARGET" ]]; then - echo "Usage: $0 [save|restore] " - exit 1 -fi - -CACHE_PATH="$CACHE_DIR/$KEY" - -mkdir -p "$CACHE_DIR" - -if [ "$MODE" == "restore" ]; then - if [ -d "$CACHE_PATH" ]; then - echo "✅ Restoring cache from $CACHE_PATH → $TARGET" - mkdir -p "$TARGET" - cp -r "$CACHE_PATH/"* "$TARGET/" || true - else - echo "⚠️ No cache found for key: $KEY" - fi - -elif [ "$MODE" == "save" ]; then - echo "📦 Saving cache from $TARGET → $CACHE_PATH" - mkdir -p "$CACHE_PATH" - cp -r "$TARGET/"* "$CACHE_PATH/" || true -else - echo "❌ Invalid mode: $MODE" - exit 1 -fi From cde5ca41dca76996500e08404c6a7e6d1006d703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Estev=C3=A3o?= Date: Tue, 8 Apr 2025 09:25:18 +0100 Subject: [PATCH 3/3] feat: use local cache action --- action.yml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/action.yml b/action.yml index a510371..1512710 100644 --- a/action.yml +++ b/action.yml @@ -78,30 +78,18 @@ runs: otp-version: ${{ inputs.otp-version }} - name: Get deps cache - uses: actions/cache@v4 + uses: corca-ai/local-cache@v2 with: + base: /home/runner/.cache/actions path: deps/ - key: deps-${{ inputs.cache-key }}-${{ runner.os }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - deps-${{ inputs.cache-key }}-${{ runner.os }}- + key: deps-${{ runner.os }}-${{ hashFiles('**/mix.lock') }} - name: Get build cache - uses: actions/cache@v4 - id: build-cache + uses: corca-ai/local-cache@v2 with: + base: /home/runner/.cache/actions path: _build/${{env.MIX_ENV}}/ - key: build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - build-${{ inputs.cache-key }}-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}- - - - name: Get Hex cache - uses: actions/cache@v4 - id: hex-cache - with: - path: ~/.hex - key: build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}- + key: build-${{ runner.os }}-${{ inputs.otp-version }}-${{ inputs.elixir-version }}-${{ env.MIX_ENV }}-${{ hashFiles('**/mix.lock') }} # In my experience, I have issues with incremental builds maybe 1 in 100 # times that are fixed by doing a full recompile.