"flutter channel stable" failed in docker image: cirrusci when publish pages to gitlab - flutter

I'm trying to publish my flutter page on gitlab which is the git host of my project. I'm using the ci configure like the following(from this post)
gitlab page CI configure
image: cirrusci/flutter:latest
before_script:
- flutter channel stable
- flutter upgrade
- flutter config --enable-web
- flutter pub get
pages:
stage: deploy
script:
- flutter build web
- cp -r build/web public
artifacts:
paths:
- public
only:
- live
The ci job failed in an error like:
...
$ flutter channel stable
Switching to flutter channel 'stable'...
git: fatal: 'origin/stable' is not a commit and a branch 'stable' cannot be created from it
Switching channels failed with error code 128.
...
What's the problem?
One thing worth to note is my flutter project locate in a subdirectory(ie., my-flutter-dir) of the repository root. Is it the reason? How to configure the CI script in this situation?
I've tried to add a cd my-flutter-dir as the first command in the before_script, but it still result in the same error.

It's turn out being an issue of the docker image. After I removed the flutter channel and flutter upgrade command in the befor_script part, everything is ok now.
Note if you have the flutter project in a subdirectory under the repository root, still you need to add cd you-flutter-dir command in the before_script. Also don't forget to put the .gitlab-ci.yml file in the root of the repository.

Related

How to automate testing of Flutter application on Linux-Desktop via Github Actions CI

We want to make our integration tests work on Linux desktop (ubuntu-latest) via Github Actions.
The command is
flutter config --enable-linux-desktop
flutter test -d linux integration_test
But we always get an error:
Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
//...
TestDeviceException(Unable to start the app on the device.)
package:flutter_tools/src/test/integration_test_device.dart 61:7 IntegrationTestTestDevice.start
Can Github Actions not handle the GPU / GUI related stuff fast enough on the CPU or what is going on. Is this even possible?
I found only one repository which call similar command for a linux environment.
Thanks!
I saw this question, where Xvfb was mentioned in an answer, it worked:
jobs:
linux:
runs-on: ubuntu-latest
...
steps:
run: |
export DISPLAY=:99
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
flutter test -d linux integration_test
I am using the GabrielBB/xvfb-action#v1.6 github action to enable xvfb.
- name: flutter test
uses: GabrielBB/xvfb-action#v1.6
with:
working-directory: ./examples/flutter
run: |
flutter config --enable-linux-desktop
flutter test integration_test/basics_test.dart -d linux

Flutter Web - Icons not showing up when Hosted

I found this link
https://github.com/flutter/flutter/issues/32540#issuecomment-491498679
and tried out the fix but sadly it didn't work for me.
Hoping you can help!!
Thanks
also I'm using aws amplify hosting using this setting
version: 1
frontend:
phases:
preBuild:
commands:
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
- export PATH="$PATH:`pwd`/flutter/bin"
# IMPORTANT - Please verify your build commands
build:
commands:
- flutter build web -t ./lib/main.dart
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: build/web
files:
- '**/*'
cache:
paths: []
Flutter web doesn't support images of SVG format. Please use png instead.

Flutter - How to run unit tests over a plugin native code for Android

