mirror of
https://github.com/denglihong2007/CRSim
synced 2026-06-18 23:45:40 +08:00
105 lines
3.3 KiB
YAML
105 lines
3.3 KiB
YAML
name: Release on Version Change
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: read
|
|
|
|
jobs:
|
|
check-version:
|
|
runs-on: windows-latest
|
|
outputs:
|
|
version_updated: ${{ steps.check_version.outputs.updated }}
|
|
new_version: ${{ steps.get_version.outputs.version }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # 获取全部提交历史以便比较标签
|
|
|
|
- name: Extract version from props
|
|
id: get_version
|
|
shell: pwsh
|
|
run: |
|
|
[xml]$props = Get-Content "Directory.Build.props"
|
|
# 确保选择包含Version的PropertyGroup
|
|
$version = $props.Project.PropertyGroup.Version
|
|
echo "Detected version: $version"
|
|
# 将版本设置为步骤输出
|
|
echo "version=$version" >> $env:GITHUB_OUTPUT
|
|
|
|
- name: Compare with latest tag
|
|
id: check_version
|
|
shell: pwsh
|
|
run: |
|
|
# 获取最新标签(按语义版本排序)
|
|
$latestTag = git tag --list --sort=-v:refname | Select-Object -First 1
|
|
echo "Latest tag: $latestTag"
|
|
|
|
# 获取csproj中的版本
|
|
$currentVersion = "v${{ steps.get_version.outputs.version }}"
|
|
|
|
if (-not $latestTag) {
|
|
echo "首次发布,没有现有标签"
|
|
echo "updated=true" >> $env:GITHUB_OUTPUT
|
|
} elseif ($currentVersion -ne $latestTag) {
|
|
echo "检测到新版本: $currentVersion (旧版本: $latestTag)"
|
|
echo "updated=true" >> $env:GITHUB_OUTPUT
|
|
} else {
|
|
echo "版本未变化,跳过发布"
|
|
echo "updated=false" >> $env:GITHUB_OUTPUT
|
|
}
|
|
|
|
release:
|
|
needs: check-version
|
|
if: ${{ needs.check-version.outputs.version_updated == 'true' }}
|
|
runs-on: windows-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup .NET SDK
|
|
uses: actions/setup-dotnet@v3
|
|
with:
|
|
dotnet-version: '10.x'
|
|
|
|
- name: Add GitHub Package Source
|
|
env:
|
|
GHPKG_KEY: ${{ secrets.GHPKG_KEY }}
|
|
run: |
|
|
dotnet nuget add source --username denglihong2007 --password $env:GHPKG_KEY --store-password-in-clear-text --name github "https://nuget.pkg.github.com/denglihong2007/index.json"
|
|
|
|
- name: Generate changelog
|
|
uses: orhun/git-cliff-action@v4
|
|
with:
|
|
config: cliff.toml
|
|
args: --verbose --unreleased
|
|
env:
|
|
OUTPUT: CHANGELOG.md
|
|
GITHUB_REPO: ${{ github.repository }}
|
|
|
|
- name: Publish
|
|
run: |
|
|
dotnet restore CRSim.slnx
|
|
dotnet publish -c Release -p:PublishProfile=win-x64.pubxml -o out
|
|
|
|
- name: Create Zip Package
|
|
shell: pwsh
|
|
run: |
|
|
$version = "${{ needs.check-version.outputs.new_version }}"
|
|
Compress-Archive -Path out/* -DestinationPath "CRSim-release-$version.zip"
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: v${{ needs.check-version.outputs.new_version }}
|
|
body_path: ./CHANGELOG.md
|
|
name: ${{ needs.check-version.outputs.new_version }}
|
|
files: CRSim-release-${{ needs.check-version.outputs.new_version }}.zip |