configuring-github-actions ยท git:20260331.a8cec9f ยท 2026-03-31 ยท sha256 51e5dd2d81a74515
configuring-github-actions git:20260331.a8cec9fA
Immutable. This exact content never changes and is served at /api/v1/blob/51e5dd2d81a74515.
No tool to install first
claude plugin marketplace add https://markdownregistry.com/mp/a/art_pt46zdhmolscxfqu/51e5dd2d81a74515ada58cefa542a4be908fd54a46eec5648cc2795015a3d8de.json
Then /plugin install configuring-github-actions@markdownregistry-pt46zdhmolscxfqu in Claude Code. It installs this exact version, the one graded A here, pinned to the commit it was graded at, and leaves it there.
---
name: "github-actions"
description: "GitHub Actions CI/CD workflows for Flutter projects including automated testing, building, and deployment. Use when setting up continuous integration, configuring release pipelines, or automating Flutter build processes."
metadata:
last_modified: "2026-03-12 11:18:17 (GMT+8)"
---
# Flutter combined with GitHub Actions Best Practices (CI/CD)
## Goal
Implements robust CI/CD pipelines using GitHub Actions for Flutter projects. GitHub Actions is the most popular CI/CD platform for open-source and small-to-medium projects. By configuring YAML files under `.github/workflows/`, you can achieve high automation.
## Instructions
### 1. Environment Setup & Core Setup
In all Flutter Workflows, the core package to use is the third-party maintained [subosito/flutter-action](https://github.com/subosito/flutter-action).
**Best Practices:**
1. **Bind the Flutter Version**: Never use `channel: stable` or let it automatically fetch the latest version. Explicitly specify `flutter-version` or use `flutter-version-file: pubspec.yaml` to guarantee the CI environment exactly matches the local development environment.
2. **Enable Cache**: `flutter pub get` is a time-consuming step. Always enable `cache: true`.
```yaml
name: Flutter CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build_and_test:
runs-on: ubuntu-latest # If not building iOS, Ubuntu is the fastest and cheapest
steps:
- name: ๐ฆ Checkout repository
uses: actions/checkout@v4
- name: ๐ฆ Setup Flutter (Standard or FVM)
uses: subosito/flutter-action@v2
with:
# ๐ Standard Best Practice: Read from pubspec.yaml
# flutter-version-file: pubspec.yaml
# ๐ FVM Best Practice: If your team uses FVM, read directly from the FVM config!
flutter-version-file: .fvmrc # Or .fvm/fvm_config.json for older FVM versions
cache: true # ๐ Enable pub-cache to significantly speed up subsequent builds
# [Optional] If your strict project requirements dictate that all commands MUST be executed via `fvm flutter ...` instead of natively, you must activate the FVM CLI globally:
# - name: ๐ ๏ธ Install FVM CLI
# run: dart pub global activate fvm
- name: โฌ๏ธ Get packages
# If FVM CLI is installed, this becomes: `fvm flutter pub get`
run: flutter pub get
```
### 2. Code Generation
If the project uses packages relying on `build_runner` (like Freezed, Riverpod, go_router builder), you must execute code generation before testing or compiling.
**Best Practice:**
If it is a Pull Request check, use `build_runner build --delete-conflicting-outputs` to ensure a clean generation state.
```yaml
- name: โ๏ธ Run build_runner
run: dart run build_runner build --delete-conflicting-outputs
```
### 3. Analyze & Test
This is the core defense line of CI (Continuous Integration), and it's recommended to strictly require passing these for every PR.
```yaml
# ๐ Check if code formatting follows Dart guidelines (trailing commas, indentation)
- name: ๐ Analyze Formatting
run: dart format --output=none --set-exit-if-changed .
# ๐ Run static analysis to ensure no warnings or lint errors
- name: ๐จ Analyze Code
run: flutter analyze --no-fatal-warnings
# ๐ Run Unit and Widget Tests (If there are integration tests, set up another job with emulators)
- name: ๐งช Run Tests
run: flutter test --coverage
```
### 4. Build Bundle (Android Example)
If setting up a CD (Continuous Deployment) pipeline, you can automatically build an AAB after tests pass.
```yaml
- name: ๐จ Build Android App Bundle (AAB)
run: flutter build appbundle --release
# Upload the built file to GitHub Actions Artifacts for manual download
- name: ๐ค Upload Artifact
uses: actions/upload-artifact@v4
with:
name: release-aab
path: build/app/outputs/bundle/release/app-release.aab
```
### 5. Deployment and Key Management (Keystore & App Store)
The downside of GitHub Actions is that it **isn't great at handling native certificates**.
* **Android**: You need to convert the `keystore` into a Base64 string, store it in GitHub Secrets, and use a script in the Workflow to convert it back to a file.
* **iOS**: More complicated, requiring the handling of Certificates and Provisioning Profiles.
## Constraints
* **GitHub Actions should primarily be used for CI**: In the Flutter ecosystem, GitHub Actions is typically only used for CI (Analyze, Test, Build_runner) to ensure code quality.
* **Delegate specific deployments to specialized tools**: For actual building and deployment (pushing to App Store/Play Console), delegate to tools optimized for mobile development, like **Fastlane** or **Codemagic** (which natively supports Flutter).