forked from ShardLauncher/ShardLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (106 loc) · 5.02 KB
/
Copy pathrelease.yml
File metadata and controls
123 lines (106 loc) · 5.02 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
name: Release Build
on:
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整历史以检索上一个 tag
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '.gitmodules') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Extract Version Name
id: extract_version
run: |
VERSION_NAME=$(grep 'val vName =' ShardLauncher/build.gradle.kts | sed 's/.*"\(.*\)".*/\1/' | sed 's/ - /_/g')
echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
echo "Detected version: $VERSION_NAME"
- name: Configure Git and Create Tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "LanRhyme"
git config user.email "xiao_ren233@foxmail.com"
# 检查 tag 是否已存在,若存在则删除(确保可以用新代码重新发布同一版本)
if git rev-parse "$VERSION_NAME" >/dev/null 2>&1; then
echo "Tag $VERSION_NAME already exists, replacing it..."
git tag -d "$VERSION_NAME"
git push origin ":refs/tags/$VERSION_NAME"
fi
# 创建附注标签 (Annotated Tag) 以记录署名
git tag -a "$VERSION_NAME" -m "Release $VERSION_NAME"
git push origin "$VERSION_NAME"
- name: Generate Changelog
id: changelog
run: |
# 寻找上一个 tag (排除掉刚才创建的这个)
LAST_TAG=$(git describe --tags --abbrev=0 "${{ env.VERSION_NAME }}^" 2>/dev/null || echo "")
echo "CHANGELOG_CONTENT<<EOF" >> $GITHUB_OUTPUT
if [ -z "$LAST_TAG" ]; then
echo "No previous tags found. Generating changelog from first commit."
git log --pretty=format:"- %s (%h)" --no-merges >> $GITHUB_OUTPUT
else
echo "Last tag: $LAST_TAG"
# 获取从 LAST_TAG 到当前 VERSION_NAME 的所有提交
git log ${LAST_TAG}..${{ env.VERSION_NAME }} --pretty=format:"- %s (%h)" --no-merges >> $GITHUB_OUTPUT
fi
echo "" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Decode Keystore
id: decode_keystore
env:
SIGNING_KEYSTORE_BASE64: ${{ secrets.SIGNING_KEYSTORE_BASE64 }}
run: |
echo $SIGNING_KEYSTORE_BASE64 | base64 --decode > ShardLauncher/keystore.jks
- name: Build Release APKs
env:
MICROSOFT_CLIENT_ID: ${{ secrets.MICROSOFT_CLIENT_ID }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: ./gradlew assembleRelease -Pandroid.injected.signing.store.file=$(pwd)/ShardLauncher/keystore.jks -Pandroid.injected.signing.store.password=$SIGNING_KEYSTORE_PASSWORD -Pandroid.injected.signing.key.alias=$SIGNING_KEY_ALIAS -Pandroid.injected.signing.key.password=$SIGNING_KEY_PASSWORD
- name: Prepare Artifacts
run: |
mkdir -p release_artifacts
find ShardLauncher/build/outputs/apk/release -name "*universal*release*.apk" -exec cp {} release_artifacts/com.lanrhyme.shardlauncher-all.apk \;
find ShardLauncher/build/outputs/apk/release -name "*armeabi-v7a*release*.apk" -exec cp {} release_artifacts/com.lanrhyme.shardlauncher-armeabi-v7a.apk \;
find ShardLauncher/build/outputs/apk/release -name "*arm64-v8a*release*.apk" -exec cp {} release_artifacts/com.lanrhyme.shardlauncher-arm64-v8a.apk \;
find ShardLauncher/build/outputs/apk/release -name "*x86*release*.apk" -not -name "*x86_64*" -exec cp {} release_artifacts/com.lanrhyme.shardlauncher-x86.apk \;
find ShardLauncher/build/outputs/apk/release -name "*x86_64*release*.apk" -exec cp {} release_artifacts/com.lanrhyme.shardlauncher-x86_64.apk \;
ls -l release_artifacts/
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.VERSION_NAME }}
name: ${{ env.VERSION_NAME }}
body: |
## 更新日志
${{ steps.changelog.outputs.CHANGELOG_CONTENT }}
files: |
release_artifacts/*.apk
draft: false
prerelease: false
env:
# 如果你希望发布人显示为 LanRhyme 而不是 github-actions[bot],
# 建议在 Repository Secrets 中添加一个名为 RELEASE_TOKEN 的个人访问令牌 (PAT),
# 并将下面这一行改为 GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}