|
1 |
| -# This is a Semaphore configuration file for Flutter projects using Docker |
2 |
| -# For more information about Semaphore configuration visit: |
3 |
| -# https://docs.semaphoreci.com/reference/pipeline-yaml-reference/ |
| 1 | +# π Semaphore docs: |
| 2 | +# - Pipeline YAML reference: https://docs.semaphoreci.com/reference/pipeline-yaml |
| 3 | +# - Job parallelism: https://docs.semaphoreci.com/using-semaphore/jobs/#job-parallelism |
| 4 | +# - Cache: https://docs.semaphoreci.com/using-semaphore/optimization/cache |
| 5 | +# - Test Reports: https://docs.semaphoreci.com/using-semaphore/tests/test-reports |
| 6 | +# - Artifacts: https://docs.semaphoreci.com/using-semaphore/artifacts |
4 | 7 |
|
5 |
| -version: v1.0 # Semaphore configuration version |
6 |
| -name: "π Flutter CI Pipeline" # Pipeline display name |
| 8 | +version: v1.0 |
| 9 | +name: "π³ Flutter (Docker) β’ Web build" |
7 | 10 |
|
8 |
| -# Define the machine type, OS image, and containers |
9 | 11 | agent:
|
10 | 12 | machine:
|
11 | 13 | type: {{ machine_type }}
|
12 | 14 | os_image: {{ os_image }}
|
13 |
| - |
14 | 15 | containers:
|
15 | 16 | - name: main
|
16 |
| - image: 'registry.semaphoreci.com/flutter:3.16' # Flutter 3.16 container |
| 17 | + image: registry.semaphoreci.com/android:34-flutter |
| 18 | + |
17 | 19 |
|
18 |
| -# Configure when to stop the pipeline early |
19 | 20 | fail_fast:
|
| 21 | + # π΄ Stop all running jobs on failure (configurable): |
| 22 | + # https://docs.semaphoreci.com/reference/pipeline-yaml/#fail_fast |
20 | 23 | stop:
|
21 |
| - when: branch != 'main' # Stop all blocks if a job fails on non-main branches |
| 24 | + when: branch != 'main' |
| 25 | + |
22 | 26 | auto_cancel:
|
| 27 | + # π Auto-cancel superseded pipelines on new pushes to the same branch: |
| 28 | + # https://docs.semaphoreci.com/reference/pipeline-yaml/#auto_cancel |
23 | 29 | running:
|
24 |
| - when: branch != 'main' # Cancel running pipelines on non-main branches |
| 30 | + when: branch != 'main' |
25 | 31 | queued:
|
26 |
| - when: branch = 'main' # Cancel queued pipelines on main branch |
| 32 | + when: branch != 'main' |
27 | 33 |
|
28 |
| -# Commands to run before each job |
29 | 34 | global_job_config:
|
| 35 | + env_vars: |
| 36 | + - name: FLUTTER_HOME |
| 37 | + value: $HOME/flutter |
| 38 | + - name: PATH |
| 39 | + value: '$HOME/.pub-cache/bin:$FLUTTER_HOME/bin:$PATH' |
| 40 | + - name: JUNIT_FILE |
| 41 | + value: test-results/junit.xml |
30 | 42 | prologue:
|
31 | 43 | commands:
|
32 |
| - - checkout # Get the code from repository |
33 |
| - - flutter pub get # Install dependencies |
34 |
| - - cache restore # Restore cached dependencies |
| 44 | + - checkout |
| 45 | + # πΎ Restore dependency cache (keyed by pubspec.lock): |
| 46 | + # https://docs.semaphoreci.com/using-semaphore/optimization/cache |
| 47 | + - cache restore "pub-cache-$(checksum pubspec.lock)" |
| 48 | + # If the container doesn't include Flutter, install it; otherwise, reuse preinstalled toolchain. |
| 49 | + - 'command -v flutter >/dev/null 2>&1 || git clone --depth 1 -b stable https://github.com/flutter/flutter.git "$FLUTTER_HOME"' |
| 50 | + - flutter --version |
| 51 | + - flutter doctor -v |
| 52 | + - flutter pub get |
| 53 | + # π§Ύ JUnit converter used by Test Reports: |
| 54 | + # https://docs.semaphoreci.com/using-semaphore/tests/test-reports |
| 55 | + - dart pub global activate junitreport |
| 56 | + epilogue: |
| 57 | + always: |
| 58 | + commands: |
| 59 | + # π Publish job-level test results to Test Reports UI (safe if file missing): |
| 60 | + # https://docs.semaphoreci.com/using-semaphore/tests/test-reports |
| 61 | + - '[[ -f "$JUNIT_FILE" ]] && test-results publish "$JUNIT_FILE" || true' |
35 | 62 |
|
36 |
| -# Pipeline blocks represent groups of jobs that can run in parallel |
37 | 63 | blocks:
|
38 |
| - # Block for setting up dependencies and caching |
39 |
| - - name: "π Setup and Cache" |
40 |
| - dependencies: [] |
| 64 | + - name: "π§Ή Quality" |
41 | 65 | task:
|
42 | 66 | jobs:
|
43 |
| - - name: Install Dependencies |
| 67 | + - name: "π§Ό Format" |
44 | 68 | commands:
|
45 |
| - - cache store # Cache dependencies for future runs |
46 |
| - |
47 |
| - # Block for code quality checks |
48 |
| - - name: "π Code Quality" |
49 |
| - dependencies: ["π Setup and Cache"] |
50 |
| - task: |
51 |
| - jobs: |
52 |
| - - name: Analyze and Format |
| 69 | + - flutter format --set-exit-if-changed . |
| 70 | + - name: "π Analyze" |
53 | 71 | commands:
|
54 |
| - - flutter analyze # Static code analysis |
55 |
| - - flutter format --set-exit-if-changed . # Check code formatting |
| 72 | + - flutter analyze . |
| 73 | + dependencies: [] |
56 | 74 |
|
57 |
| - # Block for security checks |
58 |
| - - name: "π Security Checks" |
59 |
| - dependencies: ["π Setup and Cache"] |
| 75 | + - name: "π§ͺ Tests (parallel)" |
60 | 76 | task:
|
61 | 77 | jobs:
|
62 |
| - - name: Security Scan |
| 78 | + - name: "π§ͺ Flutter tests (sharded)" |
| 79 | + # β‘οΈ Fan out a single job into N parallel jobs: |
| 80 | + # https://docs.semaphoreci.com/using-semaphore/jobs/#job-parallelism |
| 81 | + parallelism: 4 |
63 | 82 | commands:
|
64 |
| - - flutter pub outdated # Check for outdated dependencies |
65 |
| - - flutter pub deps # Display dependency tree |
| 83 | + - mkdir -p test-results |
| 84 | + # Convert 1-based SEMAPHORE_JOB_INDEX -> 0-based shard index for Flutter/Dart |
| 85 | + - export SHARD_INDEX=$((SEMAPHORE_JOB_INDEX - 1)) |
| 86 | + - echo "Shard $SHARD_INDEX of $SEMAPHORE_JOB_COUNT" |
| 87 | + # π§Ύ Produce JUnit via tojunit for Test Reports: |
| 88 | + # https://docs.semaphoreci.com/using-semaphore/tests/test-reports |
| 89 | + - flutter test --machine --total-shards $SEMAPHORE_JOB_COUNT --shard-index $SHARD_INDEX | tojunit --output $JUNIT_FILE |
| 90 | + dependencies: |
| 91 | + - "π§Ή Quality" |
66 | 92 |
|
67 |
| - # Block for running tests |
68 |
| - - name: "π§ͺ Test Suite" |
69 |
| - dependencies: ["π Setup and Cache"] |
| 93 | + - name: "π‘οΈ Security (pub deps)" |
70 | 94 | task:
|
71 | 95 | jobs:
|
72 |
| - - name: "π’ Flutter Tests" |
73 |
| - parallelism: 4 # Run tests in parallel |
| 96 | + - name: "π‘οΈ Pub outdated (informational)" |
74 | 97 | commands:
|
75 |
| - - flutter test --coverage # Run tests with coverage |
76 |
| - - flutter pub global activate remove_from_coverage |
77 |
| - - flutter pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$' # Remove generated files from coverage |
| 98 | + - dart pub outdated || true |
| 99 | + dependencies: |
| 100 | + - "π§ͺ Tests (parallel)" |
78 | 101 |
|
79 |
| - # Block for building the app |
80 |
| - - name: "π¦ Build" |
81 |
| - dependencies: ["π§ͺ Test Suite"] |
| 102 | + - name: "π¦ Build Web (artifact)" |
| 103 | + dependencies: |
| 104 | + - "π§ͺ Tests (parallel)" |
| 105 | + skip: |
| 106 | + when: branch != 'main' |
82 | 107 | task:
|
83 | 108 | jobs:
|
84 |
| - - name: Android Build |
| 109 | + - name: "π flutter build web" |
85 | 110 | commands:
|
86 |
| - - flutter build apk --release # Build Android APK |
87 |
| - - name: iOS Build |
88 |
| - commands: |
89 |
| - - flutter build ios --release --no-codesign # Build iOS without signing |
| 111 | + - flutter build web --release |
| 112 | + # π¦ Store build output as an artifact: |
| 113 | + # https://docs.semaphoreci.com/using-semaphore/artifacts |
| 114 | + - artifact push job build/web |
| 115 | + |
| 116 | +after_pipeline: |
| 117 | + task: |
| 118 | + jobs: |
| 119 | + - name: "π Merge test reports" |
| 120 | + commands: |
| 121 | + # π§© Merge all job reports into a single pipeline report: |
| 122 | + # https://docs.semaphoreci.com/using-semaphore/tests/test-reports |
| 123 | + - test-results gen-pipeline-report |
0 commit comments