The Flutter App uses Github Actions for CI/CD

CI/CD and Github Actions

1. What is CI/CD?

Continuous Integration/Continuous Delivery (CI/CD) is a method of frequently delivering applications to customers by introducing automation during application development. The core concepts of CD/CD are continuous integration, continuous delivery, and continuous deployment. CI/CD is a solution for development and operations teams that addresses the problems that can arise when integrating new code (aka “integration hell”).

Specifically, CI/CD enables continuous automation and monitoring throughout the entire application lifecycle, from the integration and testing phases to delivery and deployment. These related transactions are often referred to collectively as “CI/CD pipelines” and are supported by development and operations teams working together in an agile manner.

The main purpose of CI/CD is to catch integration errors early, allow teams to work more closely together, and automate builds so that code can be released at any time, ideally.

2. Github Actions introduction

Github Actions is a CI/CD service provided by Github. We can test, build and publish projects on Github automatically through Github Actions.

Concept:

  • Wordflow file

Workflow configuration file, YAML file, in. Githu /workflows directory

  • Workflow

Workflow, typically consisting of a series of tasks.

  • Job

Tasks in a workflow typically consist of a series of steps.

  • Step

A step in a task to execute a command or Action.

  • Action

An operation performed in a step, such as pulling code.

  • Event

Events that trigger a workflow, such as a push operation.

2. Use Github Actions for the Flutter project

1. New projects

Android Studio creates a New Flutter project or creates one from the command line.

flutter create flutter_github_actions
Copy the code

Once you’ve created your project, upload it directly to Github.

2. Create a workflow file

Github itself provides a number of predefined workflow files for us to use, but here we’ll use our own.

Similarly, there can be multiple workflow files within a project, so we’ll just create a new one to demonstrate.

Create a.github/workflows directory under the project root and create a main.yml file under that directory.

3. Write commands

You can then write commands in main.yml.

# Trigger workflow actions
on: push
# workflow name
name: Test, Build and Release apk
# Tasks to be performed
jobs:
  build:
    name: Build APK
    Define the runtime environment
    runs-on: ubuntu-latest
    # Execute steps
    steps:
      Pull the latest code before executing the step
      - uses: actions/checkout@v1
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      Configure the Flutter environment
      - uses: subosito/flutter-action@v1
        with:
          flutter-version: '1.7.8 + hotfix. 4'
      Update the flutter dependencies before performing the build
      - run: flutter pub get
      # test
      - run: flutter test
      - run: flutter build apk --debug --split-per-abi
      - name: Create a Release APK
        uses: ncipollo/release-action@v1
        with:
          artifacts: "build/app/outputs/apk/debug/*.apk"
          token: ${{ secrets.TOKEN }}
Copy the code

In the command above:

  • Actions /checkout@v1 means to use Github Action to pull code.

  • Ubosito /flutter-action@v1 Indicates that the flutter environment is configured.

  • Secrets.TOKEN Permission Check

4. Configure the Token

To perform CI/CD, you need to obtain permissions to perform related operations. Therefore, you need to configure the Token by yourself. Create a Personal Access token to provide permissions to publish action access and manipulate the repository

Then go to the Settings page of the new repository and create Secrets. Here create a variable named Token and its value is secret of the Token value that was just copied.

Git push triggers the build

Once created successfully, you can test to see if the workflow can be triggered.

Git tag v1.0 Git push Origin v1.0Copy the code

After you execute the git command, you can go to Github to see if you want to build again.


1, How to Setup CI/CD for Flutter Apps with GitHub Actions

2, CI/CD for Flutter Apps Using GitHub Actions

3, flutter – action

4, making the actions


Gihub demo address


Recommended reading


Easy tutorial on Flutter animation

Flutter 3 d animation

Flutter Path based

Flutter advanced