Skip to content

Commit fb77583

Browse files
authored
Merge pull request #2172 from StoDevX/build-and-deploy-on-circleci
Build and deploy on CircleCI
2 parents ac6f62a + c58c128 commit fb77583

File tree

7 files changed

+121
-177
lines changed

7 files changed

+121
-177
lines changed

.circleci/config.yml

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
version: 2
33

44
x-config:
5-
x-caching: # caching instructions
5+
x-caching: # caching instructions
66
- &save-cache-yarn
77
key: 'v3-yarn-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}'
88
paths: [~/.cache/yarn, ~/Library/Caches/Yarn]
@@ -18,27 +18,63 @@ x-config:
1818
paths: [~/.gradle]
1919
- &restore-cache-gradle
2020
key: 'v1-gradle-dependencies-{{ arch }}-{{ checksum "android/build.gradle" }}-{{ checksum "android/app/build.gradle" }}-{{ checksum "node_modules/react-native/package.json" }}'
21-
x-commands: # command shorthands
21+
x-commands: # command shorthands
2222
- &set-ruby-version
2323
name: Set Ruby Version
2424
command: echo "ruby-2.4.2" > ~/.ruby-version
2525
- &run-danger
2626
command: yarn run danger --id $task
2727
when: always
28+
- &embed-env-vars
29+
name: Embed environment variables into the app
30+
command: |
31+
touch .env.js
32+
echo "export const GOOGLE_CALENDAR_API_KEY = '$GCAL_KEY'" >> .env.js
33+
echo "export const GOOGLE_MAPS_API_KEY = '$GMAPS_KEY'" >> .env.js
2834
2935
workflows:
3036
version: 2
31-
analyze:
32-
jobs:
33-
- cache-yarn-linux
34-
- danger: {requires: [cache-yarn-linux]}
35-
- flow: {requires: [cache-yarn-linux]}
36-
- jest: {requires: [cache-yarn-linux]}
37-
- prettier: {requires: [cache-yarn-linux]}
38-
- eslint: {requires: [cache-yarn-linux]}
39-
- data: {requires: [cache-yarn-linux]}
40-
- ios: {requires: [danger, flow, jest, prettier, eslint, data]}
41-
- android: {requires: [danger, flow, jest, prettier, eslint, data]}
37+
analyze-and-build:
38+
# The way this works is, Circle runs analyze-and-build on every commit
39+
# to every branch.
40+
# Fastlane checks the environment to see if it should build or deploy,
41+
# and if there's a tag then it deploys (otherwise it just builds.)
42+
# These same jobs are run by the "nightly" workflow, which has a
43+
# different CIRCLE_WORKFLOW_ID, which should allow us to only deploy
44+
# nightlies from that branch.
45+
jobs: &basic-jobs
46+
- cache-yarn-linux:
47+
filters: &filters {tags: {only: /.*/}}
48+
- danger:
49+
filters: *filters
50+
requires: [cache-yarn-linux]
51+
- flow:
52+
filters: *filters
53+
requires: [cache-yarn-linux]
54+
- jest:
55+
filters: *filters
56+
requires: [cache-yarn-linux]
57+
- prettier:
58+
filters: *filters
59+
requires: [cache-yarn-linux]
60+
- eslint:
61+
filters: *filters
62+
requires: [cache-yarn-linux]
63+
- data:
64+
filters: *filters
65+
requires: [cache-yarn-linux]
66+
- ios:
67+
filters: *filters
68+
requires: [danger, flow, jest, prettier, eslint, data]
69+
- android:
70+
filters: *filters
71+
requires: [danger, flow, jest, prettier, eslint, data]
72+
nightly:
73+
triggers:
74+
- schedule:
75+
cron: 0 6 * * *
76+
filters: {branches: {only: [master]}}
77+
jobs: *basic-jobs
4278

4379
jobs:
4480
cache-yarn-linux:
@@ -178,8 +214,12 @@ jobs:
178214
environment: {TERM: xterm-256color}
179215
- save_cache: *save-cache-gradle
180216
- run: mkdir -p logs/
181-
- run: touch .env.js
182-
- run: bundle exec fastlane android ci-run | tee ./logs/build
217+
- run: *embed-env-vars
218+
- run:
219+
name: Run Fastlane
220+
command: bundle exec fastlane android ci-run | tee ./logs/build
221+
environment:
222+
GIT_COMMIT_DESC: $(git log --format=oneline -n 1 $CIRCLE_SHA1)
183223
- run: *run-danger
184224

