mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 03:53:37 +08:00
feat: 更新 test-cache-state 和 cache-state GitHub Action,修正缓存键格式验证逻辑,确保在不同运行环境下正确识别缓存键,同时增强输出信息以便于调试和监控缓存状态。
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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 }}"
|
||||
|
Reference in New Issue
Block a user