Skip to content

Instantly share code, notes, and snippets.

@albertogalca
Last active January 13, 2023 13:10
Show Gist options
  • Save albertogalca/47c8f368aff0ae8ec5b653f780fb5049 to your computer and use it in GitHub Desktop.
Save albertogalca/47c8f368aff0ae8ec5b653f780fb5049 to your computer and use it in GitHub Desktop.
Circle CI Config for fastlane
version: 2
aliases:
- &restore_npm_cache
name: 'Restoring node_modules from the cache'
key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}
- &install_npm_dependencies
name: Installing NPM Dependencies
command: yarn install
- &save_npm_cache
name: 'Saving node_modules into the cache'
key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}
paths:
- node_modules
- &restore_gem_cache
name: 'Restoring bundles from the cache'
key: bundle-v3-{{ checksum "Gemfile.lock" }}-{{ arch }}
- &install_bundles
name: Installing Bundles
command: bundle install
working_directory: ios
- &save_gem_cache
name: 'Saving bundles into the cache'
key: bundle-v3-{{ checksum "Gemfile.lock" }}-{{ arch }}
paths:
- vendor/bundle
- &restore_pods_cache
name: 'Restoring Pods from the cache'
key: pods-v3-{{ checksum "ios/Podfile.lock" }}-{{ arch }}
- &install_pods
name: Make install
command: |
yarn make
- &save_pods_cache
name: 'Saving Pods into the cache'
key: pods-v3-{{ checksum "ios/Podfile.lock" }}-{{ arch }}
paths:
- ios/Pods
- &set_ruby_version
name: set Ruby version
command: echo "ruby-2.5.5" > ~/.ruby-version
- &update_sdk_manager
name: SDK Manager update
command: |
echo 'Y' | sdkmanager --update
- &accept_sdk_licenses
name: Android SDK Licences
command: |
echo 'Y' | sdkmanager --licenses
- &install_bundler
name: Install bundler
command: |
gem update --system
gem install bundler
- &set_node_version
name: Install node@10.16.3 (need right version for `yarn`)
command: |
set +e
touch $BASH_ENV
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
echo 'nvm install v10.16.3' >> $BASH_ENV
echo 'nvm alias default v10.16.3' >> $BASH_ENV
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install v10.16.3 && nvm use v10.16.3 && nvm alias default v10.16.3
node -v
- &update_fastlane_session
name: Update FASTLANE_SESSION from CircleCI
command: |
echo Updating FASTLANE_SESSION
./update_fastlane_session.rb
jobs:
node:
working_directory: ~/example
docker:
- image: circleci/node:8
environment:
BUNDLER_VERSION: 2.0.1
steps:
- checkout
- restore_cache: *restore_npm_cache
- run: *install_npm_dependencies
- save_cache: *save_npm_cache
- run:
name: jest tests
command: yarn run test
- persist_to_workspace:
root: ~/example
paths:
- node_modules
beta-ios:
macos:
xcode: '10.3.0'
working_directory: ~/example
shell: /bin/bash --login -o pipefail
steps:
- checkout
- run:
name: Create environment file
command: |
echo Creating environment file
./create-env.sh STAGING >> .env.staging
- run: *set_ruby_version
- run: *install_bundler
- restore_cache: *restore_gem_cache
- run: *install_bundles
- save_cache: *save_gem_cache
- restore_cache: *restore_pods_cache
- run: *set_node_version
- run: *install_pods
- save_cache: *save_pods_cache
- run:
name: Prepare environment and compile beta
command: |
echo Executing fastlane
yarn fastlane:ios:beta
release-ios:
macos:
xcode: '10.3.0'
working_directory: ~/example
environment:
ENVFILE: .env.prod
shell: /bin/bash --login -o pipefail
steps:
- checkout
- run:
name: Create environment file
command: |
echo Creating environment file
./create-env.sh PROD >> .env.prod
- run: *set_ruby_version
- run: *install_bundler
- restore_cache: *restore_gem_cache
- run: *install_bundles
- save_cache: *save_gem_cache
- restore_cache: *restore_pods_cache
- run: *set_node_version
- run: *install_pods
- save_cache: *save_pods_cache
- run:
name: Prepare environment and compile beta
command: |
echo Executing fastlane
yarn fastlane:ios:release
beta-android:
working_directory: ~/example
docker:
- image: circleci/android:api-28-node8-alpha
environment:
BUNDLER_VERSION: 2.0.1
steps:
- checkout:
path: ~/example
- attach_workspace:
at: ~/example
- run:
name: Create environment file
command: |
echo Creating environment file
./create-env.sh STAGING >> .env.staging
- run: *install_bundler
- restore_cache: *restore_gem_cache
- run: *install_bundles
- save_cache: *save_gem_cache
- restore_cache: *restore_npm_cache
- run: *install_npm_dependencies
- save_cache: *save_npm_cache
- run: *update_sdk_manager
- run: *accept_sdk_licenses
- run:
name: Prepare environment and compile beta
command: |
echo Config Git
git config --global -l
git config --global user.email circleci@circleci
git config --global user.name CircleCI
echo Executing fastlane
yarn fastlane:android:beta
release-android:
working_directory: ~/example
docker:
- image: circleci/android:api-27-node8-alpha
steps:
- checkout:
path: ~/example
- attach_workspace:
at: ~/example
- run:
name: Create environment file
command: |
echo Creating environment file
./create-env.sh PROD >> .env.prod
- run: *install_bundler
- restore_cache: *restore_gem_cache
- run: *install_bundles
- save_cache: *save_gem_cache
- restore_cache: *restore_npm_cache
- run: *install_npm_dependencies
- save_cache: *save_npm_cache
- run: *update_sdk_manager
- run: *accept_sdk_licenses
- run:
name: Prepare environment and compile release
command: |
echo Config Git
git config --global -l
git config --global user.email circleci@circleci
git config --global user.name CircleCI
echo Executing fastlane
yarn fastlane:android:release
workflows:
version: 2
test-and-build:
jobs:
- node
- deploy-beta-ios:
type: approval
requires:
- node
- deploy-beta-android:
type: approval
requires:
- node
- deploy-release-ios:
type: approval
requires:
- node
filters:
branches:
only: master
- deploy-release-android:
type: approval
requires:
- node
filters:
branches:
only: master
- beta-ios:
requires:
- deploy-beta-ios
- beta-android:
requires:
- deploy-beta-android
- release-ios:
requires:
- deploy-release-ios
- release-android:
requires:
- deploy-release-android
#!/usr/bin/env ruby
require "circleci"
unless ENV.key?('FASTLANE_USER') && ENV.key?('FASTLANE_PASSWORD') && ENV.key?('CIRCLE_API_TOKEN')
puts "Please set FASTLANE_USER, FASTLANE_PASSWORD and CIRCLE_API_TOKEN env vars."
exit 1
end
puts "When/if the script pauses, type the 2FA code and press Enter."
spaceauth_output = "bundle exec fastlane spaceauth"
fastlane_session_regex = %r{Pass the following via the FASTLANE_SESSION environment variable:\n(?<session>.+)\n\n\nExample:\n.+}
new_session = nil
if match = spaceauth_output.match(fastlane_session_regex)
new_session = match[:session].gsub("\e[4m\e[36m", "").gsub("\e[0m\e[0m", "")
end
# Yell and quit if unable to parse out session from spaceauth output
if new_session.nil?
puts "Unable to obtain new session via fastlane spaceauth"
exit 1
else
puts "Updating FASTLANE_SESSION for iOS CircleCI projects"
projects = %w[project1 project2]
env_hash = { name: 'FASTLANE_SESSION', value: new_session }
config = CircleCi::Config.new token: ENV['CIRCLE_API_TOKEN']
projects.each do |p|
project = CircleCi::Project.new("YourUserOrOrg", p, "github", config)
response = project.add_envvar env_hash
puts "Response for #{p}: #{response.body}"
end
puts "Done!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment