mnemo_cards/.forgejo/workflows/deploy.yaml

116 lines
3.7 KiB
YAML
Raw Normal View History

name: Deploy Mnemo Cards
on:
workflow_dispatch:
push:
branches:
- master
jobs:
deploy-backend:
name: Deploy Backend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Dependencies
run: |
apt-get update && apt-get install -y rsync openssh-client
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Sync Source Code
run: |
# Sync common packages
rsync -avz --delete --exclude '.*' --exclude 'build' --exclude 'doc' \
mnemo_cards_common \
mnemo_cards_common_backend \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/
# Sync backend project
rsync -avz --delete --exclude '.*' --exclude 'build' --exclude 'server.exe' --exclude 'isar' \
mnemo_cards_backend \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/
# Sync build script
rsync -avz tools/deploy/backend/server_build.sh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/mnemo_cards_backend/
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "chmod +x ~/mnemo_cards_backend/server_build.sh"
- name: Trigger Remote Build
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "~/mnemo_cards_backend/server_build.sh"
deploy-web:
name: Deploy Web App
runs-on: ubuntu-latest
needs: deploy-backend
if: always() # Run even if backend fails (optional, but usually good to separate)
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all tags and branches
lfs: false
- name: Configure Git
run: |
git config --global http.postBuffer 524288000
git config --global http.maxRequestBuffer 100M
git config --global core.compression 0
- name: Install Dependencies
run: |
2025-11-19 19:15:21 +00:00
apt-get update && apt-get install -y rsync openssh-client jq
2025-11-19 22:02:32 +00:00
- name: Restore Flutter cache
uses: actions/cache@v3
with:
2025-11-19 22:02:32 +00:00
path: /opt/flutter
key: flutter-${{ runner.os }}-${{ hashFiles('**/pubspec.yaml') }}
restore-keys: |
flutter-${{ runner.os }}-
2025-11-19 22:02:32 +00:00
- name: Install Flutter if missing
2025-11-19 21:43:53 +00:00
run: |
2025-11-19 22:02:32 +00:00
if [ ! -d /opt/flutter/bin ]; then
echo "Flutter not found in cache. Cloning..."
git clone https://github.com/flutter/flutter.git /opt/flutter
cd /opt/flutter
git checkout 3.35.5
else
echo "Using cached Flutter"
2025-11-19 21:48:07 +00:00
fi
2025-11-19 22:02:32 +00:00
echo "FLUTTER_ROOT=/opt/flutter" >> $GITHUB_ENV
echo "/opt/flutter/bin" >> $GITHUB_PATH
2025-11-19 21:48:07 +00:00
2025-11-19 22:02:32 +00:00
flutter --version
2025-11-19 21:43:53 +00:00
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Build Web App
run: |
cd mnemo_cards_web_v2
flutter pub get
flutter build web --release --dart-define=API_BASE_URL=https://api.memo-cards.online:8444 --dart2js-optimization=O4
- name: Deploy Web App
run: |
# Sync build artifacts
rsync -avz --delete build/web/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/mnemo_cards/
- name: Fix Permissions
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "chown -R www-data:www-data /var/www/mnemo_cards && chmod -R 755 /var/www/mnemo_cards"