feat: 更新 test-cache-state 和 cache-state GitHub Action,修正缓存键格式验证逻辑,确保在不同运行环境下正确识别缓存键,同时增强输出信息以便于调试和监控缓存状态。

This commit is contained in:
Lyda
2025-08-21 12:22:22 +08:00
parent ef9d766ecb
commit 7f178d1e30
2 changed files with 11 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ outputs:
cache-hit:
description: '是否命中缓存 (true/false)'
value: ${{ steps.cache-get.outputs.cache-hit || steps.cache-set.outputs.cache-hit }}
value: ${{ steps.result.outputs.cache-hit }}
used-default:
description: '是否使用了默认值 (true/false)'
@@ -164,6 +164,7 @@ runs:
USED_DEFAULT="false"
EXPIRED="false"
DELETED="false"
CACHE_HIT="false"
FINAL_VALUE=""
# 判断是否因过期而未命中缓存
@@ -175,6 +176,7 @@ runs:
"get")
if [[ "${{ steps.cache-get.outputs.cache-hit }}" == "true" && -n "${{ steps.read-cached.outputs.value }}" ]]; then
FINAL_VALUE="${{ steps.read-cached.outputs.value }}"
CACHE_HIT="true"
echo "✅ 获取模式: 使用缓存值"
else
FINAL_VALUE="${{ inputs.default-value }}"
@@ -195,6 +197,7 @@ runs:
"get-or-set")
if [[ "${{ steps.cache-get.outputs.cache-hit }}" == "true" && -n "${{ steps.read-cached.outputs.value }}" ]]; then
FINAL_VALUE="${{ steps.read-cached.outputs.value }}"
CACHE_HIT="true"
echo "✅ 获取或设置模式: 使用缓存值"
else
if [[ -n "${{ inputs.state-value }}" ]]; then
@@ -220,6 +223,7 @@ runs:
DELETED="true"
FINAL_VALUE=""
if [[ "${{ steps.cache-get.outputs.cache-hit }}" == "true" && -n "${{ steps.read-cached.outputs.value }}" ]]; then
CACHE_HIT="true"
echo "🗑️ 删除模式: 删除现有缓存状态"
else
echo "🗑️ 删除模式: 状态不存在,执行删除标记"
@@ -231,6 +235,7 @@ runs:
echo "used-default=${USED_DEFAULT}" >> $GITHUB_OUTPUT
echo "expired=${EXPIRED}" >> $GITHUB_OUTPUT
echo "deleted=${DELETED}" >> $GITHUB_OUTPUT
echo "cache-hit=${CACHE_HIT}" >> $GITHUB_OUTPUT
- name: 保存状态到缓存
if: (inputs.action == 'set') || (inputs.action == 'get-or-set' && steps.cache-get.outputs.cache-hit != 'true') || (inputs.action == 'del')
@@ -273,7 +278,7 @@ runs:
echo " - 操作类型: ${{ inputs.action }}"
echo " - 状态键名: ${{ inputs.state-key }}"
echo " - 缓存键名: ${{ steps.cache-key.outputs.key }}"
echo " - 缓存命中: ${{ steps.cache-get.outputs.cache-hit || steps.cache-set.outputs.cache-hit || 'N/A' }}"
echo " - 缓存命中: ${{ steps.result.outputs.cache-hit }}"
echo " - 使用默认值: ${{ steps.result.outputs.used-default }}"
echo " - 缓存过期: ${{ steps.result.outputs.expired }}"
echo " - 执行删除: ${{ steps.result.outputs.deleted }}"