|
| 1 | +version: 2.1 |
| 2 | +executors: |
| 3 | + flutter_executor: |
| 4 | + docker: |
| 5 | + - image: cirrusci/flutter:stable |
| 6 | + environment: |
| 7 | + _JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" |
| 8 | + |
| 9 | +commands: |
| 10 | + prepare_enviroment: |
| 11 | + description: Fetch the repo, do flutter doctor and install deps |
| 12 | + steps: |
| 13 | + - add_ssh_keys: |
| 14 | + fingerprints: |
| 15 | + - 26:72:b1:08:0f:c1:3b:2b:2d:ea:61:7d:d6:11:63:fb |
| 16 | + - checkout |
| 17 | + - run: |
| 18 | + name: Run Flutter doctor |
| 19 | + command: flutter doctor |
| 20 | + - restore_cache: |
| 21 | + keys: |
| 22 | + - android-sdk-licenses |
| 23 | + - gradle |
| 24 | + - pub-cache |
| 25 | + - bin |
| 26 | + - run: |
| 27 | + name: pub get |
| 28 | + command: flutter pub get |
| 29 | + |
| 30 | + code_coverage: |
| 31 | + description: Do prebuild stuff |
| 32 | + steps: |
| 33 | + - run: |
| 34 | + name: Run the application tests |
| 35 | + command: flutter test --coverage |
| 36 | + |
| 37 | + - run: |
| 38 | + name: Upload coverage |
| 39 | + command: | |
| 40 | + sudo gem install coveralls-lcov |
| 41 | + coveralls-lcov -t $COVERALLS_REPO_TOKEN coverage/lcov.info |
| 42 | +
|
| 43 | + build_app: |
| 44 | + description: Build the app |
| 45 | + parameters: |
| 46 | + mode: |
| 47 | + type: string |
| 48 | + default: "debug" |
| 49 | + file_type: |
| 50 | + type: string |
| 51 | + default: "apk" |
| 52 | + target: |
| 53 | + type: string |
| 54 | + default: "" |
| 55 | + buildNumber: |
| 56 | + type: string |
| 57 | + default: "" |
| 58 | + working_directory: |
| 59 | + type: string |
| 60 | + default: ~/project |
| 61 | + steps: |
| 62 | + - run: |
| 63 | + name: Check that we can build for all Android platforms |
| 64 | + command: | |
| 65 | + flutter build -v << parameters.file_type >> << parameters.buildNumber >> --<< parameters.mode >> << parameters.target >> |
| 66 | + working_directory: <<parameters.working_directory>> |
| 67 | + |
| 68 | + save_env_cache: |
| 69 | + description: Save the caches |
| 70 | + steps: |
| 71 | + - save_cache: |
| 72 | + key: android-sdk-licenses |
| 73 | + paths: |
| 74 | + - /opt/android-sdk-linux/licenses |
| 75 | + |
| 76 | + - save_cache: |
| 77 | + key: pub-cache |
| 78 | + paths: |
| 79 | + - /home/cirrus/.pub-cache |
| 80 | + |
| 81 | + - save_cache: |
| 82 | + key: gradle |
| 83 | + paths: |
| 84 | + - ~/.gradle |
| 85 | + |
| 86 | + - save_cache: |
| 87 | + key: bin |
| 88 | + paths: |
| 89 | + - /usr/local/bin |
| 90 | + |
| 91 | +jobs: |
| 92 | + build_pr: |
| 93 | + executor: flutter_executor |
| 94 | + steps: |
| 95 | + - prepare_enviroment |
| 96 | + - code_coverage |
| 97 | + - build_app: |
| 98 | + target: "--target-platform android-arm,android-arm64,android-x86,android-x64" |
| 99 | + buildNumber: "--build-number $CIRCLE_BUILD_NUM" |
| 100 | + working_directory: ~/project/example |
| 101 | + - run: |
| 102 | + name: Copy APK |
| 103 | + command: | |
| 104 | + sudo mkdir -p /artifacts && sudo chown "$(whoami)" /artifacts && cp build/app/outputs/apk/app.apk /artifacts/p2p-cashier.apk |
| 105 | + working_directory: ~/project/example |
| 106 | + |
| 107 | + - store_artifacts: |
| 108 | + path: /artifacts |
| 109 | + - run: |
| 110 | + name: Upload to Slack |
| 111 | + command: | |
| 112 | + export GIT_COMMIT_DESC=$(git log --format=oneline -n 1 | sed -E 's/^[^ ]+ (.*)$/\1/g') |
| 113 | + echo $CIRCLE_BUILD_URL |
| 114 | + # If we wanted to upload the APK rather than providing a link, we can do that via |
| 115 | + # something like this, but it requires an API token: |
| 116 | + # curl -F file=@/artifacts/otc-cashier.apk -F channels=$SLACK_CHANNEL -F token=$SLACK_API_TOKEN -F title="${CIRCLE_PROJECT_REPONAME} | branch -> ${CIRCLE_BRANCH} | commit -> ${GIT_COMMIT_DESC}" https://slack.com/api/files.upload |
| 117 | + # See https://medium.com/major-league/delivering-builds-through-slack-with-circle-ci-3d9e685e08f2 for an example |
| 118 | + if [ "$CIRCLE_BRANCH" = "master" ]; then |
| 119 | + # That 221348483 magic number is the internal CircleCI repository ID. |
| 120 | + # Since it's not easily accessible from the environment or API, it's hardcoded for now. |
| 121 | + curl -X POST --data-urlencode "payload={\"channel\": \"#project_p2p_cashier\", \"username\": \"CircleCI\", \"text\": \"Latest Android build for P2P cashier:\\nhttps://${CIRCLE_BUILD_NUM}-221348483-gh.circle-artifacts.com/0/artifacts/p2p-cashier.apk\\n> $GIT_COMMIT_DESC\", \"icon_emoji\": \":autobot:\"}" $SLACK_URL |
| 122 | + fi |
| 123 | + - save_env_cache |
| 124 | + |
| 125 | +workflows: |
| 126 | + version: 2.1 |
| 127 | + build-workflow: |
| 128 | + jobs: |
| 129 | + - build_pr: |
| 130 | + context: perl |
| 131 | + filters: |
| 132 | + branches: |
| 133 | + ignore: master |
0 commit comments