Files
actions-rust/.gitea/actions/rust-cache/action.yml

80 lines
2.7 KiB
YAML

name: Rust Setup + Cache
description: Install Rust toolchain and cache cargo/rustup dependencies for Gitea Actions
author: eric
inputs:
toolchain:
description: Rust toolchain to install (e.g., stable, 1.75.0, nightly)
default: stable
required: false
cache-prefix:
description: Prefix for cache keys.
default: rust
required: false
cache-version:
description: Cache format version. Bump this to avoid reusing stale or partial cache entries.
default: v3
required: false
outputs:
cache-hit:
description: "Whether a cache entry was found"
value: ${{ steps.cache-restore.outputs.cache-hit }}
runs:
using: composite
steps:
- name: Compute cache key
id: cache-key
shell: bash
run: |
OS=$(printf '%s' '${{ runner.os }}' | tr '[:upper:]' '[:lower:]')
ARCH=$(printf '%s' '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')
{
printf 'toolchain=%s\n' '${{ inputs.toolchain }}'
find . \
\( -path './.git' -o -path './target' \) -prune -o \
\( -name Cargo.toml -o -name Cargo.lock -o -name rust-toolchain -o -name rust-toolchain.toml \) \
-type f -print0 \
| sort -z \
| xargs -0 sha256sum 2>/dev/null || true
} > /tmp/rust-cache-fingerprint
HASH=$(sha256sum /tmp/rust-cache-fingerprint | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "key=${{ inputs.cache-prefix }}-${{ inputs.cache-version }}-$OS-$ARCH-${{ inputs.toolchain }}-$HASH" >> $GITHUB_OUTPUT
echo "restore-prefix=${{ inputs.cache-prefix }}-${{ inputs.cache-version }}-$OS-$ARCH-${{ inputs.toolchain }}-" >> $GITHUB_OUTPUT
- name: Configure cache upload
shell: bash
run: |
echo "CACHE_UPLOAD_CONCURRENCY=1" >> "$GITHUB_ENV"
- name: Restore Rust cache
id: cache-restore
env:
ACTIONS_CACHE_SERVICE_V2: "0"
uses: https://gitea.com/actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.rustup/toolchains
~/.rustup/settings.toml
target
key: ${{ steps.cache-key.outputs.key }}
restore-keys: |
${{ steps.cache-key.outputs.restore-prefix }}
- name: Show Rust cache status
shell: bash
run: |
echo "Rust cache key: ${{ steps.cache-key.outputs.key }}"
echo "Rust cache hit: ${{ steps.cache-restore.outputs.cache-hit }}"
- name: Setup Rust
shell: bash
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain ${{ inputs.toolchain }}
echo "$HOME/.cargo/bin" >> $GITHUB_PATH