Skip to content

Commit dada970

Browse files
authored
Create flutter-ci-cd.yml
1 parent b0d23f8 commit dada970

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Build and Release Flutter APK
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write # 允许 GITHUB_TOKEN 发布 release
14+
15+
steps:
16+
- name: Checkout source
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Flutter
20+
uses: subosito/flutter-action@v2
21+
with:
22+
flutter-version: '3.13.0'
23+
24+
- name: Disable analytics
25+
run: flutter config --no-analytics
26+
27+
# 解码 keystore
28+
- name: Decode keystore from secret
29+
run: |
30+
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > flutter_printer_qpos/example/android/app/app.keystore
31+
32+
# 创建 key.properties 文件
33+
- name: Create key.properties
34+
run: |
35+
cat > flutter_printer_qpos/example/android/key.properties <<EOF
36+
storePassword=${{ secrets.KEYSTORE_PASSWORD }}
37+
keyPassword=${{ secrets.KEY_PASSWORD }}
38+
keyAlias=${{ secrets.KEY_ALIAS }}
39+
storeFile=app.keystore
40+
EOF
41+
42+
# 安装依赖
43+
- name: Install dependencies
44+
run: flutter pub get
45+
working-directory: flutter_printer_qpos/example
46+
47+
# 分析插件本体
48+
- name: Analyze (non-fatal)
49+
run: flutter analyze || true
50+
working-directory: flutter_printer_qpos
51+
52+
# 构建 APK(已签名)
53+
- name: Build signed APK
54+
run: flutter build apk --release
55+
working-directory: flutter_printer_qpos/example
56+
57+
# 自动生成 TAG(递增规则 0.0.1 -> 0.0.2 ... -> 0.1.0)
58+
- name: Determine next tag
59+
id: tag
60+
run: |
61+
# 获取远程 tag 列表
62+
git fetch --tags
63+
latest_tag=$(git tag | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)
64+
if [[ -z "$latest_tag" ]]; then
65+
next_tag="1.0.0"
66+
else
67+
IFS='.' read -r major minor patch <<<"${latest_tag}"
68+
if [[ $patch -lt 9 ]]; then
69+
patch=$((patch+1))
70+
else
71+
patch=0
72+
minor=$((minor+1))
73+
fi
74+
next_tag="${major}.${minor}.${patch}"
75+
fi
76+
echo "Next tag: $next_tag"
77+
echo "tag=$next_tag" >> $GITHUB_OUTPUT
78+
79+
# 创建 Git Tag(必要)
80+
- name: Create Git tag
81+
run: |
82+
git config user.name "github-actions"
83+
git config user.email "github-actions@github.com"
84+
git tag ${{ steps.tag.outputs.tag }}
85+
git push origin ${{ steps.tag.outputs.tag }}
86+
87+
# 创建 GitHub Release 并上传 APK
88+
- name: Create GitHub Release
89+
uses: softprops/action-gh-release@v2
90+
with:
91+
tag_name: ${{ steps.tag.outputs.tag }}
92+
name: Release ${{ steps.tag.outputs.tag }}
93+
files: flutter_printer_qpos/example/build/app/outputs/flutter-apk/app-release.apk
94+
env:
95+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)