-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (131 loc) · 5.45 KB
/
android-deploy.yml
File metadata and controls
152 lines (131 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: FxFiles Android Deploy
on:
workflow_dispatch:
release:
types: [published]
jobs:
deploy-android:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space
run: |
echo "Disk space before cleanup:"
df -h
# Remove unused software to free up space
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android/sdk/ndk
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/share/boost
sudo rm -rf /usr/share/swift
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
# Remove Docker images
sudo docker image prune --all --force || true
# Clean apt cache
sudo apt-get clean
echo "Disk space after cleanup:"
df -h
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.38.5'
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- name: Flutter Doctor
run: flutter doctor -v
- name: Get Dependencies
run: flutter pub get
- name: Set Production Package Name
run: |
echo "Changing package name from land.fx.files.dev to land.fx.files for production..."
# Update build.gradle.kts
sed -i 's/namespace = "land.fx.files.dev"/namespace = "land.fx.files"/' android/app/build.gradle.kts
sed -i 's/applicationId = "land.fx.files.dev"/applicationId = "land.fx.files"/' android/app/build.gradle.kts
# Update package declarations in all Kotlin files
for file in android/app/src/main/kotlin/land/fx/files/dev/*.kt; do
sed -i 's/^package land.fx.files.dev$/package land.fx.files/' "$file"
echo "Updated package in: $file"
done
# Move all Kotlin files to production package directory
mkdir -p android/app/src/main/kotlin/land/fx/files
mv android/app/src/main/kotlin/land/fx/files/dev/*.kt android/app/src/main/kotlin/land/fx/files/
rm -rf android/app/src/main/kotlin/land/fx/files/dev
echo "Package name updated to land.fx.files"
echo "Verifying changes..."
grep -n "namespace\|applicationId" android/app/build.gradle.kts
ls -la android/app/src/main/kotlin/land/fx/files/
head -1 android/app/src/main/kotlin/land/fx/files/*.kt
- name: Get Package Version
run: |
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //' | tr -d ' ')
echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
echo "App version: $VERSION"
- name: Decode Keystore
run: echo "${{ secrets.SIGNING_KEY_BASE64 }}" | base64 -d > ${{ github.workspace }}/android/app/signingKey.jks
- name: Create key.properties
run: |
echo "storePassword=${{ secrets.KEY_STORE_PASSWORD }}" > ${{ github.workspace }}/android/key.properties
echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> ${{ github.workspace }}/android/key.properties
echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> ${{ github.workspace }}/android/key.properties
echo "storeFile=${{ github.workspace }}/android/app/signingKey.jks" >> ${{ github.workspace }}/android/key.properties
- name: Build Android App Bundle
run: flutter build appbundle --release
- name: List Build Output
run: ls -la ${{ github.workspace }}/build/app/outputs/bundle/release/
- name: Get Release Info
id: get-release-info
uses: actions/github-script@v5
with:
script: |
let releaseId = 0;
try {
const release = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
releaseId = release.data.id;
} catch (error) {
console.log('Error fetching latest release: ', error.message);
}
return releaseId;
- name: Print Release ID
run: echo "Release ID is ${{ steps.get-release-info.outputs.result }}"
- name: Upload AAB to Release
uses: actions/github-script@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const path = require('path');
const directory = '${{ github.workspace }}/build/app/outputs/bundle/release';
const files = fs.readdirSync(directory);
for (const file of files) {
if (file.endsWith('.aab')) {
const filePath = path.join(directory, file);
console.log(`Uploading ${file}...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.get-release-info.outputs.result }},
name: `FxFiles_v${{ env.APP_VERSION }}_${file}`,
data: fs.readFileSync(filePath)
});
}
}
# Optional: Upload to Google Play using Fastlane or r0adkll/upload-google-play
# - name: Upload to Google Play
# uses: r0adkll/upload-google-play@v1
# with:
# serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
# packageName: land.fx.files
# releaseFiles: build/app/outputs/bundle/release/app-release.aab
# track: internal
# status: completed