-
Notifications
You must be signed in to change notification settings - Fork 6
133 lines (115 loc) · 4.79 KB
/
Copy pathrelease.yml
File metadata and controls
133 lines (115 loc) · 4.79 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
name: Release
on:
push:
paths:
- 'custom_components/ai_hub/manifest.json'
release:
types: [published]
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from manifest
id: extract_version
if: github.event_name == 'push'
run: |
version=$(jq -r '.version' custom_components/ai_hub/manifest.json)
echo "version=$version" >> $GITHUB_OUTPUT
echo "version_number=${version#v}" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
if: github.event_name == 'push'
run: |
version="${{ steps.extract_version.outputs.version }}"
if git rev-parse "$version" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag $version already exists, skipping release"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag $version does not exist, will create release"
fi
- name: Get previous tag
id: prev_tag
run: |
git fetch --tags
prev_tag=$(git tag --sort=-creatordate | grep -v "^${{ steps.extract_version.outputs.version }}$" | head -n 1)
echo "prev_tag=$prev_tag" >> $GITHUB_OUTPUT
- name: Create changelog since previous release
id: changelog
env:
ZHIPU_API_KEY: ${{ secrets.ZHIPU_API_KEY }}
run: |
prev_tag="${{ steps.prev_tag.outputs.prev_tag }}"
if [ -n "$prev_tag" ]; then
log=$(git log --pretty=format:"- %s" "$prev_tag"..HEAD)
else
log=$(git log --pretty=format:"- %s")
fi
# 如果有 API Key,使用 AI 生成双语 changelog
if [ -n "$ZHIPU_API_KEY" ]; then
prompt="请将以下 git commit 记录翻译成中英双语格式。如果原文是中文就翻译成英文,如果是英文就翻译成中文。输出格式:每条记录先显示中文,然后显示英文(用斜体),例如:- 修复登录问题 / *Fix login issue*。只输出翻译结果,不要其他内容。\n\n${log}"
response=$(curl -s https://open.bigmodel.cn/api/paas/v4/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ZHIPU_API_KEY" \
-d "$(jq -n --arg content "$prompt" '{
"model": "glm-4.7-flash",
"messages": [{"role": "user", "content": $content}],
"temperature": 0.1
}')")
translated=$(echo "$response" | jq -r '.choices[0].message.content // empty')
if [ -n "$translated" ]; then
log="$translated"
fi
fi
{
echo "log<<EOF"
echo "$log"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create tag and release
if: github.event_name == 'push' && steps.check_tag.outputs.exists == 'false'
run: |
version="${{ steps.extract_version.outputs.version }}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a "$version" -m "Release $version"
git push origin "$version"
- name: Create GitHub Release
if: github.event_name == 'push' && steps.check_tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.extract_version.outputs.version }}
name: Release ${{ steps.extract_version.outputs.version }}
body: |
## Changes since ${{ steps.prev_tag.outputs.prev_tag }}
${{ steps.changelog.outputs.log }}
draft: false
prerelease: false
- name: Create zip file
run: |
cd ${{ github.workspace }}/custom_components/ai_hub
zip -r ai_hub.zip ./
- name: Upload release asset
if: github.event_name == 'push' && steps.check_tag.outputs.exists == 'false'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/custom_components/ai_hub/ai_hub.zip
asset_name: ai_hub.zip
tag: ${{ steps.extract_version.outputs.version }}
overwrite: true
- name: Upload release asset to existing release
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/custom_components/ai_hub/ai_hub.zip
asset_name: ai_hub.zip
tag: ${{ github.ref }}
overwrite: true