63 lines
2.0 KiB
YAML
63 lines
2.0 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
|
|
|
|
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: |
|
|
{
|
|
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 }}-${{ runner.os }}-${{ runner.arch }}-${{ inputs.toolchain }}-$HASH" >> $GITHUB_OUTPUT
|
|
echo "restore-prefix=${{ inputs.cache-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ inputs.toolchain }}-" >> $GITHUB_OUTPUT
|
|
|
|
- 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: 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
|