diff --git a/.github/workflows/gh-pages.yaml b/.github/workflows/gh-pages.yaml index 3622cebca..64bf3ea54 100644 --- a/.github/workflows/gh-pages.yaml +++ b/.github/workflows/gh-pages.yaml @@ -5,6 +5,9 @@ on: name: Deploy PR on Github Pages +env: + FLUTTER_VERSION: 3.27.4 + concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -17,33 +20,61 @@ jobs: url: ${{ steps.configure.outputs.URL }} steps: + # ๐Ÿงน Free up space before building + - name: Free up disk space before build + run: | + echo "=== Disk space before cleanup ===" + df -h + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + sudo apt-get clean + sudo apt-get autoclean + echo "=== Disk space after cleanup ===" + df -h + + # ๐Ÿ”„ Checkout code - name: Checkout repository uses: actions/checkout@v4 - - name: Setup flutter + # ๐Ÿงฐ Setup Flutter + - name: Setup Flutter uses: subosito/flutter-action@v2 with: - flutter-version: "3.27.4" + flutter-version: ${{ env.FLUTTER_VERSION }} channel: "stable" cache: true cache-key: deps-${{ hashFiles('**/pubspec.lock') }} # optional, change this to force refresh cache cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path + # ๐Ÿงน Clean Flutter cache before building + - name: Flutter clean + run: flutter clean + + # ๐Ÿ“ฆ Run prebuild (if any) - name: Run prebuild run: ./scripts/prebuild.sh + # โš™๏ธ Configure environment for PR - name: Configure environments id: configure env: FOLDER: ${{ github.event.pull_request.number }} run: ./scripts/configure-web-environment.sh - - name: Build + # ๐Ÿงฑ Build Flutter Web (release) + - name: Build Web (Release) env: FOLDER: ${{ github.event.pull_request.number }} - run: ./scripts/build-web.sh + run: | + echo "=== Disk usage before build ===" + df -h + ./scripts/build-web.sh + echo "=== Disk usage after build ===" + df -h - - name: Deploy to Github Pages + # ๐Ÿš€ Deploy to GitHub Pages + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -51,6 +82,16 @@ jobs: keep_files: true publish_dir: "build/web" + # ๐Ÿงน Clean up after build to save space + - name: Cleanup after deploy + if: always() + run: | + rm -rf build/ + rm -rf .dart_tool/ + echo "=== Disk usage after cleanup ===" + df -h + + # ๐Ÿ’ฌ Create or update comments on PR - name: Find deployment comment uses: peter-evans/find-comment@v3 id: fc diff --git a/scripts/build-web.sh b/scripts/build-web.sh index b9e36c340..df075a4cb 100755 --- a/scripts/build-web.sh +++ b/scripts/build-web.sh @@ -1,4 +1,6 @@ #!/usr/bin/env sh set -eux -flutter build web --profile --verbose --base-href "/${GITHUB_REPOSITORY##*/}/$FOLDER/" + +# Build web in release mode (lightweight, optimized) +flutter build web --release --base-href "/${GITHUB_REPOSITORY##*/}/$FOLDER/"