I'm trying out GitHub Actions to build my Flutter app but I don't know which container image to choose from.
Is there a trusted container image that I can use for Flutter?
What are the adjustments I need to make so that the Flutter SDK is available during my build step?
Run flutter pub get
/__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: 1: /__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: flutter: not found
##[error]Process completed with exit code 127.
I adapted the dart.yml file generated by GitHub Actions to look like this:
name: Dart CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
container:
image: google/dart:latest
steps:
- uses: actions/checkout#v1
- name: Install dependencies
run: flutter pub get
- name: Run tests
run: flutter test
You don't need to use a flutter specific container, there is a Flutter Action available that runs on the default Windows, Linux and macOS containers.
This means that building your flutter app is as simple as using the action (you will also need the Java action) and then running the flutter build command. The following example runs an aot build:
on: push
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
# The flutter action needs java so include it
- uses: actions/setup-java#v1
with:
java-version: '12.x'
# Include the flutter action
- uses: subosito/flutter-action#v1
with:
channel: 'stable'
# Get flutter packages
- run: flutter pub get
# Build :D
- run: flutter build aot
I wrote a blog post about building and testing flutter using actions if you'd like to learn more.
I let my one running without Docker.
You could try to install flutter and run flutter pub get. I used in my example subosito/flutter-action#v1
name: CI
on:
pull_request:
branches:
- development
- master
jobs:
test:
name: Flutter Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
flutter-version: '1.7.8+hotfix.4'
- run: flutter doctor
- run: flutter pub get
- run: flutter test
#Rezwan provided the link to the image I was looking for.
I'm still not able to run it due to the following issues:
https://github.com/cirruslabs/docker-images-flutter/issues/27
GitHub Actions workflow error: Cannot create file, path = '/github/home/.flutter'
I leave here a link to the production project with the app in the stores.
Maybe it saves time for somebody, I would be glad to have it when I implement it.
Uses secret keys for signing releases.
Create .apks for different flavors.
Add the build number to the files.
Create a GitHub release.
https://github.com/AgoraDesk-LocalMonero/agoradesk-app-foss/blob/main/.github/workflows/build_from_tags_ci.yml
Related
I have swift package for iOS apps (it needs UIKit to run). I wan't to build this package using Github action this is how my workflow looks like
name: Swift
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v2
- uses: YOCKOW/Action-setup-swift#master
with:
swift-version: '5.3'
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
When I run this build I got error: no such module 'UIKit'.
So I have 2 options:
make my package UIKit independent (actually don't know how)
configure build to run on iOS specifically
What should I do?
We're using xcodebuild instead of swift build to do platform specific CI from GitHub Actions. See specific example at https://github.com/firebase/firebase-ios-sdk/blob/master/.github/workflows/spm.yml and https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/build.sh#L540
The simplest approach as of 2022 is to use xcodebuild like stated above.
Condensed to the basics, the script can be as simple as this:
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
name: Build and Test
on:
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout#v3
# Sanity check to make sure we use a valid device in the next step
- name: List available devices
run: xcrun simctl list devicetypes
#generic/platform=iOS is sufficient for just building, - but need to specify concrete destination for tests
- name: Build and run tests
run: xcodebuild test -scheme YourSchemeNameHere -destination 'platform=iOS Simulator,name=iPhone 13 Pro' #or any other name from the list of sim devices
This is enough to build the project and run tests on it.
In some cases you may need to install a later version of Swift than what's available by default on Github Actions, - you can use a third party step for that and use xcode-select.
I am creating two flutter applications which share many functionality and decided to create a separate package for it to be used by both.
The following is the directory structure
my_project
.github/workflows/main.yaml
apps
app1
lib/main_devnet.dart
app2
lib/main_devnet.dart
packages
graph
main.dart
The graph package have some codes which are generated by code_builder by running
flutter pub run build_runner build --delete-conflicting-outputs
In my computer everything works fine when building apks, But I was trying to automate this work with github actions.
Here is my current workflow with which I am having trouble getting it work.
.github/workflows/main.yaml
on:
push:
branches:
- main
- dev
- alpha
name: "Build & Release"
jobs:
generate: #THIS JOB WORKS FINE
name: Generate codes
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action#v2
with:
flutter-version: '2.10.0'
- name: Installing graph dependencies
working-directory: ./packages/graph
run: flutter pub get
- name: Generating code
working-directory: ./packages/graph
run: flutter pub run build_runner build --delete-conflicting-outputs
build: #THIS JOB FAILS
needs: generate
name: Build appps
runs-on: ubuntu-latest
strategy:
matrix:
dir: [ './apps/app1/','./apps/app2/' ]
permissions:
contents: write
steps:
- name: Installing dependencies in apps
working-directory: ${{ matrix.dir }}
run: flutter pub get
- name: Building apks
working-directory: ${{ matrix.dir }}
run: flutter build apk --debug lib/main_devnet.dart
- name: Push to Releases
uses: ncipollo/release-action#v1
with:
artifacts: "${{ matrix.dir }}/build/app/outputs/apk/debug/*"
tag: v1.0.${{ github.run_number }}
token: ${{ secrets.GITHUB_TOKEN }}
When pushing my code to github I am getting the following error which causes CI to fail:
Run flutter pub get
flutter pub get
shell: /usr/bin/bash -e {0}
Error: An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/my-app-repository/my-app-repository/./apps/app2/'. No such file or directory
I think the problem relies in defining working directories using matrix as you can see in error
my-app-repository/my-app-repository this word my-app-repository is repeated twice and cause wrong dir and fail the whole process.
How can I solve this?
Each job starts with a new environment.
You have to checkout repository and install flutter on each of those jobs:
So you have to add this to steps in your matrix solution:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action#v2
with:
flutter-version: '2.10.0'
Currently I have a job which looks like this inside a workflow:
flutter_test:
name: Run flutter test and analyze
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v2
- uses: actions/setup-java#v1
with:
java-version: "12.x"
- uses: subosito/flutter-action#v1.5.3
with:
channel: "stable"
- name: Testing and analyzing paginablelistviewbuilder_example
run: cd example/paginablelistviewbuilder_example/ && flutter pub get && flutter analyze && flutter test
- name: Testing and analyzing paginablelistviewbuilder_example
run: cd example/paginablesliverchildbuilderdelegate_example/ && flutter pub get && flutter analyze && flutter test
- name: Testing and analyzing paginable
run: flutter pub get && flutter analyze && flutter test --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action#v2
with:
files: coverage/lcov.info
As you can see the Testing and analyzing paginablelistviewbuilder_example, Testing and analyzing paginablelistviewbuilder_example, and Testing and analyzing paginable has different commands attached together with && operator which make it kind of longer and hard to read.
If there is a way to group runs like the following hypothesis:
- name: Testing and analyzing paginablelistviewbuilder_example
run: cd example/paginablelistviewbuilder_example/ flutter pub get
run: flutter analyze
run: flutter test
It would make the workflow much readable.
You can use a pipe to run multiline commands
- name: Testing and analyzing paginablelistviewbuilder_example
run: |
cd example/paginablelistviewbuilder_example/ flutter pub get
flutter analyze
flutter test
I'm trying to implement continuous integration on my github repository.
If the project is at the same level as root, it works. But I want to have the project inside a folder to keep it organized. On my local setup, I would do "cd my_folder", but I tried to add that to the .yml script and still fails.
Error shown:
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Error: Process completed with exit code 1.
Basically it fails because it's trying to do pub get at the root of the repository where pubspec.yaml doesn't exist, instead of inside of the folder.
This is the code:
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
channel: 'beta'
# Enter into the flutter project.
- run: cd my_folder # Here I tried to put this command, but is useless
# Get flutter dependencies.
- run: flutter pub get # <--- Here is the error
# Statically analyze the Dart code for any errors.
- run: flutter analyze .
# Run widget tests for our flutter project.
- run: flutter test
I found the solution, just needed to add a working-directory
Final code
name: CI
on:
push:
branches:
- development
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-java#v1
with:
java-version: '12.x'
- uses: subosito/flutter-action#v1
with:
channel: 'beta'
- name: Get flutter dependencies
run: flutter pub get
working-directory: my_folder
- name: Statically analyze the Dart code for any errors.
run: flutter analyze .
working-directory: my_folder
- name: Run widget tests for our flutter project.
run: flutter test
working-directory: my_folder
This error tells you that there is no pubspec.yaml in your development branch, try to push your pubspec.yaml to the development branch.
When the following action is run, it fails on flutter analyze. If I remove it, it fails later on flutter build. Both commands work fine locally. I understand the message, but fail to grasp what might be wrong with the package path.
GitHub action error:
flutter analyze
shell: /bin/bash -e {0}
env:
JAVA_HOME_12.0.2_x64: /opt/hostedtoolcache/jdk/12.0.2/x64
JAVA_HOME: /opt/hostedtoolcache/jdk/12.0.2/x64
JAVA_HOME_12_0_2_X64: /opt/hostedtoolcache/jdk/12.0.2/x64
FLUTTER_HOME: /opt/hostedtoolcache/flutter/1.22.5-stable/x64
Analyzing myApp...
error • Target of URI doesn't exist: 'package:myApp/app.dart' • lib/main.dart:7:8 • uri_does_not_exist
error • The function 'App' isn't defined • lib/main.dart:38:16 • undefined_function
2 issues found. (ran in 18.4s)
Error: Process completed with exit code 1.
Action source:
name: Flutter Android Test and Build
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build_android:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v2
- name: Setup Java
uses: actions/setup-java#v1
with:
java-version: "12.x"
- name: Setup Flutter
uses: subosito/flutter-action#v1
with:
flutter-version: "1.22.5"
- name: Install Flutter dependencies
run: flutter pub get
- name: Format files
run: flutter format --set-exit-if-changed .
- name: Analyze code
run: flutter analyze
- name: Run tests
run: flutter test
- name: Build Android
run: flutter build apk
Passing --no-fatal-infos and --no-fatal-warnings as a flag to flutter analyzer worked for me.
Here: flutter analyze --no-fatal-infos --no-fatal-warnings
This is because, unlike dart analyzer, flutter analyzer returns a fatal exit code of 1 regardless of the severity issue (info, warning, error).
Reference
The issue was in a upper case / lower case file name typo. OSX filesystem is by default case insensitive, while Ubuntu, on which the GitHub Action runs, is not.