66 lines
1.8 KiB
YAML
66 lines
1.8 KiB
YAML
name: Build and Deploy Web App
|
|
on:
|
|
push:
|
|
tags:
|
|
- '*' # 监听所有标签的推送
|
|
workflow_dispatch:
|
|
# 允许手动触发工作流
|
|
|
|
jobs:
|
|
build_web:
|
|
name: Build and Deploy Web to a Branch
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Flutter
|
|
uses: subosito/flutter-action@v2
|
|
with:
|
|
channel: 'stable'
|
|
|
|
- name: Modify API endpoints for Web build
|
|
run: |
|
|
TARGET_FILE="lib/core/api_client.dart"
|
|
if [ -f "$TARGET_FILE" ]; then
|
|
echo "Modifying API endpoints in $TARGET_FILE..."
|
|
sed -i 's#https://api-bc.wtzw.com#https://api-bc.wtzw.staredges.cn#g' $TARGET_FILE
|
|
sed -i 's#https://api-ks.wtzw.com#https://api-ks.wtzw.staredges.cn#g' $TARGET_FILE
|
|
echo "File modification complete."
|
|
cat $TARGET_FILE
|
|
else
|
|
echo "Error: Target file $TARGET_FILE not found!"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Get Flutter dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Build Flutter Web app
|
|
run: flutter build web --release
|
|
|
|
- name: Archive Web build artifact
|
|
run: tar -czvf web-build.tar.gz -C build/web .
|
|
|
|
- name: Upload Web build artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: web-build
|
|
path: web-build.tar.gz
|
|
|
|
- name: Deploy to a separate branch
|
|
uses: peaceiris/actions-gh-pages@v3
|
|
with:
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
publish_dir: ./build/web
|
|
|
|
publish_branch: web-builds
|
|
|
|
user_name: 'github-actions[bot]'
|
|
user_email: 'github-actions[bot]@users.noreply.github.com'
|