1111 runs-on : ubuntu-latest
1212
1313 steps :
14- # Step 0: Free up disk space (CRITICAL FIX)
15- # This removes unused tools (Dotnet, Haskell, Docker) to prevent "No space left" errors.
14+ # Step 0: Free up disk space
1615 - name : Free Disk Space (Ubuntu)
1716 uses : jlumbroso/free-disk-space@main
1817 with :
@@ -28,15 +27,15 @@ jobs:
2827 - name : Checkout Main Branch
2928 uses : actions/checkout@v4
3029 with :
31- fetch-depth : 1 # Changed from 0 to 1 to save disk space
30+ fetch-depth : 1
3231
33- # Step 2: Setup Java with version 17.x
32+ # Step 2: Setup Java
3433 - uses : actions/setup-java@v4
3534 with :
3635 distribution : " temurin"
3736 java-version : " 17.x"
3837
39- # Step 3: Setup Flutter with version 3.29.2
38+ # Step 3: Setup Flutter
4039 - name : Setup Flutter
4140 uses : subosito/flutter-action@v2
4241 with :
4645 - name : Get dependencies
4746 run : flutter pub get
4847
49- # Step 5: Decode signing secrets for keystore and properties
48+ # Step 5: Decode signing secrets
5049 - name : Decode Signing Secrets
5150 env :
5251 NIGHTLY_KEYSTORE_B64 : ${{ secrets.NIGHTLY_KEYSTORE_B64 }}
@@ -55,28 +54,33 @@ jobs:
5554 echo "$NIGHTLY_KEYSTORE_B64" | base64 --decode > android/nightly.jks
5655 echo "$NIGHTLY_PROPERTIES_B64" | base64 --decode > android/key_nightly.properties
5756
58- # Step 6: Build the APK with nightly flavor and release mode
57+ # Step 6: Build the APK
5958 - name : Build APK
6059 run : flutter build apk --flavor nightly --build-number=${{ github.run_number }} --release
6160
6261 # Step 7: Verify the APK is signed
6362 - name : Verify sign
6463 run : keytool -printcert -jarfile build/app/outputs/flutter-apk/app-nightly-release.apk
6564
66- # Step 8: Configure git and push the APK to fdroid-repo branch
67- - name : Configure and push to fdroid-repo
65+ # Step 8: Configure git, fetch existing repo, and place new APK
66+ # We fetch the repo so we can see existing APKs to prune them in the next step.
67+ - name : Configure and Prepare Files
6868 run : |
6969 git config --global user.name "github-actions[bot]"
7070 git config --global user.email "github-actions[bot]@users.noreply.github.com"
71- # Fetch only the specific branch needed (works even with shallow checkout)
72- git fetch origin fdroid-repo:fdroid-repo
73- git stash || echo "No changes to stash"
74- git checkout fdroid-repo
71+
72+ # Fetch the target branch to get existing APKs (if branch exists)
73+ git fetch origin fdroid-repo:fdroid-repo || echo "Branch not found, proceeding..."
74+
75+ # Switch to that branch or create if it doesn't exist (to setup folder structure)
76+ git checkout fdroid-repo || git checkout --orphan fdroid-repo
77+
78+ # Move the newly built APK into the repo folder
79+ # Ensure repo dir exists
80+ mkdir -p repo
7581 mv build/app/outputs/flutter-apk/app-nightly-release.apk repo/nightly.${{ github.run_number }}.apk
76- git add repo/
77- git commit -m "chore: Add new signed APK from build ${{ github.run_number }}"
7882
79- # Step 9: Prune old APKs, keeping only the 5 most recent
83+ # Step 9: Prune Old APKs, keeping only the 5 most recent
8084 - name : Prune Old APKs
8185 run : |
8286 echo "Checking for old APKs to prune..."
8791 echo "5 or fewer APKs found. No cleanup needed."
8892 fi
8993
90- # Step 10: Setup F-Droid and update the repo
94+ # Step 10: Setup F-Droid and update the repo metadata
9195 - name : Run F-Droid Update
9296 env :
9397 FDROID_CONFIG_YML_B64 : ${{ secrets.FDROID_CONFIG_YML }}
@@ -104,9 +108,19 @@ jobs:
104108 # Run the update command
105109 fdroid update -c
106110
107- # Step 11: Push the updated repo files with amended commit
111+ # Step 11: Push a fresh history with NO bloat
112+ # This creates a temporary orphan branch (no parents) containing ONLY
113+ # the files currently on disk, then force pushes it to replace fdroid-repo.
108114 - name : Push F-Droid updates
109115 run : |
116+ # Create a temporary orphan branch (fresh start, no history)
117+ git checkout --orphan temp_deploy_branch
118+
119+ # Add all files currently on disk (New APK + 4 Old APKs + New Index)
110120 git add .
111- git commit --amend -m "chore: Add new signed APK from build ${{ github.run_number }} and update F-Droid metadata"
112- git push origin fdroid-repo --force
121+
122+ # Create a new 'Initial Commit'
123+ git commit -m "chore: Update F-Droid repo (Build ${{ github.run_number }})"
124+
125+ # Force push this new state to overwrite fdroid-repo
126+ git push origin temp_deploy_branch:fdroid-repo --force
0 commit comments