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: # Gitea Actions does not have Cargo.lock by default (cargo generates it on first build), # and hashFiles() globs don't work reliably here. Use shell hashing instead. - name: Compute cache key id: cache-key shell: bash run: | # Hash both files; if Cargo.lock doesn't exist yet, only Cargo.toml is hashed HASH=$( (cat Cargo.toml 2>/dev/null || true; cat Cargo.lock 2>/dev/null || true) | sha256sum | cut -d' ' -f1) echo "hash=$HASH" >> $GITHUB_OUTPUT echo "fingerprint=$HASH" >> $GITHUB_ENV - 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 sizes before cache shell: bash run: | echo "=== ~/.cargo ===" && du -sh ~/.cargo 2>/dev/null || echo "(empty)" echo "=== ~/.rustup ===" && du -sh ~/.rustup 2>/dev/null || echo "(empty)" - name: Save cache id: cache-save 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: rust-linux-${{ steps.cache-key.outputs.hash }} save-always: true - name: Debug: print save outputs shell: bash run: | echo "=== Save action outputs ===" echo "cache-hit: '${{ steps.cache-save.outputs.cache-hit }}'" echo "key: '${{ steps.cache-save.outputs.key }}'" echo "=== All outputs ===" env | grep -i ACTIONS_CACHE || echo "No ACTIONS_CACHE env vars in shell" - name: Twirp probe via curl (debug) shell: bash env: ACTIONS_CACHE_URL: ${{ env.ACTIONS_CACHE_URL }} ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }} ACTIONS_RESULTS_URL: ${{ env.ACTIONS_RESULTS_URL }} run: | echo "=== Cache env vars ===" echo "ACTIONS_CACHE_URL=$ACTIONS_CACHE_URL" echo "ACTIONS_RUNTIME_TOKEN len=${#ACTIONS_RUNTIME_TOKEN}" if [ -n "$ACTIONS_CACHE_URL" ]; then HASH="${{ steps.cache-key.outputs.hash }}" KEY="rust-linux-$HASH" echo "=== Twirp v1: GetCacheEntryDownloadURL ===" BODY=$(printf '{"key":"%s","restoreKeys":[],"version":"%s"}' "$KEY" "$HASH") echo "POST $ACTIONS_CACHE_URL/twirp/github.actions.results.api.v1.CacheService/GetCacheEntryDownloadURL" echo "Body: $BODY" RESP=$(curl -si -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \ "$ACTIONS_CACHE_URL/twirp/github.actions.results.api.v1.CacheService/GetCacheEntryDownloadURL" \ -d "$BODY" \ 2>&1) echo "$RESP" echo "" echo "=== Also try list cache API ===" LIST_RESP=$(curl -si \ -H "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \ "$ACTIONS_CACHE_URL/_apis/artifactcache/caches?key=$KEY&version=$HASH" \ 2>&1) echo "$LIST_RESP" else echo "ACTIONS_CACHE_URL is empty" fi - name: Lookup same key immediately after save id: cache-lookup env: ACTIONS_CACHE_URL: ${{ env.ACTIONS_CACHE_URL }} ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }} ACTIONS_CACHE_SERVICE_V2: "0" ACTIONS_RESULTS_URL: ${{ env.ACTIONS_RESULTS_URL }} uses: https://gitea.com/actions/cache@v3 with: path: ~/.cargo/registry key: rust-linux-${{ steps.cache-key.outputs.hash }} lookup-only: true - name: Show sizes after cache shell: bash run: | echo "=== ~/.cargo ===" && du -sh ~/.cargo 2>/dev/null || echo "(empty)" echo "=== ~/.rustup ===" && du -sh ~/.rustup 2>/dev/null || echo "(empty)" echo "save result: ${{ steps.cache-save.outputs.cache-hit }}" echo "lookup result: ${{ steps.cache-lookup.outputs.cache-hit }}" echo "ACTIONS_CACHE_URL=$ACTIONS_CACHE_URL"