From 7f178d1e30d3e7bae6fd1b9a832a806bbe45d8dd Mon Sep 17 00:00:00 2001 From: Lyda <1829913225@qq.com> Date: Thu, 21 Aug 2025 12:22:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20test-cache-state?= =?UTF-8?q?=20=E5=92=8C=20cache-state=20GitHub=20Action=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E7=BC=93=E5=AD=98=E9=94=AE=E6=A0=BC=E5=BC=8F=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83=E4=B8=8B?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=AF=86=E5=88=AB=E7=BC=93=E5=AD=98=E9=94=AE?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A2=9E=E5=BC=BA=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=BB=A5=E4=BE=BF=E4=BA=8E=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=92=8C=E7=9B=91=E6=8E=A7=E7=BC=93=E5=AD=98=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/test-cache-state.yml | 8 ++++---- cache-state/action.yml | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/test-cache-state.yml b/.gitea/workflows/test-cache-state.yml index b1ca312..7748b71 100644 --- a/.gitea/workflows/test-cache-state.yml +++ b/.gitea/workflows/test-cache-state.yml @@ -66,8 +66,8 @@ jobs: exit 1 fi - # 验证缓存键格式 - if [[ "${{ steps.basic-test.outputs.cache-key }}" =~ ^ubuntu-latest-.*-basic-test-.* ]]; then + # 验证缓存键格式(runner.os 在 ubuntu 运行器上返回 "Linux") + if [[ "${{ steps.basic-test.outputs.cache-key }}" =~ ^Linux-.*-basic-test-.* ]]; then echo "✅ 缓存键格式正确" else echo "❌ 缓存键格式不正确: ${{ steps.basic-test.outputs.cache-key }}" @@ -364,7 +364,7 @@ jobs: if [[ "${{ steps.short-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]]; then echo "✅ 缓存键包含时间窗口标识" else - echo "❌ 缓存键缺少时间窗口标识" + echo "❌ 缓存键缺少时间窗口标识: ${{ steps.short-expiry.outputs.cache-key }}" exit 1 fi @@ -390,7 +390,7 @@ jobs: if [[ ! "${{ steps.no-expiry.outputs.cache-key }}" =~ -[0-9]+$ ]]; then echo "✅ 永不过期缓存键格式正确" else - echo "❌ 永不过期缓存键不应包含时间窗口" + echo "❌ 永不过期缓存键不应包含时间窗口: ${{ steps.no-expiry.outputs.cache-key }}" exit 1 fi diff --git a/cache-state/action.yml b/cache-state/action.yml index 1036f9a..5b02334 100644 --- a/cache-state/action.yml +++ b/cache-state/action.yml @@ -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 }}"