mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 16:53:37 +08:00
feat: 添加触发版本信息的 GitHub Action,支持标签、版本分支和常规分支触发,提供详细的输出信息和环境变量,更新文档以反映新功能和使用示例。
This commit is contained in:
135
trigger-version/examples/custom-prefix.yml
Normal file
135
trigger-version/examples/custom-prefix.yml
Normal file
@@ -0,0 +1,135 @@
|
||||
# 自定义版本前缀示例
|
||||
# 这个示例展示了如何使用不同的版本前缀
|
||||
|
||||
name: Custom Version Prefix
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['main', 'release-*']
|
||||
tags: ['release-*', 'hotfix-*']
|
||||
|
||||
jobs:
|
||||
# 使用默认前缀 'v' 的标准版本
|
||||
standard-version:
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 获取标准版本信息
|
||||
id: standard-version
|
||||
uses: ./trigger-version
|
||||
# 使用默认的 'v' 前缀
|
||||
|
||||
- name: 显示标准版本信息
|
||||
run: |
|
||||
echo "🏷️ 标准版本标签处理"
|
||||
echo "版本号: ${{ steps.standard-version.outputs.trigger-version }}"
|
||||
echo "是否版本触发: ${{ steps.standard-version.outputs.is-version-trigger }}"
|
||||
|
||||
# 使用 'release-' 前缀的发布版本
|
||||
release-version:
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/release-') || startsWith(github.ref, 'refs/heads/release-')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 获取发布版本信息
|
||||
id: release-version
|
||||
uses: ./trigger-version
|
||||
with:
|
||||
version-prefix: 'release-'
|
||||
|
||||
- name: 显示发布版本信息
|
||||
run: |
|
||||
echo "🚀 发布版本处理"
|
||||
echo "引用名称: ${{ steps.release-version.outputs.ref-name }}"
|
||||
echo "版本号: ${{ steps.release-version.outputs.trigger-version }}"
|
||||
echo "触发源: ${{ steps.release-version.outputs.trigger-source }}"
|
||||
echo "是否版本触发: ${{ steps.release-version.outputs.is-version-trigger }}"
|
||||
|
||||
# 使用 'hotfix-' 前缀的热修复版本
|
||||
hotfix-version:
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/hotfix-')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 获取热修复版本信息
|
||||
id: hotfix-version
|
||||
uses: ./trigger-version
|
||||
with:
|
||||
version-prefix: 'hotfix-'
|
||||
|
||||
- name: 显示热修复版本信息
|
||||
run: |
|
||||
echo "🔧 热修复版本处理"
|
||||
echo "版本号: ${{ steps.hotfix-version.outputs.trigger-version }}"
|
||||
echo "完整引用: ${{ steps.hotfix-version.outputs.full-ref }}"
|
||||
|
||||
# 无前缀版本处理
|
||||
no-prefix-version:
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/') && !startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/release-') && !startsWith(github.ref, 'refs/tags/hotfix-')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 获取无前缀版本信息
|
||||
id: no-prefix-version
|
||||
uses: ./trigger-version
|
||||
with:
|
||||
version-prefix: ''
|
||||
|
||||
- name: 显示无前缀版本信息
|
||||
run: |
|
||||
echo "📦 无前缀版本处理"
|
||||
echo "标签名: ${{ steps.no-prefix-version.outputs.ref-name }}"
|
||||
echo "版本号: ${{ steps.no-prefix-version.outputs.trigger-version }}"
|
||||
|
||||
# 演示多种前缀处理策略
|
||||
multi-prefix-demo:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 检测并处理不同前缀
|
||||
run: |
|
||||
REF_NAME="${{ github.ref_name }}"
|
||||
REF_TYPE="${{ github.ref_type }}"
|
||||
|
||||
echo "当前引用: $REF_NAME (类型: $REF_TYPE)"
|
||||
|
||||
# 根据引用名称确定使用哪种前缀策略
|
||||
if [[ "$REF_NAME" == v* ]]; then
|
||||
echo "检测到标准版本前缀 'v'"
|
||||
VERSION_PREFIX="v"
|
||||
elif [[ "$REF_NAME" == release-* ]]; then
|
||||
echo "检测到发布前缀 'release-'"
|
||||
VERSION_PREFIX="release-"
|
||||
elif [[ "$REF_NAME" == hotfix-* ]]; then
|
||||
echo "检测到热修复前缀 'hotfix-'"
|
||||
VERSION_PREFIX="hotfix-"
|
||||
else
|
||||
echo "未检测到特定前缀,使用默认处理"
|
||||
VERSION_PREFIX=""
|
||||
fi
|
||||
|
||||
echo "VERSION_PREFIX=$VERSION_PREFIX" >> $GITHUB_ENV
|
||||
|
||||
- name: 使用动态前缀获取版本信息
|
||||
id: dynamic-version
|
||||
uses: ./trigger-version
|
||||
with:
|
||||
version-prefix: ${{ env.VERSION_PREFIX }}
|
||||
|
||||
- name: 显示动态版本信息
|
||||
run: |
|
||||
echo "🎯 动态前缀处理结果"
|
||||
echo "使用的前缀: '${{ env.VERSION_PREFIX }}'"
|
||||
echo "提取的版本号: ${{ steps.dynamic-version.outputs.trigger-version }}"
|
||||
echo "是否版本触发: ${{ steps.dynamic-version.outputs.is-version-trigger }}"
|
Reference in New Issue
Block a user