|
1 |
| -name: Flutter Build |
| 1 | +name: Flutter Android Build |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 |
| - branches: |
6 |
| - - main |
| 5 | + branches: [main] # Adjust this to match your main branch name (e.g., master, main, develop) |
| 6 | + tags: |
| 7 | + - "v*" # This will trigger the workflow when you push a tag starting with 'v' |
| 8 | + |
| 9 | +# Add permissions needed for creating releases |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + packages: write |
7 | 13 |
|
8 | 14 | jobs:
|
9 | 15 | build:
|
10 | 16 | runs-on: ubuntu-latest
|
11 |
| - |
12 | 17 | steps:
|
13 | 18 | - name: Checkout code
|
14 |
| - uses: actions/checkout@v4 |
| 19 | + uses: actions/checkout@v3 |
| 20 | + |
| 21 | + - name: Set up Java |
| 22 | + uses: actions/setup-java@v3 |
| 23 | + with: |
| 24 | + distribution: "zulu" |
| 25 | + java-version: "17" |
| 26 | + cache: gradle |
15 | 27 |
|
16 | 28 | - name: Set up Flutter
|
17 | 29 | uses: subosito/flutter-action@v2
|
18 | 30 | with:
|
19 |
| - flutter-version: "stable" |
| 31 | + flutter-version: "3.29.2" |
20 | 32 | channel: "stable"
|
21 |
| - |
22 |
| - - name: Cache Flutter dependencies |
23 |
| - uses: actions/cache@v3 |
24 |
| - with: |
25 |
| - path: ~/.pub-cache |
26 |
| - key: ${{ runner.os }}-pub-cache-${{ hashFiles('**/pubspec.yaml') }} |
27 |
| - restore-keys: | |
28 |
| - ${{ runner.os }}-pub-cache- |
| 33 | + cache: true |
29 | 34 |
|
30 | 35 | - name: Install dependencies
|
31 | 36 | run: flutter pub get
|
32 | 37 |
|
33 | 38 | - name: Build APK
|
34 | 39 | run: flutter build apk --release
|
35 | 40 |
|
36 |
| - - name: Upload APK |
37 |
| - uses: actions/upload-artifact@v4 |
| 41 | + - name: Upload APK as artifact |
| 42 | + uses: actions/upload-artifact@v4.6.2 |
38 | 43 | with:
|
39 |
| - name: flutter-apk |
| 44 | + name: app-release |
40 | 45 | path: build/app/outputs/flutter-apk/app-release.apk
|
41 |
| - retention-days: 7 |
| 46 | + |
| 47 | + - name: Get version from pubspec |
| 48 | + id: get_version |
| 49 | + if: startsWith(github.ref, 'refs/heads/main') |
| 50 | + run: | |
| 51 | + VERSION=$(grep 'version:' pubspec.yaml | awk '{print $2}' | tr -d "'" | tr -d '"') |
| 52 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 53 | +
|
| 54 | + - name: Create Release |
| 55 | + id: create_release |
| 56 | + if: startsWith(github.ref, 'refs/heads/main') |
| 57 | + |
| 58 | + with: |
| 59 | + tag_name: v${{ env.VERSION }} |
| 60 | + name: Release v${{ env.VERSION }} |
| 61 | + draft: false |
| 62 | + prerelease: false |
| 63 | + files: build/app/outputs/flutter-apk/app-release.apk |
| 64 | + generate_release_notes: true |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments