amplify-swift/.circleci/config.yml

428 lines
13 KiB
YAML

# .circleci/config.yml
version: 2.1
parameters:
ios-destination:
type: string
default: platform=iOS Simulator,name=iPhone 14,OS=latest
macos-destination:
type: string
default: platform=macOS,arch=x86_64
orbs:
# Using inline orb for now
getting-started-smoke-test:
orbs:
macos: circleci/macos@2
node: circleci/node@5.0.2
ruby: circleci/ruby@1.6.0
commands:
run-with-retry:
description: Run command with retry
parameters:
label:
description: Display name
type: string
command:
description: Command to run
type: string
retry-count:
description: Number of retry
type: integer
default: 3
sleep:
description: Wait duration until next retry
type: integer
default: 5
no_output_timeout:
description: Elapsed time the command can run without output
type: string
default: 10m
steps:
- run:
name: << parameters.label >>
command: |
retry() {
MAX_RETRY=<< parameters.retry-count >>
n=0
until [ $n -ge $MAX_RETRY ]
do
<< parameters.command >> && break
n=$[$n+1]
sleep << parameters.sleep >>
done
if [ $n -ge $MAX_RETRY ]; then
echo "failed: ${@}" >&2
exit 1
fi
}
retry
no_output_timeout: << parameters.no_output_timeout >>
jobs:
ios:
parameters:
xcode-version:
type: string
default: 13.4.1
simulator-device:
type: string
default: iPhone 13
simulator-os-version:
type: string
default: "15.5"
working_directory: ~/ios-canaries/canaries/example
macos:
xcode: <<parameters.xcode-version>>
environment:
FL_OUTPUT_DIR: output
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout:
path: ~/ios-canaries
- node/install
- run: npm install -g @aws-amplify/cli
- run: amplify init --quickstart --frontend ios
- macos/preboot-simulator:
device: <<parameters.simulator-device>>
version: <<parameters.simulator-os-version>>
- ruby/install-deps
- run-with-retry:
label: Run tests
command: bundle exec fastlane scan --device "<<parameters.simulator-device>>" --deployment_target_version "<<parameters.simulator-os-version>>"
defaults: &defaults
macos:
xcode: '14.0.0'
working_directory: ~/amplify-swift
environment:
BUNDLE_PATH: vendor/bundle
references:
repo_cache_key: &repo_cache_key v2-repo-{{ .Branch }}-{{ .Revision }}
restore_repo: &restore_repo
restore_cache:
keys:
- *repo_cache_key
- v2-repo-{{ .Branch }}
- v2-repo
commands:
restore_gems:
steps:
- restore_cache:
keys:
- v2-gems-{{ checksum "~/amplify-swift/Gemfile.lock" }}
- v2-gems-
check_bundle:
steps:
- run:
name: Check bundle
command: bundle check --path $BUNDLE_PATH || bundle install --path $BUNDLE_PATH
make_artifacts_directory:
steps:
- run:
name: Make artifacts directory
command: mkdir -p "artifacts"
upload_artifacts:
steps:
- store_artifacts:
path: artifacts
jobs:
checkout_code:
<<: *defaults
steps:
- *restore_repo
- checkout
- save_cache:
key: *repo_cache_key
paths:
- ~/amplify-swift
install_gems:
<<: *defaults
steps:
- *restore_repo
- restore_gems
- run:
name: Bundle install
command: bundle check --path $BUNDLE_PATH || bundle install --path $BUNDLE_PATH
environment:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
- save_cache:
key: v2-gems-{{ checksum "~/amplify-swift/Gemfile.lock" }}
paths:
- vendor/bundle
build_amplify_ios_spm:
<<: *defaults
steps:
- *restore_repo
- make_artifacts_directory
- run:
name: Build amplify for ios SPM
command: xcodebuild build -scheme Amplify-Package -sdk iphonesimulator -destination "<< pipeline.parameters.ios-destination >>" | tee "artifacts/build-Ampify-for-ios-SPM.log" | xcpretty
build_amplify_macos_spm:
<<: *defaults
steps:
- *restore_repo
- make_artifacts_directory
- run:
name: Build amplify for macos SPM
command: xcodebuild build -scheme Amplify-Package -sdk macosx -destination "<< pipeline.parameters.macos-destination >>" | tee "artifacts/build-Ampify-for-macos-SPM.log" | xcpretty
unit_test:
<<: *defaults
parameters:
xcode-version:
type: string
default: 14.0.0
scheme:
type: string
sdk:
type: string
destination:
type: string
description: << parameters.scheme >> unit test
steps:
- *restore_repo
- make_artifacts_directory
- run:
name: Build << parameters.scheme >>
command: xcodebuild build-for-testing -scheme <<parameters.scheme>> -sdk << parameters.sdk >> -destination "<<parameters.destination>>" | tee "artifacts/build-<< parameters.scheme >>-<< parameters.sdk >>.log" | xcpretty
- run:
name: Test << parameters.scheme >>
command: xcodebuild test -scheme <<parameters.scheme>> -sdk << parameters.sdk >> -destination "<<parameters.destination>>" | tee "artifacts/test-<< parameters.scheme >>-<< parameters.sdk >>.log" | xcpretty --simple --color --report junit
- run:
name: Upload << parameters.scheme >> coverage report to Codecov
command: bash ~/amplify-swift/build-support/codecov.sh -F << parameters.scheme >>_unit_test -J '^<< parameters.scheme >>$'
- store_test_results:
path: build/reports
- upload_artifacts
generate_api_docs:
<<: *defaults
steps:
- *restore_repo
- restore_gems
- check_bundle
- run:
name: Jazzy API doc generation
command: bash ~/amplify-swift/CircleciScripts/jazzy_doc_gen.sh
deploy:
<<: *defaults
parameters:
lane:
type: string
default: 'unstable'
description: deploy new release
steps:
- add_ssh_keys:
fingerprints:
- '7a:f2:7f:a6:62:1a:9e:0f:f1:03:8c:fc:86:93:77:6e'
- *restore_repo
- restore_gems
- check_bundle
- run:
name: Release Amplify for Swift
command: bundle exec fastlane << parameters.lane >>
no_output_timeout: 60m
deploy_requires: &deploy_requires
requires:
- build_amplify_ios_spm
- build_amplify_macos_spm
- ios_unit_test_amplify
- ios_unit_test_awspluginscore
- ios_unit_test_analytics
- ios_unit_test_api
- ios_unit_test_auth
- ios_unit_test_datastore
- ios_unit_test_geo
- ios_unit_test_storage
- macos_unit_test_amplify
- macos_unit_test_awspluginscore
- macos_unit_test_analytics
- macos_unit_test_api
- macos_unit_test_auth
- macos_unit_test_datastore
- macos_unit_test_geo
- macos_unit_test_storage
workflows:
build_test_deploy:
when:
not:
equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
jobs:
- checkout_code
- install_gems:
requires:
- checkout_code
- build_amplify_ios_spm:
requires:
- install_gems
- build_amplify_macos_spm:
requires:
- install_gems
- unit_test:
name: ios_unit_test_amplify
scheme: Amplify
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_awspluginscore
scheme: AWSPluginsCore
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_analytics
scheme: AWSPinpointAnalyticsPlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_api
scheme: AWSAPIPlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_auth
scheme: AWSCognitoAuthPlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_datastore
scheme: AWSDataStorePlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_geo
scheme: AWSLocationGeoPlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: ios_unit_test_storage
scheme: AWSS3StoragePlugin
sdk: iphonesimulator
destination: << pipeline.parameters.ios-destination >>
requires:
- build_amplify_ios_spm
- unit_test:
name: macos_unit_test_amplify
scheme: Amplify
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_awspluginscore
scheme: AWSPluginsCore
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_analytics
scheme: AWSPinpointAnalyticsPlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_api
scheme: AWSAPIPlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_auth
scheme: AWSCognitoAuthPlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_datastore
scheme: AWSDataStorePlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_geo
scheme: AWSLocationGeoPlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- unit_test:
name: macos_unit_test_storage
scheme: AWSS3StoragePlugin
sdk: macosx
destination: << pipeline.parameters.macos-destination >>
requires:
- build_amplify_macos_spm
- deploy:
name: deploy unstable
<<: *deploy_requires
filters:
branches:
only:
- main
- deploy:
name: deploy stable
lane: release
<<: *deploy_requires
filters:
branches:
only:
- release
- generate_api_docs:
name: Generate api documentation
requires:
- deploy stable
filters:
branches:
only:
- release
# Scheduled smoke test workflow
# Jobs are pulled from the getting-started-smoke-test inline orb defined above
canaries:
when:
and:
- equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
- equal: [ "Canaries", << pipeline.schedule.name >> ]
jobs:
- getting-started-smoke-test/ios:
xcode-version: "14.1.0"
simulator-os-version: "16.1"
simulator-device: "iPhone 14 Pro"
- getting-started-smoke-test/ios:
xcode-version: "13.4.1"
simulator-os-version: "15.5"
simulator-device: "iPhone 13 Pro"