Files
xgj/trigger-version/examples/basic-usage.yml

72 lines
3.0 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

# 基本用法示例
# 这个示例展示了如何使用 trigger-version action 获取版本信息
name: Basic Usage Example
on:
push:
branches: ['main', 'develop', 'v*']
tags: ['v*']
workflow_dispatch:
jobs:
get-version-info:
runs-on: ubuntu-latest
outputs:
is-version-trigger: ${{ steps.version-info.outputs.is-version-trigger }}
trigger-version: ${{ steps.version-info.outputs.trigger-version }}
version-with-dash: ${{ steps.version-info.outputs.version-with-dash }}
trigger-source: ${{ steps.version-info.outputs.trigger-source }}
ref-type: ${{ steps.version-info.outputs.ref-type }}
ref-name: ${{ steps.version-info.outputs.ref-name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: 获取触发版本信息
id: version-info
uses: actions/xgj/trigger-version@v1
- name: 显示版本信息
run: |
echo "========== 触发信息汇总 =========="
echo "引用类型: ${{ steps.version-info.outputs.ref-type }}"
echo "引用名称: ${{ steps.version-info.outputs.ref-name }}"
echo "完整引用: ${{ steps.version-info.outputs.full-ref }}"
echo "是否版本触发: ${{ steps.version-info.outputs.is-version-trigger }}"
echo "触发版本号: ${{ steps.version-info.outputs.trigger-version }}"
echo "横线版本号: ${{ steps.version-info.outputs.version-with-dash }}"
echo "触发源: ${{ steps.version-info.outputs.trigger-source }}"
echo "================================"
- name: 检查环境变量
run: |
echo "========== 环境变量 =========="
echo "IS_VERSION_TRIGGER: ${IS_VERSION_TRIGGER}"
echo "TRIGGER_VERSION: ${TRIGGER_VERSION}"
echo "VERSION_WITH_DASH: ${VERSION_WITH_DASH}"
echo "TRIGGER_SOURCE: ${TRIGGER_SOURCE}"
echo "============================"
show-usage:
needs: get-version-info
runs-on: ubuntu-latest
steps:
- name: 演示如何使用输出参数
run: |
echo "在其他 job 中使用输出参数:"
echo "版本触发: ${{ needs.get-version-info.outputs.is-version-trigger }}"
echo "版本号: ${{ needs.get-version-info.outputs.trigger-version }}"
if [[ "${{ needs.get-version-info.outputs.is-version-trigger }}" == "true" ]]; then
echo "✅ 这是一个版本发布触发"
echo "🚀 版本号: ${{ needs.get-version-info.outputs.trigger-version }}"
echo "🏷️ 横线版本号: ${{ needs.get-version-info.outputs.version-with-dash }}"
echo "🐳 Docker标签: myapp:${{ needs.get-version-info.outputs.version-with-dash }}"
echo "📦 触发源: ${{ needs.get-version-info.outputs.trigger-source }}"
else
echo " 这是一个常规分支推送"
echo "🌿 分支名: ${{ needs.get-version-info.outputs.ref-name }}"
fi