Skip to content

Commit 8d395f3

Browse files
committed
ci: update release workflow
1 parent fbf97ab commit 8d395f3

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

.github/workflows/auto-release.yml

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
name: Auto Release
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: "Tag name for release (leave empty to use latest pushed tag)"
8+
required: false
49
push:
510
tags:
6-
- "v*" # Listen to tags like v1.0.0
11+
- "v*.*.*" # Match only version-like tags (e.g., v1.0.0, v2.1.3)
12+
13+
permissions:
14+
contents: write # Required for GitHub release creation
715

816
jobs:
917
release:
@@ -12,16 +20,49 @@ jobs:
1220
steps:
1321
- name: Checkout repository
1422
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0 # Fetch full commit history and tags
25+
26+
- name: Determine Tag Name
27+
id: get_tag
28+
run: |
29+
# If manually triggered, use the input tag; otherwise, use github.ref_name
30+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then
31+
TAG_NAME="${{ github.event.inputs.tag }}"
32+
else
33+
TAG_NAME="${{ github.ref_name }}"
34+
fi
35+
36+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
37+
echo "Resolved TAG_NAME: $TAG_NAME"
1538
1639
- name: Get Previous Tag
1740
id: get_prev_tag
18-
run: echo "LAST_TAG=$(git describe --tags --abbrev=0 --exclude=${{ github.ref_name }})" >> $GITHUB_ENV
41+
run: |
42+
# Get the last tag before the new one, or empty if this is the first tag
43+
LAST_TAG=$(git tag --sort=-creatordate | grep -v "$TAG_NAME" | head -n 1 || echo "")
44+
45+
# If no previous tag exists, use the root commit
46+
if [[ -z "$LAST_TAG" ]]; then
47+
LAST_TAG=$(git rev-list --max-parents=0 HEAD)
48+
echo "First release detected, using root commit: $LAST_TAG"
49+
fi
50+
51+
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
52+
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_OUTPUT
53+
54+
- name: Skip Release if No Previous Tag
55+
if: env.LAST_TAG == ''
56+
run: |
57+
echo "No previous tag found, skipping release..."
58+
exit 0
1959
2060
- name: Generate GitHub Release
2161
uses: softprops/action-gh-release@v2
62+
if: startsWith(github.ref, 'refs/tags/') # Ensures release runs only on tag pushes
2263
with:
23-
tag_name: ${{ github.ref_name }} # Tag Name
24-
name: ${{ github.ref_name }} # Release Name (same as Tag Name)
64+
tag_name: ${{ env.TAG_NAME }} # Ensure correct tag name is used
65+
name: ${{ env.TAG_NAME }} # Release Name
2566
body: |
2667
📢 **SuzuBlog new version released!** 🚀
2768
新版本发布!请查看自动生成的 Release Notes 🔽
@@ -30,7 +71,7 @@ jobs:
3071
- Automatically generated Release Notes based on changes in this release.
3172
3273
## Full Changelog
33-
[View Full Changelog](https://github.com/ZL-Asica/SuzuBlog/compare/${{ github.event.before }}...${{ github.ref }})
74+
[View Full Changelog](https://github.com/ZL-Asica/SuzuBlog/compare/${{ env.LAST_TAG }}...${{ env.TAG_NAME }})
3475
3576
## Contributors
3677
🏆 Thank you to everyone who contributed to this release!

0 commit comments

Comments
 (0)