@@ -17,28 +17,49 @@ jobs:
1717 outputs :
1818 should_build : ${{ steps.flags.outputs.should_build }}
1919 should_release : ${{ steps.flags.outputs.should_release }}
20+ should_publish : ${{ steps.flags.outputs.should_publish }}
21+ version : ${{ steps.flags.outputs.version }}
2022 steps :
23+ - name : Checkout
24+ uses : actions/checkout@v4
25+
2126 - name : Parse commit message
2227 id : flags
2328 run : |
2429 MSG="${{ github.event.head_commit.message }}"
30+
31+ # 从 Cargo.toml 提取版本号
32+ VERSION="v$(grep '^version' rust/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')"
33+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
34+ echo "📦 Version: $VERSION"
35+
2536 # PR 始终构建
2637 if [ "${{ github.event_name }}" = "pull_request" ]; then
27- echo "should_build=true" >> "$GITHUB_OUTPUT"
38+ echo "should_build=true" >> "$GITHUB_OUTPUT"
2839 echo "should_release=false" >> "$GITHUB_OUTPUT"
40+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
2941 exit 0
3042 fi
31- # "build release" 同时构建 + 发布
32- if echo "$MSG" | grep -qi "build release"; then
33- echo "should_build=true" >> "$GITHUB_OUTPUT"
34- echo "should_release=true" >> "$GITHUB_OUTPUT"
35- # "build action" 只构建
43+
44+ # "build publish" = 完整发布流程
45+ if echo "$MSG" | grep -qi "build publish"; then
46+ echo "should_build=true" >> "$GITHUB_OUTPUT"
47+ echo "should_release=true" >> "$GITHUB_OUTPUT"
48+ echo "should_publish=true" >> "$GITHUB_OUTPUT"
49+ # "build release" = 构建 + GitHub Release
50+ elif echo "$MSG" | grep -qi "build release"; then
51+ echo "should_build=true" >> "$GITHUB_OUTPUT"
52+ echo "should_release=true" >> "$GITHUB_OUTPUT"
53+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
54+ # "build action" = 仅构建
3655 elif echo "$MSG" | grep -qi "build action"; then
37- echo "should_build=true" >> "$GITHUB_OUTPUT"
56+ echo "should_build=true" >> "$GITHUB_OUTPUT"
3857 echo "should_release=false" >> "$GITHUB_OUTPUT"
58+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
3959 else
40- echo "should_build=false" >> "$GITHUB_OUTPUT"
60+ echo "should_build=false" >> "$GITHUB_OUTPUT"
4161 echo "should_release=false" >> "$GITHUB_OUTPUT"
62+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
4263 fi
4364
4465 # ── 多平台构建 ───────────────────────────────────────────
@@ -100,13 +121,32 @@ jobs:
100121
101122 - name : Prepare artifact
102123 shell : bash
103- run : cp "rust/target/${{ matrix.target }}/release/${{ matrix.binary }}" "${{ matrix.asset }}"
124+ run : |
125+ VERSION="${{ needs.check.outputs.version }}"
126+ ASSET_BASE="${{ matrix.asset }}"
127+
128+ # 在扩展名前插入版本号
129+ # winload-linux-x86_64 -> winload-linux-x86_64-v0.1.0
130+ # winload-windows-x86_64.exe -> winload-windows-x86_64-v0.1.0.exe
131+ if [[ "$ASSET_BASE" == *.* ]]; then
132+ # 有扩展名
133+ BASE_NAME="${ASSET_BASE%.*}"
134+ EXTENSION="${ASSET_BASE##*.}"
135+ ASSET_WITH_VERSION="${BASE_NAME}-${VERSION}.${EXTENSION}"
136+ else
137+ # 无扩展名
138+ ASSET_WITH_VERSION="${ASSET_BASE}-${VERSION}"
139+ fi
140+
141+ echo "📦 Output: $ASSET_WITH_VERSION"
142+ cp "rust/target/${{ matrix.target }}/release/${{ matrix.binary }}" "$ASSET_WITH_VERSION"
143+ echo "asset_name=$ASSET_WITH_VERSION" >> "$GITHUB_ENV"
104144
105145 - name : Upload build artifact
106146 uses : actions/upload-artifact@v4
107147 with :
108- name : ${{ matrix.asset }}
109- path : ${{ matrix.asset }}
148+ name : ${{ env.asset_name }}
149+ path : ${{ env.asset_name }}
110150
111151 # ── 发布到 GitHub Releases ─────────────────────────────
112152 release :
@@ -115,29 +155,26 @@ jobs:
115155 if : needs.check.outputs.should_release == 'true'
116156 runs-on : ubuntu-latest
117157 steps :
118- - name : Checkout (for version info)
158+ - name : Checkout
119159 uses : actions/checkout@v4
120160 with :
121161 fetch-depth : 0
122162
123- - name : Determine version tag
124- id : version
125- run : |
126- VER=$(grep '^version' rust/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
127- TAG="v${VER}"
128- echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
129- echo "Version: ${TAG}"
130-
131163 - name : Download all artifacts
132164 uses : actions/download-artifact@v4
133165 with :
134166 merge-multiple : true
135167
168+ - name : List downloaded files
169+ run : |
170+ echo "Downloaded artifacts:"
171+ ls -lh
172+
136173 - name : Create GitHub Release
137174 uses : softprops/action-gh-release@v2
138175 with :
139- tag_name : ${{ steps.version .outputs.tag }}
140- name : " winload ${{ steps.version .outputs.tag }}"
176+ tag_name : ${{ needs.check .outputs.version }}
177+ name : " winload ${{ needs.check .outputs.version }}"
141178 generate_release_notes : true
142179 make_latest : true
143- files : winload-*
180+ files : winload-*-${{ needs.check.outputs.version }}*
0 commit comments