-
Notifications
You must be signed in to change notification settings - Fork 23
134 lines (118 loc) · 3.88 KB
/
Copy pathrelease.yml
File metadata and controls
134 lines (118 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Release
run-name: Release ${{ inputs.version != '' && inputs.version || 'auto' }}
on:
workflow_dispatch:
inputs:
version:
description: '版本号 (例如: v1.0.0,留空则自动递增 patch)'
required: false
default: ''
type: string
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
resolved_version: ${{ steps.resolve-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve version (manual or auto-increment)
id: resolve-version
shell: bash
run: |
set -euo pipefail
INPUT_VERSION="${{ inputs.version }}"
INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}"
if [[ -n "$INPUT_VERSION" ]]; then
RESOLVED_VERSION="$INPUT_VERSION"
echo "Using manual version: $RESOLVED_VERSION"
else
git fetch --tags --force
LAST_TAG=$(
git tag --list --sort=-version:refname |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
head -n 1
)
if [[ -z "$LAST_TAG" ]]; then
RESOLVED_VERSION="v0.0.1"
echo "No existing semantic version tag found, defaulting to $RESOLVED_VERSION"
else
VERSION_PART="${LAST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_PART"
PATCH=$((PATCH + 1))
RESOLVED_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "Auto increment from $LAST_TAG to $RESOLVED_VERSION"
fi
fi
echo "Resolved version: $RESOLVED_VERSION"
echo "version=$RESOLVED_VERSION" >> "$GITHUB_OUTPUT"
{
echo "## Release Version Preview"
echo ""
echo "- Input version: ${INPUT_VERSION:-<empty>}"
echo "- Resolved version: $RESOLVED_VERSION"
} >> "$GITHUB_STEP_SUMMARY"
- name: Validate version format
run: |
VERSION="${{ steps.resolve-version.outputs.version }}"
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: 版本号格式不正确,应为 vX.Y.Z"
exit 1
fi
- name: Check if tag exists
run: |
VERSION="${{ steps.resolve-version.outputs.version }}"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Error: Tag $VERSION 已存在"
exit 1
fi
- name: Create tag
run: |
VERSION="${{ steps.resolve-version.outputs.version }}"
git tag "$VERSION"
git push origin "$VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.resolve-version.outputs.version }}
name: ${{ steps.resolve-version.outputs.version }}
generate_release_notes: true
draft: false
prerelease: false
build:
needs: release
uses: ./.github/workflows/ci-docker-build.yml
with:
tag: ${{ needs.release.outputs.resolved_version }}
permissions:
contents: read
packages: write
wails-build:
needs: release
uses: ./.github/workflows/ci-wails-build.yml
with:
tag: ${{ needs.release.outputs.resolved_version }}
permissions:
contents: write
update-homebrew:
needs:
- release
- wails-build
uses: ./.github/workflows/update-homebrew.yml
with:
tag: ${{ needs.release.outputs.resolved_version }}
secrets:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
update-scoop:
needs:
- release
- wails-build
uses: ./.github/workflows/update-scoop.yml
with:
tag: ${{ needs.release.outputs.resolved_version }}
secrets:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}