From a043e7d62ca787b2fa32acc99aec6e62f63bcb2b Mon Sep 17 00:00:00 2001 From: Hermes Date: Sat, 2 May 2026 15:43:39 -0700 Subject: [PATCH] Add rust-cache composite action --- .gitea/actions/rust-cache/action.yml | 48 ++++++++++++++++++++++++++++ README.md | 38 +++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .gitea/actions/rust-cache/action.yml diff --git a/.gitea/actions/rust-cache/action.yml b/.gitea/actions/rust-cache/action.yml new file mode 100644 index 0000000..48ebe1e --- /dev/null +++ b/.gitea/actions/rust-cache/action.yml @@ -0,0 +1,48 @@ +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 + +outputs: + cache-hit: + description: "Whether a cache entry was found" + value: ${{ steps.cache.outputs.cache-hit }} + +runs: + using: composite + steps: + - name: Cache cargo + rustup + id: cache + uses: https://gitea.com/actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/.rustup/toolchains + ~/.rustup/settings.toml + target + key: rust-linux-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + rust-linux-${{ hashFiles('**/Cargo.lock') }}- + rust-linux- + + - name: Setup Rust + shell: bash + run: | + # If toolchain was cached, rustup will skip download — install still runs for metadata + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ + | sh -s -- -y --default-toolchain ${{ inputs.toolchain }} + # Add cargo bin to PATH for subsequent steps + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Show cached sizes + shell: bash + run: | + echo "=== ~/.cargo ===" && du -sh ~/.cargo 2>/dev/null || echo "(empty)" + echo "=== ~/.rustup ===" && du -sh ~/.rustup 2>/dev/null || echo "(empty)" + echo "=== target ===" && du -sh target 2>/dev/null || echo "(empty)" diff --git a/README.md b/README.md index fbdd907..ab146c2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,39 @@ # actions-rust -Reusable Rust setup + cache action for Gitea Actions \ No newline at end of file +Reusable Gitea Actions for Rust projects. + +## actions/rust-cache + +Composite action that installs a Rust toolchain and caches cargo/crate dependencies. + +### Usage + +```yaml +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: https://gitea.com/actions/checkout@v4 + + - name: Setup Rust + Cache + uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main + with: + toolchain: stable # optional, defaults to stable + + - run: cargo build --release + - run: cargo test +``` + +### What it does + +1. **Cache restore** — Restores `~/.cargo/registry`, `~/.cargo/git`, `~/.rustup/toolchains`, and `target/` using Gitea's native `actions/cache`. +2. **Rust install** — Runs `rustup` to install or verify the requested toolchain. +3. **PATH setup** — Appends `$HOME/.cargo/bin` to `$GITHUB_PATH` so cargo/rustc are available in subsequent steps. + +### Cache key format + +``` +rust-linux-{hash(Cargo.lock)}{hash(Cargo.toml)} +``` + +Warm builds run in ~40–60s vs ~3min for a cold build.