Simplify: cache rustup toolchains, skip rust install on cache hit
Some checks failed
Rust Build / build (push) Failing after 35s
Some checks failed
Rust Build / build (push) Failing after 35s
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: Rust Build Cache Test
|
name: Rust Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -17,54 +17,32 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: https://gitea.com/actions/checkout@v4
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
run: |
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
|
||||||
source "$HOME/.cargo/env"
|
|
||||||
|
|
||||||
- name: Get Cargo lock hash
|
- name: Get Cargo lock hash
|
||||||
id: hash
|
id: hash
|
||||||
run: |
|
run: |
|
||||||
source "$HOME/.cargo/env"
|
|
||||||
echo "hash=$(cat Cargo.lock Cargo.toml | sha256sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
|
echo "hash=$(cat Cargo.lock Cargo.toml | sha256sum | cut -d' ' -f1)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Cache cargo
|
- name: Cache cargo + rustup
|
||||||
|
id: cache
|
||||||
uses: https://gitea.com/actions/cache@v3
|
uses: https://gitea.com/actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
|
~/.rustup/toolchains
|
||||||
|
~/.rustup/settings.toml
|
||||||
target
|
target
|
||||||
key: rust-${{ runner.os }}-${{ steps.hash.outputs.hash }}
|
key: rust-${{ runner.os }}-${{ steps.hash.outputs.hash }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
rust-${{ runner.os }}-
|
rust-${{ runner.os }}-
|
||||||
|
|
||||||
- name: Show cache info (before build)
|
- name: Setup Rust
|
||||||
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
source "$HOME/.cargo/env"
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
||||||
echo "=== Cache Key ==="
|
|
||||||
echo "rust-${{ runner.os }}-${{ steps.hash.outputs.hash }}"
|
|
||||||
echo ""
|
|
||||||
echo "=== Cargo cache directories (before build) ==="
|
|
||||||
du -sh ~/.cargo/registry ~/.cargo/git target 2>/dev/null || echo "Dirs not yet present"
|
|
||||||
echo ""
|
|
||||||
echo "=== Cargo/Rust versions ==="
|
|
||||||
cargo --version
|
|
||||||
rustc --version
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: cargo build --verbose
|
||||||
source "$HOME/.cargo/env"
|
|
||||||
cargo build --verbose
|
|
||||||
|
|
||||||
- name: Run
|
- name: Run
|
||||||
run: |
|
run: cargo run
|
||||||
source "$HOME/.cargo/env"
|
|
||||||
cargo run
|
|
||||||
|
|
||||||
- name: Check cache after build
|
|
||||||
run: |
|
|
||||||
echo "=== After build ==="
|
|
||||||
echo "~/.cargo/registry: $(du -sh ~/.cargo/registry 2>/dev/null | cut -f1)"
|
|
||||||
echo "~/.cargo/git: $(du -sh ~/.cargo/git 2>/dev/null | cut -f1)"
|
|
||||||
echo "target: $(du -sh target 2>/dev/null | cut -f1)"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user