Sanmill icon indicating copy to clipboard operation
Sanmill copied to clipboard

CI optimization

Open Leptopoda opened this issue 4 years ago • 11 comments

Describe the bug

  • Only run the CUI and Qt builds when there is a change for them (exclude files in /src/ui/flutter_app from triggering it)
  • When the dart analyze hook fails don't try to build the apk.

Leptopoda avatar Nov 28 '21 16:11 Leptopoda

Good idea!

Reference: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions https://github.com/tj-actions/verify-changed-files

calcitem avatar Nov 28 '21 16:11 calcitem

The first problem has been solved. I don’t know how to solve the second problem. I did not find a specific example in the official document. I don’t understand the simple example of need.

calcitem avatar Nov 28 '21 17:11 calcitem

to use the needs keyword you need to specify both jobs in the same file. something like:

name: Flutter

on:
  push:
  pull_request:
    branches: [ master ]

jobs:
  linter:
    runs-on: ubuntu-latest
    name: Lint flutter code
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - name: Set up Flutter
      uses: subosito/flutter-action@v1
    - run: bash -x ./flutter-init.sh
    - run: cp -f ./src/ui/flutter_app/analysis_options.yaml ./
    - name: Analyze Flutter
      uses: ValentinVignal/[email protected]
      with:
        fail-on: 'format'
        working-directory: src/ui/flutter_app

  build:
    runs-on: ubuntu-latest
    needs: linter

    # Note that this workflow uses the latest stable version of the Dart SDK.
    # Docker images for other release channels - like dev and beta - are also
    # available. See https://hub.docker.com/r/google/dart/ for the available
    # images.
    #container:
    #  image:  google/dart:latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      - run: echo $SIGNING_KEY | base64 -d > src/ui/flutter_app/android/app/key.jks
        env:
          SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
      - uses: subosito/flutter-action@v1
        with:
          flutter-version: '2.5.3'

      - name: Export environment valuables
        run: export

      - name: Create App version
        run: git fetch --tags; git tag; git log -n1; bash -x ./version.sh

      - name: Print Flutter SDK version
        run: flutter --version

      - name: Install dependencies
        run: bash -x ./flutter-init.sh

      # Uncomment this step to verify the use of 'dart format' on each commit.
      # - name: Verify formatting
      #   run: dart format --output=none --set-exit-if-changed .

      # Your project will need to have tests in test/ and a dependency on
      # package:test for this step to succeed. Note that Flutter projects will
      # want to change this to 'flutter test'.
      #- name: Run tests
      #  run: dart test

      # Build
      - name: Build apk
        run: cd src/ui/flutter_app; flutter build apk -v; flutter build appbundle -v
        env:
          KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
          KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
          ALIAS: ${{ secrets.ALIAS }}
          KEY_PATH: key.jks

      # Archive apk
      - name: Archive apk
        uses: actions/upload-artifact@v2
        with:
          name: sanmill-flutter-apk-release
          path: src/ui/flutter_app/build/app/outputs/flutter-apk/app-release.apk

      # Archive aab
      - name: Archive aab
        uses: actions/upload-artifact@v2
        with:
          name: sanmill-flutter-aab-release
          path: src/ui/flutter_app/build/app/outputs/bundle/release/app-release.aab

THIS IS NOT FINAL as it doesn't your recent fix for excluding the Qt dirs ...

You should probably also unify the CUI build into a separate CI (but don't depend on each other) this would unify the excluded dirs...

Leptopoda avatar Nov 28 '21 17:11 Leptopoda

also the comment # Archive apk in the CUI CI files is a bit off :upside_down_face:

Leptopoda avatar Nov 28 '21 17:11 Leptopoda

I’m not sure if jobs on different OS can be merged into a file. Is there an example?

calcitem avatar Nov 28 '21 20:11 calcitem

I don't see a reason why it shouldn't.

The platform is defined on a per job basis ...

I'll have a look tomorrow

Leptopoda avatar Nov 28 '21 21:11 Leptopoda

Thanks! I will have a try.

calcitem avatar Nov 29 '21 04:11 calcitem

Fixed. https://github.com/calcitem/Sanmill/pull/414

calcitem avatar Nov 29 '21 15:11 calcitem

reopening as I have a few new ideas:

  • only run the CI on PRs or commits on branches like dev/master

This change should allow us to push to draft PRs without building every time. converting the draft to a normal pr would then run the CI. If the proposed changes don't bring the intended results some other fix might need to be found...

Leptopoda avatar Dec 01 '21 12:12 Leptopoda

I'm looking for some examples and see if I can find them.

calcitem avatar Dec 02 '21 10:12 calcitem

something like:

on:
  push:
    branches: [master, dev]
  pull_request:

This will run on pulls that are made directly onto the master or dev branch but only on PRs for the other branches. I think (but am not shure) that this will prevent it from running on draft PRs

Leptopoda avatar Dec 02 '21 11:12 Leptopoda