185225
ios:
@@ -202,8 +242,12 @@ jobs:
202242
- run: bundle check || bundle install --frozen --path ./vendor/bundle
203243
- save_cache: *save-cache-bundler
204244
- run: mkdir -p logs/
205-
- run: touch .env.js
206-
- run: bundle exec fastlane ios ci-run | tee ./logs/build
245+
- run: *embed-env-vars
246+
- run:
247+
name: Run Fastlane
248+
command: bundle exec fastlane ios ci-run | tee ./logs/build
249+
environment:
250+
GIT_COMMIT_DESC: $(git log --format=oneline -n 1 $CIRCLE_SHA1)
207251
- run:
208252
name: Analyze Fastlane Logfile
209253
command: python2 ./scripts/analyze-gym.py -s 20 < ./logs/build | tee ./logs/analysis || true

.travis.yml

Lines changed: 12 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1+
---
12
env:
23
# To update the secure tokens, run `travis encrypt NAME='VALUE' --add` after
34
# installing the travis gem with `gem install travis`.
45
global:
56
# variables from the web interface:
67
# - BOT_ITC_PASSWORD_FOR_FASTLANE
78
# - BUGSNAG_KEY: api key for Bugsnag connection
8-
# - CI_USER_TOKEN: unknown
9+
# - CI_USER_TOKEN: used to auth with the keys repo
910
# - DANGER_GITHUB_API_TOKEN: api key to let Danger write comments to github
10-
# - FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: app-specific password for the iTMS Transporter (obselete)
1111
# - FASTLANE_PASSWORD: password for apple id used by fastlane
12-
# - FASTLANE_SESSION: if fastlane's apple ID has 2fa enabled, this is the 1-month 2fa session cookie
1312
# - GCAL_KEY: google calendar API key
1413
# - GH_TOKEN: unknown
1514
# - GITHUB_PAGES_TOKEN: token to push to gh-pages
1615
# - GMAPS_KEY: google maps API key
1716
# sets our node version in one nice place
1817
- TRAVIS_NODE_VERSION=8
19-
# set the ruby version up top
20-
- TRAVIS_RUBY_VERSION=ruby-2.4.2
2118
# configure fastlane a bit
2219
- FASTLANE_SKIP_UPDATE_CHECK=1
2320
- FASTLANE_DISABLE_ANIMATION=1
@@ -32,102 +29,36 @@ env:
3229
branches:
3330
only:
3431
- master
35-
- /^travis/
3632
- /^greenkeeper\//
37-
- /^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?$/
3833

3934

4035
stages:
4136
- name: Greenkeeper
4237
if: branch =~ ^greenkeeper\/
4338
- name: Deploy Data
4439
if: branch = master AND type != pull_request
45-
- name: Build + Deploy
46-
if: type = cron OR tag IS present
47-
48-
49-
#
50-
# Definitions of dictionaries that are used by the machines below
51-
#
52-
53-
x-definitions:
54-
- &base
55-
before_install:
56-
# dirty hack for https://github.com/travis-ci/travis-ci/issues/5092
57-
- export PATH="${PATH/\.\/node_modules\/\.bin/}"
58-
59-
# finish bypassing 2fa auth for fastlane
60-
- unset FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
61-
- unset FASTLANE_SESSION
62-
63-
# print some travis debugging info
64-
- echo "Now testing on $TRAVIS_OS_NAME"
65-
- echo "Travis branch is $TRAVIS_BRANCH"
66-
- echo "Travis is in pull request $TRAVIS_PULL_REQUEST"
67-
- echo "Build triggered by $TRAVIS_EVENT_TYPE"
68-
69-
# force the ruby we want
70-
- echo "Using ruby $TRAVIS_RUBY_VERSION (ruby -v says $(ruby -v))"
71-
- rvm use $TRAVIS_RUBY_VERSION --install --binary --create
72-
- echo "ruby -v is now $(ruby -v)"
73-
- gem install bundler
74-
75-
# force a consistent node version
76-
- echo "Using node $TRAVIS_NODE_VERSION (node -v says $(node -v))"
77-
- nvm install "$TRAVIS_NODE_VERSION"
78-
- nvm use "$TRAVIS_NODE_VERSION"
79-
- echo "node -v is now $(node -v)"
80-
81-
# travis doesn't install yarn automatically on osx
82-
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew install yarn --without-node; fi
83-
84-
install:
85-
# install packages (if the first fails, try once more)
86-
- yarn || yarn
87-
88-
# install fastlane (if at first you don't succeed, try once more)
89-
- bundle install || bundle install
90-
91-
before_script:
92-
# ensure the env file exists and fill it out
93-
- touch .env.js
94-
- echo "export const GOOGLE_CALENDAR_API_KEY = '$GCAL_KEY'" >> .env.js
95-
- echo "export const GOOGLE_MAPS_API_KEY = '$GMAPS_KEY'" >> .env.js
96-
97-
# disable npm wrapper for npm scripts
98-
- npm config set loglevel=silent
99-
- mkdir -p logs/
100-
101-
after_script:
102-
- npm config set loglevel=notice
103-
- npm run danger -- --id $task
104-
105-
before_cache:
106-
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
107-
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
108-
109-
- &simplejs
110-
os: linux
111-
sudo: false
112-
distro: trusty
113-
language: node_js
114-
node_js: $TRAVIS_NODE_VERSION
11540

