1- name : Flutter CI/CD
1+ name : Flutter CI/CD - Build APK & Deploy Web
22
33on :
44 push :
5- branches : [ release ]
6- pull_request :
7- branches : [ release ]
5+ branches : [release]
6+ tags :
7+ - ' v*' # Trigger on version tags (e.g., v1.0.0)
8+
9+ env :
10+ FLUTTER_VERSION : ' 3.38.5' # Specify your Flutter version
11+ BUILD_NUMBER : ${{ github.run_number }}
12+ BUILD_DATE : ${{ github.event.head_commit.timestamp }}
813
914jobs :
10- deploy-apk :
11- name : Build Android APK
15+ build-android :
1216 runs-on : ubuntu-latest
13-
17+ permissions :
18+ contents : write # Required for creating releases
19+
1420 steps :
15- - uses : actions/checkout@v4
16-
17- - name : Set up Java
18- uses : actions/setup-java@v3
19- with :
20- distribution : ' temurin'
21- java-version : ' 21'
22-
23- - name : Set up Flutter
24- uses : subosito/flutter-action@v2
25- with :
26- flutter-version : ' 3.38.5'
27- channel : stable
28- cache : true
29-
30- - name : Install dependencies
31- run : flutter pub get
32-
33- - name : Analyze code
34- run : flutter analyze
21+ - name : Checkout code
22+ uses : actions/checkout@v4
3523
36- # - name: Run tests
37- # run: flutter test
24+ - name : Set up Java
25+ uses : actions/setup-java@v3
26+ with :
27+ distribution : ' temurin'
28+ java-version : ' 21'
29+
30+ - name : Set up Flutter
31+ uses : subosito/flutter-action@v2
32+ with :
33+ flutter-version : ${{ env.FLUTTER_VERSION }}
34+ channel : stable
35+ cache : true
36+
37+ - name : Install dependencies
38+ run : flutter pub get
39+
40+ - name : Verify Flutter installation
41+ run : flutter doctor -v
42+
43+ - name : Build APK (Release - Unsigned)
44+ run : |
45+ flutter build apk --release --no-shrink
46+ echo "APK built successfully!"
47+ ls -la build/app/outputs/flutter-apk/
48+
49+ - name : Upload APK artifact
50+ uses : actions/upload-artifact@v4
51+ with :
52+ name : app-release-unsigned
53+ path : build/app/outputs/flutter-apk/app-release.apk
54+ retention-days : 2
55+
56+ - name : Create GitHub Release
57+ if : startsWith(github.ref, 'refs/tags/v')
58+ uses : softprops/action-gh-release@v1
59+ with :
60+ files : build/app/outputs/flutter-apk/app-release.apk
61+ generate_release_notes : true
62+ prerelease : false
63+ draft : false
64+ env :
65+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3866
39- - name : Build APK
40- run : flutter build apk --release
41-
42- - name : Upload artifact
43- uses : actions/upload-artifact@v4
44- with :
45- name : android-release-apk
46- path : build/app/outputs/flutter-apk/app-release.apk
47-
48- - name : Create Release
49- id : create_release
50- uses : actions/create-release@latest
51- env :
52- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53- with :
54- tag_name : ${{ github.ref }}
55- release_name : Release ${{ github.ref }}
56- body : |
57- New release for ${{ github.ref }}.
58- draft : false
59- prerelease : false
60-
61- - name : Create Release and Upload APK
62- uses : softprops/action-gh-release@v2
63- with :
64- tag_name : ${{ github.ref }}
65- files : build/app/outputs/flutter-apk/app-release.apk
66- env :
67- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67+ build-web :
68+ runs-on : ubuntu-latest
69+ needs : build-android # Run after Android build completes
70+ permissions :
71+ contents : write # Required for gh-pages deployment
72+ pages : write
73+ id-token : write
74+
75+ steps :
76+ - name : Checkout code
77+ uses : actions/checkout@v4
78+
79+ - name : Set up Flutter
80+ uses : subosito/flutter-action@v2
81+ with :
82+ flutter-version : ${{ env.FLUTTER_VERSION }}
83+ channel : stable
84+ cache : true
85+
86+ - name : Install dependencies
87+ run : flutter pub get
88+
89+ - name : Build Web App
90+ run : |
91+ flutter config --enable-web
92+ flutter build web --release --base-href "/"
93+ echo "Web build completed!"
94+
95+ - name : Setup Pages
96+ uses : actions/configure-pages@v4
97+
98+ - name : Upload web artifact
99+ uses : actions/upload-pages-artifact@v3
100+ with :
101+ path : build/web
102+
103+ - name : Deploy to GitHub Pages
104+ uses : actions/deploy-pages@v4
105+ with :
106+ token : ${{ secrets.GITHUB_TOKEN }}
107+ target_branch : gh-pages
0 commit comments