Week 13

CI/CD and Automation

Mobile Programming

GitHub Actions | Automated Tests | APK/AAB Builds | Safer Releases

Turn every code change into a consistent, tested, and traceable process.

Learning Objectives

By the end of this session, students should be able to:

  1. Explain continuous integration and continuous delivery/deployment.
  2. Create a GitHub Actions workflow for Flutter analysis, tests, and builds.
  3. Produce APK/AAB files and store them as workflow artifacts.
  4. Apply versioning and distinguish public configuration from secrets.
  5. Review workflow triggers and permissions before enabling them.

From Commit to Artifact

  1. Change — a commit or pull request is created.
  2. Check — dependencies, static analysis, and tests run.
  3. Build — the app is packaged as an APK or AAB.
  4. Distribute — the artifact is stored or passed to a release process.
  • CI automatically checks code changes.
  • CD automates release preparation or delivery.
  • A green build is useful, but it does not prove the app is bug-free.

When Does a Workflow Run?

Trigger Example use
pull_request Check changes before merging
push to main Validate the main branch
Version tag, e.g. v1.2.0 Prepare release artifacts
Manual (workflow_dispatch) Run a controlled validation
  • Start with only the triggers you need.
  • Pull requests from forks do not receive repository secrets.
  • Do not grant write access to jobs that only read code.

GitHub Actions Workflow Parts

  • Workflow: a YAML file under .github/workflows/.
  • Event: the change that starts a workflow.
  • Job: a unit of work on a runner, such as Linux.
  • Step: an action or shell command.
  • Artifact: a build file that can be downloaded after a job.

Make triggers, permissions, steps, and outputs easy to review.

Flutter Pipeline: Checks

steps:
  - uses: actions/checkout@v4
  - uses: subosito/flutter-action@v2
    with:
      channel: stable
  - run: flutter pub get
  - run: dart format --output=none --set-exit-if-changed .
  - run: flutter analyze --fatal-infos
  - run: flutter test --coverage
  • Run the same checks locally before pushing.
  • A failing test must fail the job; do not ignore its exit code.

Flutter Pipeline: Builds and Artifacts

  - run: flutter build apk --release
  - run: flutter build appbundle --release
  - uses: actions/upload-artifact@v4
    with:
      name: android-builds
      path: |
        build/app/outputs/flutter-apk/app-release.apk
        build/app/outputs/bundle/release/app-release.aab
      if-no-files-found: error
      retention-days: 7
  • APKs are convenient for internal testing; AABs are used in Play Store workflows.
  • A successful build is not necessarily release-ready: validate signing, configuration, and target devices.

Traceable Versions and Releases

Example version in pubspec.yaml:

version: 1.2.0+15
  • 1.2.0 is the semantic version: major, minor, patch.
  • 15 is the build number; increment it for each new upload.
  • Link a release to its commit/tag, such as v1.2.0.
  • Keep artifacts with commit notes and test results.

Not All Configuration Is Secret

  • A service URL or environment name is usually configuration, not a credential.
  • Private tokens, passwords, and keystores belong in GitHub Secrets.
  • Never put secrets in source code, logs, commits, or tracked config files.
  • --dart-define embeds values in the app; do not use it to hide secrets.
  • Restrict permissions and artifact retention to what is needed.

A key shipped to a client app can be extracted. Server secrets must stay on the server.

AI as a Workflow Assistant

AI can draft YAML or explain a failure, but:

  • verify every trigger, permission, action, and shell command;
  • confirm that a failing test really fails the job;
  • make sure sensitive data is not printed or sent to third parties;
  • run the workflow and inspect logs and artifacts yourself.

Challenge: ask AI to review a workflow, then compare its findings with the actual file and run logs.

Lab and Reflection

  1. Add a CI workflow to a Flutter project that already has tests.
  2. Run it on a pull request and inspect analysis, tests, and build results.
  3. Download the APK/AAB artifact and record the commit that produced it.
  4. Note the next version and plan a safe release trigger.
  • Which check finds problems earliest?
  • Who can access workflow artifacts and secrets?
  • Is your build ready to release, or has it only compiled successfully?

References

  • GitHub Actions: docs.github.com/actions
  • Building and testing Flutter: docs.flutter.dev/deployment/cd
  • Flutter Android deployment: docs.flutter.dev/deployment/android
  • GitHub encrypted secrets: docs.github.com/actions/security-guides/using-secrets-in-github-actions
  • Semantic Versioning: semver.org

Remember: a good pipeline repeats the process consistently and makes results reviewable.