mian to master branch #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flutter Web Preview Build | |
on: | |
push: | |
branches: [master] | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 # Fetch all history | |
- name: Reset live_preview branch to master | |
run: | | |
# Create or checkout live_preview branch | |
git checkout live_preview 2>/dev/null || git checkout -b live_preview | |
# Force reset to master branch state | |
git fetch origin master | |
git reset --hard origin/master | |
# Force push to update live_preview branch | |
git push -f origin live_preview | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: "3.24.4" | |
channel: "stable" | |
- name: Install dependencies | |
run: | | |
flutter pub get | |
flutter pub add device_preview | |
flutter pub add device_preview_screenshot | |
flutter pub get | |
- name: Update main.dart for preview | |
run: | | |
# Ensure we're creating a fresh main.dart | |
cat > lib/main.dart << 'EOL' | |
import 'package:chess/gameboard.dart'; | |
import 'package:chess/values/colors.dart'; | |
import 'package:device_preview/device_preview.dart'; | |
import 'package:device_preview_screenshot/device_preview_screenshot.dart'; | |
import 'package:flutter/material.dart; | |
Future<void> main() async { | |
runApp( | |
DevicePreview( | |
backgroundColor: backgroundColor, | |
tools: const [ | |
DeviceSection( | |
frameVisibility: false, | |
orientation: false, | |
), | |
SystemSection( | |
locale: false, | |
theme: true, | |
), | |
DevicePreviewScreenshot(), | |
SettingsSection(), | |
], | |
devices: [ | |
Devices.android.samsungGalaxyA50, | |
Devices.android.samsungGalaxyNote20, | |
Devices.android.samsungGalaxyS20, | |
Devices.android.samsungGalaxyNote20Ultra, | |
Devices.android.onePlus8Pro, | |
Devices.android.sonyXperia1II, | |
Devices.ios.iPhoneSE, | |
Devices.ios.iPhone12, | |
Devices.ios.iPhone12Mini, | |
Devices.ios.iPhone12ProMax, | |
Devices.ios.iPhone13, | |
Devices.ios.iPhone13ProMax, | |
Devices.ios.iPhone13Mini, | |
Devices.ios.iPhoneSE, | |
], | |
enabled: true, | |
builder: (context) => const MyApp(), | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Chess', | |
debugShowCheckedModeBanner: false, | |
locale: DevicePreview.locale(context), | |
builder: DevicePreview.appBuilder, | |
home: const GameBoard(), | |
); | |
} | |
} | |
EOL | |
- name: Build Web | |
run: flutter build web --base-href "/flutter_chess/" | |
- name: Update docs directory | |
run: | | |
# Remove old docs and create new one | |
rm -rf docs | |
mkdir -p docs | |
# Copy web build to docs | |
cp -r build/web/. docs/ | |
- name: Commit and push preview changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
# Stage all changes | |
git add docs lib/main.dart | |
git commit -m "Update web preview build" || echo "No changes to commit" | |
# Force push to ensure clean state | |
git push -f origin live_preview |