mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 更新工作流步骤名称以反映版本和路径获取 - 从 .nupkg 文件中正确解析 NuGet 包的基本文件名 - 在 GitHub 输出中添加 package_basename 变量 - 使用 package_basename 作为上传资产的准确文件名 - 确保 release 资产使用正确的文件名而非完整路径
76 lines
2.3 KiB
YAML
76 lines
2.3 KiB
YAML
name: Create Release (on tag)
|
||
|
||
on:
|
||
push:
|
||
tags:
|
||
- '*'
|
||
|
||
permissions:
|
||
contents: write
|
||
|
||
jobs:
|
||
release:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout repository (at tag)
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
persist-credentials: true
|
||
|
||
- name: Setup .NET
|
||
uses: actions/setup-dotnet@v4
|
||
with:
|
||
dotnet-version: 9.0.x
|
||
|
||
- name: Restore dependencies
|
||
run: dotnet restore
|
||
|
||
- name: Build
|
||
run: dotnet build --no-restore -c Release
|
||
|
||
- name: Pack
|
||
run: dotnet pack --no-build -c Release -o ./packages
|
||
|
||
- name: Get Version and Package Path
|
||
id: get_version
|
||
run: |
|
||
set -e
|
||
PACKAGE_FILE=$(find ./packages -name "*.nupkg" | head -n 1)
|
||
if [ -z "$PACKAGE_FILE" ]; then
|
||
echo "No .nupkg file found in ./packages"
|
||
exit 1
|
||
fi
|
||
# 从 .nupkg(zip)里读取 .nuspec 并提取 <version> 标签(稳妥)
|
||
VERSION=$(unzip -p "$PACKAGE_FILE" *.nuspec 2>/dev/null | sed -n 's:.*<version>\(.*\)</version>.*:\1:p' | head -n1)
|
||
if [ -z "$VERSION" ]; then
|
||
echo "Failed to parse version from $PACKAGE_FILE"
|
||
exit 1
|
||
fi
|
||
BASENAME=$(basename "$PACKAGE_FILE")
|
||
echo "package_file=$PACKAGE_FILE" >> $GITHUB_OUTPUT
|
||
echo "package_basename=$BASENAME" >> $GITHUB_OUTPUT
|
||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||
|
||
- name: Create GitHub Release
|
||
id: create_release
|
||
uses: actions/create-release@v1
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
with:
|
||
tag_name: ${{ github.ref_name }}
|
||
release_name: "Release ${{ github.ref_name }}"
|
||
body: "Release created by CI for tag ${{ github.ref_name }} (package version ${{ steps.get_version.outputs.version }})"
|
||
draft: false
|
||
prerelease: false
|
||
|
||
- name: Upload .nupkg to Release
|
||
uses: actions/upload-release-asset@v1
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
with:
|
||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||
asset_path: ${{ steps.get_version.outputs.package_file }}
|
||
asset_name: ${{ steps.get_version.outputs.package_basename }}
|
||
asset_content_type: application/octet-stream
|