GitHub actions can easily automate all software workflows. Build, test, and deploy code directly from GitHub. Make code review, branch management and problem classification work as you want.
I remember that at the end of the 19th year, I saw the article run fluent driver tests on GitHub actions, and then started to write in fluent_ Use it in deer, because there were written integration tests in the project at that time.
I was in the flutter_ Many issues in deer are about project operation. Many students report that they can’t run and report various errors. To be honest, it’s impossible to determine whether it’s an environmental problem or its own code problem. With GitHub actions, you can build and run tests on GitHub. As long as the test passes, you can ensure that there is no problem running the code on the corresponding fluent version.
GitHub actions is very powerful and provides an actions market where we can search for actions using various functions written by others. The level is limited. Here I only give a brief introduction to the use. You can see the official documents in detail.
1. Add GitHub actions to the project
First add in the project.github / workflows
catalogue Then create.yml
Workflow file in format. For example:flutter-drive.yml
。 Its basic format is as follows:
#Name of Workflow
name: flutter_deer driver
#Conditions for triggering workflow
on: [push, pull_request]
#One or more tasks performed by workflow
jobs:
...
The conditions for triggering workflow can also be customized according to the situation. For example, it is triggered when you specify to push to a branch or modify some files. For example:
#Modify in push submission ` pubspec Yaml ` trigger
on:
push:
paths:
- 'pubspec.yaml'
...
See the [workflow syntax for GitHub actions] document for details
](https://docs.github.com/en/ac…
2. Preparation of tasks
The structure of the task is as follows:
The simple explanation is that under jobs is job, under job is step, and under step is action.
The following is an example of executing a fluent unit test:
jobs:
#The task ID must be unique under jobs
accessibility_test:
#The virtual machine environment required to run. For example, windows-2019, MacOS latest and macos-10.14
runs-on: macos-latest
#Running steps of job
steps:
#Easy to get the flutter source code
# https://github.com/actions/checkout
- uses: actions/[email protected]
#Setting up the fluent environment
# https://github.com/marketplace/actions/flutter-action
- uses: subosito/[email protected]
with:
flutter-version: '2.0.2'
channel: 'stable' # or: 'dev' or 'beta'
#Commands to run
- run: "flutter pub get"
#Step name
- name: "Run Flutter Accessibility Tests"
run: "flutter test test/accessibility_test.dart"
The above notes explain clearly. Two actions are used, which makes the writing of the whole script much easier. A few more flutters are pasted below_ The job used in deer can basically be used without brain. You only need to modify your own running command.
3. Examples
Run integration tests on IOS devices
drive_ios:
#Create a construction matrix
strategy:
#Set up different configurations for a set of virtual environments
matrix:
device:
- "iPhone 8 (14.4)"
- "iPhone 11 Pro Max (14.4)"
#When set to true, if any matrix job fails, GitHub will cancel all ongoing jobs.
fail-fast: false
runs-on: macOS-latest
steps:
- name: "List all simulators"
run: "xcrun instruments -s"
- name: "Start Simulator"
run: |
UDID=$(
xcrun instruments -s |
awk \
-F ' *[][]' \
-v 'device=${{ matrix.device }}' \
'$1 == device { print $2 }'
)
xcrun simctl boot "${UDID:?No Simulator with this name found}"
- uses: actions/[email protected]
- uses: subosito/[email protected]
with:
flutter-version: '2.0. 2 '# specify the fluent environment
channel: 'stable'
- name: "Run Flutter Driver tests"
run: "flutter drive --target=test_driver/driver.dart"
Run integration tests on Android devices
drive_android:
runs-on: macos-latest
strategy:
matrix:
api-level: [21, 29]
target: [default]
steps:
- uses: actions/[email protected]
- uses: subosito/[email protected]
with:
flutter-version: '2.0.2'
channel: 'stable'
- name: "Run Flutter Driver tests"
#Operation for installing, configuring and running Android simulator (MAC OS only)
# https://github.com/marketplace/actions/android-emulator-runner
uses: reactivecircus/[email protected]
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: x86_64
profile: Nexus 6
script: "flutter drive --target=test_driver/driver.dart"
Construction and deployment of fluent Web
web_build_and_deploy:
runs-on: macos-latest
steps:
- uses: actions/[email protected]
- uses: subosito/[email protected]
with:
flutter-version: '2.0.2'
channel: 'stable'
- name: "Web Build 🔧"
run: |
flutter pub get
flutter build web
- name: "Web Deploy 🚀"
# https://github.com/JamesIves/github-pages-deploy-action
uses: JamesIves/[email protected]
with:
token: '${{ secrets.GITHUB_TOKEN }}'
branch: gh-pages
folder: build/web
Recently, flutter released 2.0, and the web can be built in the stable channel. Using this job, we can easily deploy our web version code on GitHub’s page.
It should be noted here that after the deployment is completed, we need to set GitHub pages before we can access it. The setting location is in the settings menu of the project home page.
4. Others
- When we push the code to GitHub, the task will be executed automatically. The details can be found in the project
Actions
See in the menu.
The above figure shows the execution results of one of them. You can see that there are successful, cancelled and failed.
- We can create the badge of workflow execution status and add it to the markdown of the project.
Display effect:
Of course, the usage is more than what I mentioned above. You can also do the functions of packaging and automatic publishing, and not only can flutter be used. Everything depends on your needs. Finally, I offer the complete code of this article.
Finally, if this article is helpful to you, you might as well like to collect a wave.
5. Reference
- Run Flutter Driver tests on GitHub Actions
- CI_CD_Flutter_Demo