-
-
Save jukben/160d39735d4d8c496d4a1cbd98604ebc to your computer and use it in GitHub Desktop.
Medium – Continious delivery / integration for everyone – CircleCI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Hello CircleCI! Version 1 is obsolete so... | |
version: 2 | |
## | |
# Define our enviroment. | |
# This "defaults: &defaults" magic is known as Yaml anchors | |
# it allows us point to this config from several parts of the document. Neat! | |
# | |
defaults: &defaults | |
working_directory: ~/project | |
docker: | |
- image: circleci/node:latest | |
android_defaults: &android_defaults | |
working_directory: ~/project/android | |
docker: | |
- image: farwayer/react-native | |
environment: | |
# This configuration works best for our project, but you might want to experiment here a little | |
- LANG: "en_US.UTF-8" | |
- _JAVA_OPTIONS: "-Xms518m -Xmx2048m" | |
- GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' | |
- BUILD_THREADS: 2 | |
ios_defaults: &ios_defaults | |
working_directory: ~/project/ios | |
macos: | |
xcode: "9.1.0" | |
environment: | |
- LANG: "en_US.UTF-8" | |
# This is important for Fastlane because we create keychain base on this | |
- MATCH_KEYCHAIN_NAME: "circle" | |
- MATCH_KEYCHAIN_PASSWORD: "circle" | |
# ...let's define our jobs | |
jobs: | |
# let's install our project's dependenices... | |
install-dependencies: | |
<<: *defaults | |
steps: | |
- checkout | |
- attach_workspace: | |
at: ~/project | |
# ...restore cache if there is any... | |
- restore_cache: | |
keys: | |
- v1-0-dependencies-{{ checksum "package.json" }} | |
# fallback to using the latest cache if no exact match is found | |
- v1-0-dependencies- | |
# ... of not run yarn... | |
- run: | |
name: Install Dependencies | |
command: yarn | |
# ... cache the dependencies... | |
- save_cache: | |
key: v1-0-dependencies-{{ checksum "package.json" }} | |
paths: | |
- node_modules | |
- yarn.lock | |
# ...and persist to the workplace, because we want to access this within the workflows (other jobs, etc.) | |
- persist_to_workspace: | |
root: . | |
paths: . | |
# Introduce Flow job – let's staticaly check our code... | |
flow: | |
<<: *defaults | |
steps: | |
- attach_workspace: | |
at: ~/project | |
- run: yarn flow | |
# Let's check the code style as well... | |
lint: | |
<<: *defaults | |
steps: | |
- attach_workspace: | |
at: ~/project | |
- run: yarn lint | |
# Hell yeah! WE HAVE PLENTY OF THEM... | |
unit-tests: | |
<<: *defaults | |
steps: | |
- attach_workspace: | |
at: ~/project | |
- restore_cache: | |
keys: | |
- v1-0-jest-cache-{{ checksum "package.json" }} | |
# fallback to using the latest cache if no exact match is found | |
- v1-0-jest-cache- | |
- run: yarn test:ci | |
- save_cache: | |
key: v1-0-jest-cache-{{ checksum "package.json" }} | |
paths: | |
- .jestCache | |
- persist_to_workspace: | |
root: . | |
paths: . | |
## | |
# This part is little bit tricky but still it's not a rocket sience... | |
# | |
ios-beta: | |
<<: *ios_defaults | |
steps: | |
# Attach to workplace (there are our saved node_modules)... | |
- attach_workspace: | |
at: ~/project | |
# Install CocoaPod for managing our iOS native dependencies... | |
- run: | |
name: Install CocoaPod Spec | |
command: curl https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash -s cf | |
# Install Fastlane... | |
- run: | |
name: Install Ruby and Fastlane | |
command: | | |
brew install ruby | |
gem install fastlane | |
# Install our native dependencies... | |
- run: | |
name: Update CocaPods dependencies | |
command: pod install --verbose | |
timeout: 1200 | |
# Update Fastlane (Fastane plugins, namely appcenter plugin) | |
- run: | |
name: Bundle update | |
command: bundle update | |
# Run our iOS deploy task | |
- run: | |
name: Fastlane | |
command: bundle exec fastlane beta | |
## | |
# Let's do almost the same for Android... | |
# It could be worth it to create custom tailored Docker image with Fastlane preinstalled but I wanted to be explicit | |
android-beta: | |
<<: *android_defaults | |
steps: | |
# Attach to workplace (there are our saved node_modules)... | |
- attach_workspace: | |
at: ~/darwin | |
# Optimize build.gradle because memory limitation on our CircleCI machine... | |
- run: | |
name: "Optimize build.gradle for CI" | |
command: sed -i 's/2g/1g/' app/build.gradle | |
# Install Fastlane | |
- run: | |
name: Install Fastlane | |
command: | | |
gem install fastlane -NV | |
# Update Fastlane | |
- run: | |
name: Bundle update | |
command: bundle update | |
# Run our Andorid deploy task | |
- run: | |
name: Fastlane | |
command: bundle exec fastlane beta | |
# ...let's create our workflows | |
workflows: | |
# yeah we use the latest version of CircleCI | |
version: 2 | |
# Run under every PR this... | |
test: | |
# ...jobs... | |
jobs: | |
# At first, install dependencies... | |
- install-dependencies | |
# If it succeeded... | |
# Run ESlint... | |
- lint: | |
requires: | |
- install-dependencies | |
# Run FlowType check... | |
- flow: | |
requires: | |
- install-dependencies | |
# Run Jest unit tests... | |
- unit-tests: | |
requires: | |
- install-dependencies | |
# If unit tests passed and we are on MASTER branch... | |
# Deploy iOS... | |
- ios-beta: | |
requires: | |
- install-dependencies | |
- unit-tests | |
filters: | |
branches: | |
only: master | |
# Deploy Android... | |
- android-beta: | |
requires: | |
- install-dependencies | |
- unit-tests | |
filters: | |
branches: | |
only: master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment