Files
xgj/release-web/examples/version-handling.yml

149 lines
5.3 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: 版本处理示例
on:
push:
branches: [main]
jobs:
test-version-handling:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置环境
uses: actions/xgj/setup-env@main
with:
docker-registry: "docker-registry.bjxgj.com"
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
- name: 安装依赖
uses: actions/xgj/npm-install@main
# 测试1: 版本文件包含 v 前缀
- name: 创建带 v 前缀的版本文件
run: echo "v1.2.3" > /tmp/version-with-v
- name: 发布(版本文件带 v 前缀)
id: test1
uses: actions/xgj/release-web@main
with:
release-command: "echo 'Test release with v prefix in file'"
version-file: "/tmp/version-with-v"
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: 验证版本输出(应包含 v 前缀)
run: |
echo "版本输出: ${{ steps.test1.outputs.version }}"
if [[ "${{ steps.test1.outputs.version }}" == "v1.2.3" ]]; then
echo "✅ 正确:版本文件 v 前缀保持不变"
else
echo "❌ 错误:版本应该是 v1.2.3,实际是 ${{ steps.test1.outputs.version }}"
exit 1
fi
# 测试2: Git tag 包含 v 前缀
- name: 创建带 v 前缀的 git tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag v1.2.4
# 删除版本文件,强制使用 git tag
rm -f /tmp/last-version /tmp/version-with-v
- name: 发布(基于 git tag
id: test2
uses: actions/xgj/release-web@main
with:
release-command: "echo 'Test release with git tag'"
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: 验证 git tag 版本输出
run: |
echo "Git tag 版本输出: ${{ steps.test2.outputs.version }}"
if [[ "${{ steps.test2.outputs.version }}" == "v1.2.4" ]]; then
echo "✅ 正确Git tag v 前缀保持不变"
else
echo "❌ 错误:版本应该是 v1.2.4,实际是 ${{ steps.test2.outputs.version }}"
exit 1
fi
# 测试3: package.json 包含 v 前缀(不常见但要处理)
- name: 修改 package.json 添加 v 前缀
run: |
# 创建一个测试用的 package.json
echo '{"version": "v1.2.5"}' > package.json
rm -f /tmp/last-version
git tag -d v1.2.4 # 删除之前的 tag
- name: 发布(基于 package.json
id: test3
uses: actions/xgj/release-web@main
with:
release-command: "echo 'Test release with package.json'"
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: 验证 package.json 版本输出
run: |
echo "Package.json 版本输出: ${{ steps.test3.outputs.version }}"
if [[ "${{ steps.test3.outputs.version }}" == "v1.2.5" ]]; then
echo "✅ 正确Package.json 版本已添加 v 前缀"
else
echo "❌ 错误:版本应该是 v1.2.5,实际是 ${{ steps.test3.outputs.version }}"
exit 1
fi
# 测试4: 提交信息包含 v 前缀
- name: 创建带 v 前缀的提交信息
run: |
echo '{"version": "0.0.1"}' > package.json # 重置 package.json
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add package.json
git commit --allow-empty -m "release: v1.2.6"
- name: 发布(基于提交信息)
id: test4
uses: actions/xgj/release-web@main
with:
release-command: "echo 'Test release with commit message'"
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: 验证提交信息版本输出
run: |
echo "提交信息版本输出: ${{ steps.test4.outputs.version }}"
if [[ "${{ steps.test4.outputs.version }}" == "v1.2.6" ]]; then
echo "✅ 正确:提交信息 v 前缀保持不变"
else
echo "❌ 错误:版本应该是 v1.2.6,实际是 ${{ steps.test4.outputs.version }}"
exit 1
fi
# 测试5: 版本号带横线格式
- name: 验证版本带横线格式
run: |
echo "版本带横线: ${{ steps.test4.outputs.version-with-dash }}"
if [[ "${{ steps.test4.outputs.version-with-dash }}" == "v1-2-6" ]]; then
echo "✅ 正确:版本横线格式正确"
else
echo "❌ 错误:版本横线格式应该是 v1-2-6实际是 ${{ steps.test4.outputs.version-with-dash }}"
exit 1
fi
- name: 测试总结
run: |
echo "🎉 所有版本处理测试通过!"
echo "✅ 版本文件 v 前缀保持不变"
echo "✅ Git tag v 前缀保持不变"
echo "✅ Package.json 版本自动添加 v 前缀"
echo "✅ 提交信息 v 前缀保持不变"
echo "✅ 版本横线格式包含 v 前缀"