|
3 | 3 | # separate terms of service, privacy policy, and support |
4 | 4 | # documentation. |
5 | 5 |
|
6 | | -name: Dart |
| 6 | +name: Flutter Android Build & Upload |
| 7 | + |
| 8 | +# Define environment variables for easy modification |
| 9 | +env: |
| 10 | + # The name of your main Flutter project module (usually 'app' for Flutter) |
| 11 | + MAIN_PROJECT_MODULE: app |
| 12 | + # A general descriptor for the build context (e.g., 'GitHub-Release', 'CI-Build') |
| 13 | + BUILD_CONTEXT_NAME: GitHub-Release |
7 | 14 |
|
8 | 15 | on: |
9 | 16 | push: |
10 | | - branches: [ "main" ] |
| 17 | + branches: |
| 18 | + - "main" |
| 19 | + # If you have other development branches you want to trigger builds on, add them here: |
| 20 | + # - 'develop' |
| 21 | + # - 'feature/**' |
| 22 | + |
11 | 23 | pull_request: |
12 | | - branches: [ "main" ] |
| 24 | + branches: |
| 25 | + - "main" |
| 26 | + |
| 27 | + # Allows you to run this workflow manually from the Actions tab |
| 28 | + workflow_dispatch: |
13 | 29 |
|
14 | 30 | jobs: |
15 | 31 | build: |
16 | | - runs-on: ubuntu-latest |
| 32 | + runs-on: ubuntu-latest # Using a Linux runner for building Android artifacts |
17 | 33 |
|
18 | 34 | steps: |
19 | | - - uses: actions/checkout@v4 |
| 35 | + - name: Checkout Repository |
| 36 | + uses: actions/checkout@v4 # Action to check out your repository code |
| 37 | + |
| 38 | + # Set Current Date As Env Variable for artifact naming |
| 39 | + - name: Set current date as env variable |
| 40 | + run: echo "DATE_TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV |
20 | 41 |
|
21 | | - # Note: This workflow uses the latest stable version of the Dart SDK. |
22 | | - # You can specify other versions if desired, see documentation here: |
23 | | - # https://github.com/dart-lang/setup-dart/blob/main/README.md |
24 | | - # - uses: dart-lang/setup-dart@v1 |
25 | | - - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603 |
| 42 | + # Set Repository Name As Env Variable for artifact naming |
| 43 | + - name: Set repository name as env variable |
| 44 | + run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV |
26 | 45 |
|
27 | | - - name: Install dependencies |
28 | | - run: dart pub get |
| 46 | + # Setup Flutter SDK |
| 47 | + # This action sets up Flutter and Dart SDKs |
| 48 | + - name: Setup Flutter SDK |
| 49 | + uses: subosito/flutter-action@v2 # Using a dedicated Flutter setup action |
| 50 | + with: |
| 51 | + flutter-version: '3.x.x' # Specify your Flutter version, e.g., '3.19.x' or 'stable' |
| 52 | + channel: 'stable' # Or 'beta', 'dev' depending on your needs |
| 53 | + cache: true # Enable caching for Flutter dependencies |
29 | 54 |
|
30 | | - # Uncomment this step to verify the use of 'dart format' on each commit. |
| 55 | + - name: Install Flutter dependencies |
| 56 | + run: flutter pub get # Get all your project's Dart/Flutter dependencies |
| 57 | + |
| 58 | + # Optional: Verify formatting (uncomment if you use dart format) |
31 | 59 | # - name: Verify formatting |
32 | 60 | # run: dart format --output=none --set-exit-if-changed . |
33 | 61 |
|
34 | | - # Consider passing '--fatal-infos' for slightly stricter analysis. |
| 62 | + # Analyze project source for potential issues |
35 | 63 | - name: Analyze project source |
36 | | - run: dart analyze |
37 | | - |
38 | | - # Your project will need to have tests in test/ and a dependency on |
39 | | - # package:test for this step to succeed. Note that Flutter projects will |
40 | | - # want to change this to 'flutter test'. |
41 | | - - name: Run tests |
42 | | - run: dart test |
43 | | - |
44 | | - - name: Upload a Build Artifact |
45 | | - uses: actions/upload-artifact@v4.6.2 |
46 | | - with: |
47 | | - # Artifact name |
48 | | - name: quitr # optional, default is artifact |
49 | | - # A file, directory or wildcard pattern that describes what to upload |
50 | | - path: |
51 | | - # The desired behavior if no files are found using the provided path. |
52 | | -Available Options: |
53 | | - warn: Output a warning but do not fail the action |
54 | | - error: Fail the action with an error message |
55 | | - ignore: Do not output any warnings or errors, the action does not fail |
56 | | - |
57 | | - if-no-files-found: # optional, default is warn |
58 | | - # Duration after which artifact will expire in days. 0 means using default retention. |
59 | | -Minimum 1 day. Maximum 90 days unless changed from the repository settings page. |
60 | | - |
61 | | - retention-days: # optional |
62 | | - # The level of compression for Zlib to be applied to the artifact archive. The value can range from 0 to 9: - 0: No compression - 1: Best speed - 6: Default compression (same as GNU Gzip) - 9: Best compression Higher levels will result in better compression, but will take longer to complete. For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads. |
63 | | - |
64 | | - compression-level: # optional, default is 6 |
65 | | - # If true, an artifact with a matching name will be deleted before a new one is uploaded. If false, the action will fail if an artifact for the given name already exists. Does not fail if the artifact does not exist. |
66 | | - |
67 | | - overwrite: # optional, default is false |
68 | | - # If true, hidden files will be included in the artifact. If false, hidden files will be excluded from the artifact. |
69 | | - |
70 | | - include-hidden-files: # optional, default is false |
71 | | - |
| 64 | + run: flutter analyze # Use flutter analyze for Flutter projects |
| 65 | + |
| 66 | + # Run Flutter tests |
| 67 | + - name: Run Flutter tests |
| 68 | + run: flutter test # Use flutter test for Flutter projects |
| 69 | + |
| 70 | + # --- Build Android Artifacts --- |
| 71 | + |
| 72 | + # Build Debug APK |
| 73 | + - name: Build Debug APK |
| 74 | + run: flutter build apk --debug |
| 75 | + |
| 76 | + # Build Release APK |
| 77 | + # This will build a signed release APK (if you have signing configured) |
| 78 | + - name: Build Release APK |
| 79 | + run: flutter build apk --release |
| 80 | + |
| 81 | + # Build Release App Bundle (AAB) |
| 82 | + # This is the recommended format for Play Store uploads, but can still be useful for GitHub Releases |
| 83 | + - name: Build Release App Bundle (AAB) |
| 84 | + run: flutter build appbundle --release |
| 85 | + |
| 86 | + # --- Upload Artifacts to GitHub --- |
| 87 | + |
| 88 | + # Upload Debug APK(s) |
| 89 | + - name: Upload Debug APK(s) - ${{ env.REPOSITORY_NAME }} |
| 90 | + uses: actions/upload-artifact@v4.6.2 |
| 91 | + with: |
| 92 | + # Changed artifact name to be more generic for GitHub-only |
| 93 | + name: ${{ env.REPOSITORY_NAME }}-${{ env.BUILD_CONTEXT_NAME }}-${{ env.DATE_TODAY }}-debug-APKs |
| 94 | + path: build/app/outputs/flutter-apk/*.apk # Path to generated debug APKs |
| 95 | + if-no-files-found: error # Fail if no APKs are found |
| 96 | + retention-days: 7 # Keep artifacts for 7 days |
| 97 | + |
| 98 | + # Upload Release APK(s) |
| 99 | + - name: Upload Release APK(s) - ${{ env.REPOSITORY_NAME }} |
| 100 | + uses: actions/upload-artifact@v4.6.2 |
| 101 | + with: |
| 102 | + # Changed artifact name to be more generic for GitHub-only |
| 103 | + name: ${{ env.REPOSITORY_NAME }}-${{ env.BUILD_CONTEXT_NAME }}-${{ env.DATE_TODAY }}-release-APKs |
| 104 | + path: build/app/outputs/flutter-apk/*.apk # Path to generated release APKs |
| 105 | + if-no-files-found: error |
| 106 | + retention-days: 30 # Keep release artifacts longer |
| 107 | + |
| 108 | + # Upload Release App Bundle (AAB) |
| 109 | + - name: Upload AAB (App Bundle) Release - ${{ env.REPOSITORY_NAME }} |
| 110 | + uses: actions/upload-artifact@v4.6.2 |
| 111 | + with: |
| 112 | + # Changed artifact name to be more generic for GitHub-only |
| 113 | + name: ${{ env.REPOSITORY_NAME }}-${{ env.BUILD_CONTEXT_NAME }}-${{ env.DATE_TODAY }}-release-AAB |
| 114 | + path: build/app/outputs/bundle/release/*.aab # Path to generated AAB |
| 115 | + if-no-files-found: error |
| 116 | + retention-days: 90 # Keep AABs for longest retention |
0 commit comments