Files
xgj/trigger-version/examples/latest-version-demo.yml

66 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Latest Version Demo
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
show-version-info:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整历史,确保能获取所有标签
- name: Get Version Info
id: version
uses: ./trigger-version
with:
version-prefix: "v"
use-latest-version: true
- name: Display Version Information
run: |
echo "=== 版本信息详情 ==="
echo "引用类型: ${{ steps.version.outputs.ref-type }}"
echo "引用名称: ${{ steps.version.outputs.ref-name }}"
echo "完整引用: ${{ steps.version.outputs.full-ref }}"
echo ""
echo "=== 触发版本信息 ==="
echo "是否版本触发: ${{ steps.version.outputs.is-version-trigger }}"
echo "触发版本: ${{ steps.version.outputs.trigger-version }}"
echo "触发源: ${{ steps.version.outputs.trigger-source }}"
echo "版本(横线格式): ${{ steps.version.outputs.version-with-dash }}"
echo ""
echo "=== 最新版本信息 ==="
echo "最新版本: ${{ steps.version.outputs.latest-version }}"
echo "最新版本(横线格式): ${{ steps.version.outputs.latest-version-with-dash }}"
- name: Use Latest Version in Deployment
if: steps.version.outputs.latest-version != ''
run: |
echo "使用最新版本进行部署: ${{ steps.version.outputs.latest-version }}"
echo "镜像标签: myapp:${{ steps.version.outputs.latest-version-with-dash }}"
# 示例:构建 Docker 镜像
# docker build -t myapp:${{ steps.version.outputs.latest-version-with-dash }} .
# 示例:设置 Kubernetes 部署
# kubectl set image deployment/myapp container=myapp:${{ steps.version.outputs.latest-version-with-dash }}
- name: Handle No Version Found
if: steps.version.outputs.latest-version == ''
run: |
echo "⚠️ 未找到任何版本标签"
echo "这可能是因为:"
echo "1. 仓库中没有版本标签"
echo "2. 版本标签不匹配指定的前缀"
echo "3. Git 获取标签失败"
echo ""
echo "建议:"
echo "1. 检查仓库是否有版本标签(如 v1.0.0"
echo "2. 确认版本前缀设置正确"
echo "3. 确保 fetch-depth: 0 以获取完整历史"