mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-15 00:13:37 +08:00
feat: 添加状态缓存管理 GitHub Action,支持多种操作模式(获取、设置、删除),实现缓存过期控制,优化状态管理逻辑,更新文档以反映新功能和使用示例。
This commit is contained in:
77
cache-state/examples/basic-usage.yml
Normal file
77
cache-state/examples/basic-usage.yml
Normal file
@@ -0,0 +1,77 @@
|
||||
# 基础使用示例
|
||||
# 演示如何使用 cache-state action 进行基本的状态管理
|
||||
|
||||
name: Cache State - 基础使用示例
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: '要设置的版本号'
|
||||
required: false
|
||||
default: 'v1.0.0'
|
||||
|
||||
jobs:
|
||||
demo-basic-usage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 获取或设置应用版本
|
||||
id: app-version
|
||||
uses: .actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'application-version'
|
||||
state-value: ${{ github.event.inputs.version }}
|
||||
default-value: 'v0.1.0'
|
||||
action: 'get-or-set'
|
||||
|
||||
- name: 显示版本信息
|
||||
run: |
|
||||
echo "🏷️ 应用版本: ${{ steps.app-version.outputs.state-value }}"
|
||||
echo "💾 缓存命中: ${{ steps.app-version.outputs.cache-hit }}"
|
||||
echo "🔄 使用默认值: ${{ steps.app-version.outputs.used-default }}"
|
||||
echo "🔑 缓存键: ${{ steps.app-version.outputs.cache-key }}"
|
||||
|
||||
- name: 基于版本信息的条件操作
|
||||
run: |
|
||||
if [[ "${{ steps.app-version.outputs.used-default }}" == "true" ]]; then
|
||||
echo "⚠️ 使用了默认版本,可能是首次运行"
|
||||
echo "执行初始化操作..."
|
||||
else
|
||||
echo "✅ 使用了已有版本或新设置的版本"
|
||||
echo "执行常规操作..."
|
||||
fi
|
||||
|
||||
- name: 记录构建状态
|
||||
uses: .actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'last-build-status'
|
||||
state-value: 'success'
|
||||
action: 'set'
|
||||
|
||||
- name: 获取构建历史
|
||||
id: build-history
|
||||
uses: .actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'build-count'
|
||||
state-value: '1'
|
||||
default-value: '0'
|
||||
action: 'get-or-set'
|
||||
|
||||
- name: 更新构建计数
|
||||
run: |
|
||||
CURRENT_COUNT=${{ steps.build-history.outputs.state-value }}
|
||||
NEW_COUNT=$((CURRENT_COUNT + 1))
|
||||
echo "当前构建次数: ${CURRENT_COUNT}"
|
||||
echo "新的构建次数: ${NEW_COUNT}"
|
||||
|
||||
- name: 保存新的构建计数
|
||||
uses: .actions/xgj/cache-state@v1
|
||||
with:
|
||||
state-key: 'build-count'
|
||||
state-value: ${{ env.NEW_COUNT }}
|
||||
action: 'set'
|
||||
env:
|
||||
NEW_COUNT: ${{ steps.build-history.outputs.state-value == '0' && '1' || format('{0}', steps.build-history.outputs.state-value + 1) }}
|
Reference in New Issue
Block a user