11641

11742
jobs:
118-
# We define default before_install, install, and before_script steps.
119-
# To skip the default step, use `step_name: skip`.
12043
include:
12144
# Run greenkeeper stuff
122-
- <<: *simplejs
45+
- os: linux
46+
sudo: false
47+
distro: trusty
48+
language: node_js
49+
node_js: $TRAVIS_NODE_VERSION
12350
stage: Greenkeeper
12451
env: [task=GREENKEEPER]
12552
install: npm install -g greenkeeper-lockfile@1
12653
script: greenkeeper-lockfile-update
12754
after_script: greenkeeper-lockfile-upload
12855

12956
# Deploy the gh-pages data
130-
- <<: *simplejs
57+
- os: linux
58+
sudo: false
59+
distro: trusty
60+
language: node_js
61+
node_js: $TRAVIS_NODE_VERSION
13162
stage: Deploy Data
13263
env: [task=GH_PAGES]
13364
install: yarn || yarn
@@ -141,48 +72,5 @@ jobs:
14172
github_token: $GITHUB_PAGES_TOKEN
14273
local_dir: docs/
14374

144-
# Build/deploy the Android binary
145-
- <<: *base
146-
stage: Build + Deploy
147-
os: linux
148-
sudo: required
149-
distro: trusty
150-
language: android
151-
env: [task=ANDROID]
152-
android:
153-
components:
154-
- tools
155-
- platform-tools
156-
- build-tools-23.0.1
157-
- build-tools-23.0.2
158-
- build-tools-25.0.0
159-
- build-tools-25.0.1
160-
- build-tools-25.0.2
161-
- build-tools-25.0.3
162-
- build-tools-26.0.1
163-
- android-23
164-
- android-25
165-
- android-26
166-
- extra-android-m2repository
167-
- extra-google-m2repository
168-
script:
169-
- bundle exec fastlane android ci-run | tee ./logs/build
170-
171-
# Build/deploy the iOS binary
172-
- <<: *base
173-
stage: Build + Deploy
174-
os: osx
175-
language: objective-c
176-
osx_image: xcode9.2
177-
env: [task=IOS]
178-
script:
179-
- bundle exec fastlane ios ci-run | tee ./logs/build
180-
- python2 ./scripts/analyze-gym.py -s 20 < ./logs/build | tee ./logs/analysis || true
181-
18275
cache:
183-
bundler: true
18476
yarn: true
185-
directories:
186-
- $HOME/.gradle
187-
- $HOME/.gradle/wrapper/
188-
- $HOME/.android/build-cache

fastlane/lib/commands.rb

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
# coding: utf-8
22

3-
# It doesn't make sense to duplicate this in both platforms, and fastlane is
4-
# smart enough to call the appropriate platform's "beta" lane. So, let's make
5-
# a beta build if there have been new commits since the last beta.
3+
# Pick what to do - build + deploy, build + sign, or just plain build.
64
def auto_beta
7-
UI.message "TRAVIS_EVENT_TYPE: #{ENV['TRAVIS_EVENT_TYPE']}"
8-
if should_deploy?
9-
if cron?
10-
UI.message 'building nightly'
11-
nightly
12-
else
13-
UI.message 'building beta'
14-
beta
15-
end
5+
if should_nightly?
6+
UI.message 'building nightly'
7+
nightly
8+
elsif should_beta?
9+
UI.message 'building beta'
10+
beta
11+
elsif has_api_keys?
12+
UI.message 'signing and building, but not deploying'
13+
build
1614
else
17-
if pr?
18-
UI.message 'just building (not signing)'
19-
check_build
20-
else
21-
UI.message 'signing and building, but not deploying'
22-
build
23-
end
15+
UI.message 'just building (not signing)'
16+
check_build
2417
end
2518
end
2619

2720
# Adds the github token for stodevx-bot to the CI machine
2821
def authorize_ci_for_keys
29-
token = ENV['CI_USER_TOKEN']
22+
token = ENV['GITHUB_KEYS_REPOSITORY_TOKEN']
3023

3124
# see macoscope.com/blog/simplify-your-life-with-fastlane-match
3225
# we're allowing the CI access to the keys repo

fastlane/lib/git.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def git_changelog
2323

2424
# Makes a changelog from the timespan passed
2525
def make_changelog
26-
sh('git fetch --unshallow')
26+
sh('git fetch --unshallow') if travis?
2727
log = git_changelog
2828

2929
limit = 4_000

0 commit comments

Comments
 (0)