We are building a plugin for flutter that iterable.com here la-haus/iterable-flutter, and we want to test the android implementation of our plugin, we are already able to run tests for the flutter side but not each native implementation tests.
Folders and tests
So we have:
lib/: library implementation, the interace that clients use.
tests/: test for the flutter side of the library
android/
android/src/test: these are the tests we want to run
What we have tried
Run flutter plugin tests, running flutter test at the root of the project, and it runs test/iterable_flutter_test.dart but not android ones.
We have seen these docs flutter/wiki/Plugin-Tests, but I still don't figure out how to run them.
Question
How can I run Android implementation android/src/test tests?
Our current issue is https://github.com/la-haus/iterable-flutter/issues/22
We were asking us the same question and were surprised to not find any examples of running native tests with flutter - as described in https://github.com/flutter/flutter/wiki/Plugin-Tests (thanks for providing the link btw).
Solution with gradle (without flutter_plugin_tools)
Assumption: the plugin structure got scaffolded by the flutter create --template=plugin --platforms=android ... command.
To run the native tests, make sure that the local gradle property files ./example/android/local.properties and ./android/local.properties are created properly. This can be achieved by running flutter pub get or flutter test in the root directory of the plugin.
Then you're ready to run gradle --project-dir ./example/android test, which executes the test target for all subprojects from the plugin example (which includes the effective plugin code)
Here's an example of a (slightly stripped down) github actions workflow for testing a plugin (name: plgn1):
name: CI/CD, test code
on: [push]
jobs:
plgn1-plugin:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./app/3rdparty/plgn1
steps:
- uses: actions/checkout#v3
- uses: actions/setup-java#v2
with:
java-version: "11"
distribution: "adopt"
cache: 'gradle'
- uses: subosito/flutter-action#v2
with:
flutter-version: "3.0.1"
channel: "stable"
- name: Config flutter
run: flutter config --no-analytics
- name: "Run flutter pub get"
run: flutter pub get
- name: "Run Flutter test(s)"
run: flutter test
- name: "Run Flutter test(s) for plugin example"
run: flutter test
working-directory: ./app/3rdparty/plgn1/example
- name: "Run Android test(s) for plugin example"
run: gradle --project-dir ./example/android --no-daemon test
Skipping flutter_plugin_tools (opinion, own experience)
The way how the plugin tests are described for native-tests sounded quite easy and feasible, but after playing 1h around I lost my patience (and I eventually got the feeling that it's not designed for a flutter plugin like ours).
I skipped eventually flutter_plugin_tools and went on with gradle directly. That's probably not the way how it should be run in the flutter ecosystem, but it's working for us.
Please let me know when you find an easier or more elegant way to run native tests of a flutter plugin!

GitLab Flutter CI fails with "tojunit: command not found"

I'm using the following .gitlab-ci.yml file to run tests using junit and export the report as an XML artifact:
image: cirrusci/flutter:stable
before_script:
- flutter pub get
- flutter clean
- flutter --version
stages:
- analyze-and-test
analyze-and-test:
stage: analyze-and-test
script:
- flutter build aot
- flutter analyze
# - flutter test
- flutter test --machine | tojunit -o report.xml
artifacts:
when: always
reports:
junit:
- report.xml
only:
- master
- merge_requests
The application has the following package dependencies:
dependencies:
flutter:
sdk: flutter
junitreport: ^1.3.1
When this pipeline is ran, I get the following error:
$ flutter test --machine | tojunit -o report.xml
/usr/bin/bash: line 139: tojunit: command not found
Unhandled exception:
FileSystemException: writeFrom failed, path = '' (OS Error: Broken pipe, errno = 32)
I'm trying to figure out why this is failing. The command should be found since the package is retrieved in before_script stanza before the analyze-and-test is called. What am I missing?
Looks like tojunit is not installed on CI machine. According to junitreport installation instruction you should run this command to download the program and make a launch script available:
pub global activate junitreport
So firstly add this command to before_script phase:
before_script:
- flutter pub get
- flutter clean
- flutter --version
- flutter pub global activate junitreport
Try to run this.
Next, if the {dart-cache}/bin directory is not on your path, you will get a warning, including tips on how to fix it. In that case you will need to add some more commands (from tips) to before_script.

How to deploy Ionic 4 app to Github pages?

I have a problem deploying Ionic 4 app to Github pages.
I tried follwing a tutorial for uploading Angular app but it does not work. It keeps throwing errors of all kinds.
Does anyone can help?
Thanks a lot.
Here is how to use angular-cli-ghpages with Ionic 4:
Create your Ionic project (ionic start MyApp blank)
Install the plugin: npm i angular-cli-ghpages --save
Connect your project with your github repository.
Navigate in the terminal to your project directory and execute ionic build --prod -- --base-href https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/, what will create the www folder, which is comparable to the dist folder for Angular. It also sets your github page domain as base href in index.html.
Then run the plugin: npx angular-cli-ghpages --dir=www. The flag at the end points to the www folder, where the index.html file is located that will be displayed at https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/. The plugin will create a branch called "gh-pages" in your project that contains all files which are located in your www folder.
As a last step you have to select the "gh-page" branch in the settings of your project (https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/settings) as a source for your github page.
You can also set different branch names if you don't want to use the default "gh-pages" name (also master is possible, but then you should keep the source files in a different branch). Just run the plugin like this: npx angular-cli-ghpages --branch=BRANCH-NAME --dir=www.
Like Gary Großgarten suggested, you can create a script for it which makes it easier. For Ionic it would be: ionic build --prod -- --base-href https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/ && npx angular-cli-ghpages --branch=BRANCH-NAME --dir=www
I was looking for a proper solution myself, credits go to Juangui Jordán's blog.
I'm using https://github.com/angular-schule/angular-cli-ghpages to achieve this easily.
Just add
"scripts": {
...
"gh-pages": "ng build --base-href 'https://USERNAME.github.io/REPOSITORY_NAME/' --prod && npx ngh --dir=www/"
...
}
to your package.json.
If you want a costum domain you can add the cname flag
--cname=example.com
to the ngh command.
To build and upload your site run
npm run gh-pages
Just a note: For a gitlab repository (not Github) you can do this:
.gitlab-ci.yml:
pages:
image: node:latest
stage: deploy
script:
- npm install -g ionic cordova
- npm install
# frontend application is served at https://what-digital.gitlab.io/stemba/
# we need to set the basePath to the sub dir
- ionic build --prod -- --base-href="https://what-digital.gitlab.io/gitlab-pages/"
- rm -rf public
- mkdir public
- cp -r www/* public
artifacts:
expire_in: 1 week
paths:
- public
only:
- dev