508 lines
16 KiB
YAML
508 lines
16 KiB
YAML
# .circleci/config.yml
|
|
|
|
version: 2.1
|
|
|
|
orbs:
|
|
aws-cli: circleci/aws-cli@3.1.4
|
|
|
|
# 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
|
|
aws-cli: circleci/aws-cli@3.1.1
|
|
|
|
commands:
|
|
send-metric-on-fail:
|
|
description: Send failure datapoint to cloudwatch
|
|
steps:
|
|
- run:
|
|
name: Send failure datapoint to cloudwatch
|
|
command: |
|
|
payload="{\"jobName\": \"${CIRCLE_JOB}\", \"projectRepoName\": \"${CIRCLE_PROJECT_REPONAME}\"}"
|
|
echo $payload
|
|
aws lambda invoke --function-name CircleCIWorkflowFailureHandler --payload "$payload" --cli-binary-format raw-in-base64-out response.json
|
|
when: on_fail
|
|
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.3.0
|
|
simulator-device:
|
|
type: string
|
|
default: iPhone 13
|
|
simulator-os-version:
|
|
type: string
|
|
default: "15.4"
|
|
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
|
|
- aws-cli/setup:
|
|
role-session-name: ${CIRCLE_WORKFLOW_JOB_ID}
|
|
role-arn: ${AWS_ROLE_ARN}
|
|
session-duration: '2000'
|
|
- 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 pod install
|
|
command: pod install
|
|
no_output_timeout: 20m
|
|
- run-with-retry:
|
|
label: Run tests
|
|
command: bundle exec fastlane scan
|
|
- send-metric-on-fail
|
|
|
|
defaults: &defaults
|
|
macos:
|
|
xcode: '13.3.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
|
|
|
|
pods_cache_key: &pods_cache_key v3-dependency-pods-{{ checksum "~/amplify-swift/Podfile" }}
|
|
|
|
pods_backup_cache_key: &pods_backup_cache_key v3-dependency-pods
|
|
|
|
restore_pods: &restore_pods
|
|
restore_cache:
|
|
keys:
|
|
- *pods_cache_key
|
|
- *pods_backup_cache_key
|
|
|
|
plugin_pods_cache_key: &plugin_pods_cache_key
|
|
|
|
commands:
|
|
pre_start_simulator:
|
|
description: >-
|
|
pre start simulator, build may fail if simulator is not started
|
|
steps:
|
|
- run:
|
|
name: Pre-start simulator
|
|
command: bash ~/amplify-swift/CircleciScripts/pre_start_simulator.sh
|
|
|
|
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"
|
|
|
|
save_plugin_pods:
|
|
parameters:
|
|
prefix:
|
|
type: string
|
|
steps:
|
|
- save_cache:
|
|
key: v1-<< parameters.prefix >>-dependency-pods-{{ checksum "Podfile" }}
|
|
paths:
|
|
- ./Pods
|
|
|
|
restore_plugin_pods:
|
|
parameters:
|
|
prefix:
|
|
type: string
|
|
steps:
|
|
- restore_cache:
|
|
keys:
|
|
- v1-<< parameters.prefix >>-dependency-pods-{{ checksum "Podfile" }}
|
|
- v1-<< parameters.prefix >>-dependency-pods
|
|
|
|
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_test_amplify:
|
|
<<: *defaults
|
|
steps:
|
|
- *restore_repo
|
|
- pre_start_simulator
|
|
- run: pod install
|
|
- restore_gems
|
|
- check_bundle
|
|
- make_artifacts_directory
|
|
- run:
|
|
name: Build amplify
|
|
command: xcodebuild build-for-testing -workspace Amplify.xcworkspace -scheme Amplify -sdk iphonesimulator -destination "${destination}" | tee "artifacts/build-Amplify.log" | xcpretty
|
|
- run:
|
|
name: Test amplify
|
|
command: xcodebuild test -workspace Amplify.xcworkspace -scheme Amplify -sdk iphonesimulator -destination "${destination}" | tee "artifacts/test-Amplify.log" | xcpretty --simple --color --report junit
|
|
- run:
|
|
name: Upload coverage report to Codecov
|
|
command: bash ~/amplify-swift/build-support/codecov.sh -F 'Amplify' -J '^Amplify$'
|
|
- store_test_results:
|
|
path: build/reports
|
|
- upload_artifacts
|
|
|
|
build_amplify_spm:
|
|
<<: *defaults
|
|
working_directory: ~/amplify-swift/.swiftpm/xcode
|
|
steps:
|
|
- *restore_repo
|
|
- pre_start_simulator
|
|
- restore_gems
|
|
- check_bundle
|
|
- make_artifacts_directory
|
|
- run:
|
|
name: Build amplify for SPM
|
|
command: xcodebuild build-for-testing -workspace package.xcworkspace -scheme Amplify-Package -sdk iphonesimulator -destination "${destination}" | tee "artifacts/build-Ampify-for-SPM.log" | xcpretty
|
|
|
|
build_test_aws_plugins_core:
|
|
<<: *defaults
|
|
steps:
|
|
- *restore_repo
|
|
- pre_start_simulator
|
|
- run: pod install
|
|
- restore_gems
|
|
- check_bundle
|
|
- make_artifacts_directory
|
|
- run:
|
|
name: Build AWS plugins core
|
|
command: xcodebuild build-for-testing -workspace Amplify.xcworkspace -scheme AWSPluginsCore -sdk iphonesimulator -destination "${destination}" | tee "artifacts/build-AWSPluginsCore.log" | xcpretty
|
|
- run:
|
|
name: Test AWS plugins core
|
|
command: xcodebuild test -workspace Amplify.xcworkspace -scheme AWSPluginsCore -sdk iphonesimulator -destination "${destination}" | tee "artifacts/test-AWSPluginsCore.log" | xcpretty --simple --color --report junit
|
|
- run:
|
|
name: Upload coverage report to Codecov
|
|
command: bash ~/amplify-swift/build-support/codecov.sh -F 'AWSPluginsCore' -J '^AWSPluginsCore$'
|
|
- store_test_results:
|
|
path: build/reports
|
|
- upload_artifacts
|
|
|
|
plugin_unit_test:
|
|
<<: *defaults
|
|
parameters:
|
|
path:
|
|
type: string
|
|
workspace:
|
|
type: string
|
|
scheme:
|
|
type: string
|
|
working_directory: ~/amplify-swift/AmplifyPlugins/<< parameters.path >>
|
|
description: << parameters.path >> unit test
|
|
steps:
|
|
- *restore_repo
|
|
- restore_plugin_pods:
|
|
prefix: << parameters.path >>
|
|
- pre_start_simulator
|
|
- run: pod install
|
|
- save_plugin_pods:
|
|
prefix: << parameters.path >>
|
|
- restore_gems
|
|
- check_bundle
|
|
- make_artifacts_directory
|
|
- run:
|
|
name: Build << parameters.path >>
|
|
command: xcodebuild build-for-testing -workspace << parameters.workspace >>.xcworkspace -scheme << parameters.scheme >> -sdk iphonesimulator -destination "${destination}" | tee "artifacts/build-<< parameters.scheme >>.log" | xcpretty
|
|
- run:
|
|
name: Test << parameters.path >>
|
|
command: xcodebuild test -workspace << parameters.workspace >>.xcworkspace -scheme << parameters.scheme >> -sdk iphonesimulator -destination "${destination}" | tee "artifacts/test-<< parameters.scheme >>.log" | xcpretty --simple --color --report junit
|
|
- run:
|
|
name: Upload << parameters.path >> coverage report to Codecov
|
|
command: bash ~/amplify-swift/build-support/codecov.sh -F << parameters.path >>_plugin_unit_test -J '^<< parameters.scheme >>$'
|
|
- store_test_results:
|
|
path: build/reports
|
|
- upload_artifacts
|
|
|
|
deploy:
|
|
<<: *defaults
|
|
parameters:
|
|
lane:
|
|
type: string
|
|
default: 'unstable'
|
|
description: deploy pods to trunk
|
|
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
|
|
- aws-cli/setup:
|
|
role-arn: $AWS_OIDC_ROLE_ARN
|
|
role-session-name: "${CIRCLE_WORKFLOW_JOB_ID}.release"
|
|
session-duration: '900'
|
|
- run:
|
|
name: Release pods
|
|
command: bundle exec fastlane << parameters.lane >>
|
|
no_output_timeout: 60m
|
|
|
|
fortify_scan:
|
|
<<: *defaults
|
|
steps:
|
|
- *restore_repo
|
|
- run:
|
|
name: Make source directory
|
|
command: |
|
|
mkdir source
|
|
cp -r Amplify source
|
|
cp -r AmplifyPlugins source
|
|
- aws-cli/setup:
|
|
role-arn: 'arn:aws:iam::971028514469:role/CircleCiOIDC'
|
|
role-session-name: 'aws-s3-session'
|
|
- run:
|
|
name: Download License
|
|
command: |
|
|
aws s3 cp s3://amplify-swift-fortify-prod/fortify.license fortify.license
|
|
- run:
|
|
name: Download Installer
|
|
command: |
|
|
aws s3 cp s3://amplify-swift-fortify-prod/Fortify_SCA_and_Apps_22.1.1_Mac.tar.gz Fortify_SCA_and_Apps_22.1.1_Mac.tar.gz
|
|
tar -xvf Fortify_SCA_and_Apps_22.1.1_Mac.tar.gz
|
|
unzip Fortify_SCA_and_Apps_22.1.1_osx_x64.app.zip
|
|
- run:
|
|
name: Download Scripts
|
|
command: |
|
|
aws s3 cp s3://amplify-swift-fortify-prod/amplify_swift_fortify_scan.sh fortify_scan.sh
|
|
- run:
|
|
name: Run Installer
|
|
command: |
|
|
Fortify_SCA_and_Apps_22.1.1_osx_x64.app/Contents/MacOS/installbuilder.sh --mode unattended --installdir Fortify --InstallSamples 0 --fortify_license_path fortify.license --MigrateSCA 0
|
|
export PATH=~/amplify-swift/Fortify/bin:$PATH
|
|
echo "export PATH=~/amplify-swift/Fortify/bin:\$PATH" >> "$BASH_ENV"
|
|
fortifyupdate -acceptKey
|
|
sourceanalyzer -version
|
|
- run:
|
|
name: Run Scan
|
|
command: |
|
|
sh ./fortify_scan.sh source
|
|
|
|
deploy_requires: &deploy_requires
|
|
requires:
|
|
- build_test_amplify
|
|
- build_amplify_spm
|
|
- build_test_aws_plugins_core
|
|
- unit_test_analytics
|
|
- unit_test_api
|
|
- unit_test_auth
|
|
- unit_test_core_ml
|
|
- unit_test_datastore
|
|
- unit_test_geo
|
|
- unit_test_predictions
|
|
- unit_test_storage
|
|
- fortify_scan
|
|
|
|
workflows:
|
|
build_test_deploy:
|
|
when:
|
|
not:
|
|
equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
|
|
jobs:
|
|
- checkout_code
|
|
- install_gems:
|
|
requires:
|
|
- checkout_code
|
|
- fortify_scan:
|
|
context:
|
|
- amplify-swift-aws-s3-download
|
|
requires:
|
|
- install_gems
|
|
- build_test_amplify:
|
|
requires:
|
|
- fortify_scan
|
|
- build_test_aws_plugins_core:
|
|
requires:
|
|
- fortify_scan
|
|
- build_amplify_spm:
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_analytics
|
|
path: Analytics
|
|
workspace: AnalyticsCategoryPlugin
|
|
scheme: AWSPinpointAnalyticsPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_api
|
|
path: API
|
|
workspace: APICategoryPlugin
|
|
scheme: AWSAPICategoryPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_auth
|
|
path: Auth
|
|
workspace: AWSCognitoAuthPlugin
|
|
scheme: AWSCognitoAuthPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_datastore
|
|
path: DataStore
|
|
workspace: DataStoreCategoryPlugin
|
|
scheme: AWSDataStoreCategoryPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_geo
|
|
path: Geo
|
|
workspace: GeoCategoryPlugin
|
|
scheme: AWSLocationGeoPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_core_ml
|
|
path: Predictions
|
|
workspace: PredictionsCategoryPlugin
|
|
scheme: CoreMLPredictionsPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_predictions
|
|
path: Predictions
|
|
workspace: PredictionsCategoryPlugin
|
|
scheme: AWSPredictionsPlugin
|
|
requires:
|
|
- fortify_scan
|
|
- plugin_unit_test:
|
|
name: unit_test_storage
|
|
path: Storage
|
|
workspace: StoragePlugin
|
|
scheme: AWSS3StoragePlugin
|
|
requires:
|
|
- fortify_scan
|
|
- deploy:
|
|
name: deploy unstable
|
|
context: amplify-swift-aws-oidc
|
|
<<: *deploy_requires
|
|
filters:
|
|
branches:
|
|
only:
|
|
- v1
|
|
- deploy:
|
|
name: deploy stable
|
|
lane: release
|
|
context: amplify-swift-aws-oidc
|
|
<<: *deploy_requires
|
|
filters:
|
|
branches:
|
|
only:
|
|
- release-v1
|
|
|
|
# Scheduled smoke test workflow
|
|
# Jobs are pulled from the getting-started-smoke-test inline orb defined below
|
|
canaries:
|
|
when:
|
|
and:
|
|
- equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
|
|
- equal: [ "Canaries", << pipeline.schedule.name >> ]
|
|
jobs:
|
|
- getting-started-smoke-test/ios:
|
|
context:
|
|
- cloudwatch-monitoring
|
|
xcode-version: "13.3.0"
|
|
simulator-os-version: "15.4"
|
|
simulator-device: "iPhone 13"
|
|
- getting-started-smoke-test/ios:
|
|
context:
|
|
- cloudwatch-monitoring
|
|
xcode-version: "12.5.1"
|
|
simulator-os-version: "14.5"
|
|
simulator-device: "iPhone 12"
|