Skip to content

Commit 4f22281

Browse files
committed
workflow: fix workflow making repository size large on every deploy
1 parent be1d5d5 commit 4f22281

File tree

2 files changed

+64
-26
lines changed

2 files changed

+64
-26
lines changed

.github/workflows/fdroidupdateci.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ on:
66
- fdroid-repo
77

88
jobs:
9-
build:
9+
deploy-changes:
10+
name: Deploy Changes
1011
runs-on: ubuntu-latest
1112

1213
steps:
13-
- name: Fdroid Install
14-
uses: subosito/flutter-action@v1
14+
# Step 1: Checkout is REQUIRED to access the APKs and repo files
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
18+
# Step 2: Java is REQUIRED for keystore operations and apksigner
19+
- uses: actions/setup-java@v4
20+
with:
21+
distribution: "temurin"
22+
java-version: "17.x"
23+
24+
# Step 3: Run F-Droid Update
1525
- name: Run F-Droid Update
1626
env:
1727
FDROID_CONFIG_YML_B64: ${{ secrets.FDROID_CONFIG_YML }}
@@ -25,11 +35,25 @@ jobs:
2535
sudo apt-get update
2636
sudo apt-get install -y fdroidserver
2737
28-
# Run the update command, referencing the files
38+
# Run the update command (updates index.xml based on current APKs)
2939
fdroid update -c
3040
41+
# Step 4: Push with Zero Bloat (Orphan Branch Strategy)
3142
- name: Push F-Droid updates
3243
run: |
44+
git config --global user.name "github-actions[bot]"
45+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
46+
47+
# 1. Create a temporary orphan branch (fresh start, no history)
48+
# This keeps the current files (APKs + updated index) but removes the commit history links
49+
git checkout --orphan temp_update_branch
50+
51+
# 2. Add all files currently on disk
3352
git add .
34-
git commit --amend -m "update: a repo update ${{ github.run_number }}"
35-
git push origin fdroid-repo --force
53+
54+
# 3. Create a new 'Initial Commit'
55+
git commit -m "chore: Update F-Droid index ${{ github.run_number }}"
56+
57+
# 4. Force push this new state to overwrite fdroid-repo
58+
# The branch will now have exactly 1 commit total.
59+
git push origin temp_update_branch:fdroid-repo --force

.github/workflows/nightlydepolyci.yml

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ jobs:
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:
@@ -46,7 +45,7 @@ jobs:
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..."
@@ -87,7 +91,7 @@ jobs:
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

Comments
 (0)