From 2d98cf76f83c1e94a2e04894b6e0153bf8c9c716 Mon Sep 17 00:00:00 2001 From: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Date: Wed, 8 Jun 2022 09:50:46 -0400 Subject: [PATCH] add retry; correct rn-android job --- .circleci/config.yml | 205 ++++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 71 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 504abe017e3..f3a6599ec06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1071,25 +1071,23 @@ jobs: category: datastore sample_name: v2/<< parameters.scenario >>-v2 spec: << parameters.scenario >> - browser: - firefox - - # integ_duplicate_packages: - # parameters: - # browser: - # type: string - # executor: js-test-executor - # <<: *test_env_vars - # working_directory: ~/amplify-js-samples-staging/samples/react/version-conflict/duplicate-packages - # steps: - # - prepare_test_env - # - integ_test_js: - # test_name: 'Duplicate Package Errors' - # framework: react - # category: version-conflict - # sample_name: duplicate-packages - # spec: duplicate-packages - # browser: << parameters.browser >> + browser: firefox + # integ_duplicate_packages: + # parameters: + # browser: + # type: string + # executor: js-test-executor + # <<: *test_env_vars + # working_directory: ~/amplify-js-samples-staging/samples/react/version-conflict/duplicate-packages + # steps: + # - prepare_test_env + # - integ_test_js: + # test_name: 'Duplicate Package Errors' + # framework: react + # category: version-conflict + # sample_name: duplicate-packages + # spec: duplicate-packages + # browser: << parameters.browser >> integ_auth_test_cypress_no_ui: working_directory: ~/amplify-js-samples-staging/ executor: js-test-executor @@ -1538,17 +1536,16 @@ workflows: <<: *releasable_branches matrix: parameters: - <<: - *datastore_auth_scenarios - # - integ_duplicate_packages: - # requires: - # - integ_setup - # - build - # filters: - # <<: *releasable_branches - # matrix: - # parameters: - # <<: *test_browsers + <<: *datastore_auth_scenarios + # - integ_duplicate_packages: + # requires: + # - integ_setup + # - build + # filters: + # <<: *releasable_branches + # matrix: + # parameters: + # <<: *test_browsers - integ_react_geo: requires: - integ_setup @@ -1617,7 +1614,7 @@ workflows: when: and: - equal: [scheduled_pipeline, << pipeline.trigger_source >>] - # - equal: ['canaries', << pipeline.schedule.name >>] + - equal: [canaries, << pipeline.schedule.name >>] jobs: ## Web # React @@ -1733,6 +1730,49 @@ orbs: LIBRARY_STATEMENT: Logger.LOG_LEVEL='DEBUG'; MAX_WAIT_ON_TIMEOUT: 180000 # 3 minutes; how long we wait for the build to succeed before failing the job + 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 + "$@" && break + n=$[$n+1] + sleep << parameters.sleep >> + done + if [ $n -ge $MAX_RETRY ]; then + echo "failed: ${@}" >&2 + exit 1 + fi + } + retry << parameters.command >> + no_output_timeout: << parameters.no_output_timeout >> + jobs: web: parameters: @@ -1760,32 +1800,32 @@ orbs: <<: *common_env_vars working_directory: ~/project/amplify-getting-started-<< parameters.framework >> steps: - - run: - name: Scaffold App + - run-with-retry: + label: Scaffold App command: cd ../ && npx -y << parameters.npx-command >> amplify-getting-started-<< parameters.framework >> << parameters.npx-post >> no_output_timeout: 2m - - run: - name: Install AmplifyJS + - run-with-retry: + label: Install AmplifyJS command: npm i -S aws-amplify && npm i -g wait-on serve - - run: - name: Call Amplify library in code + - run-with-retry: + label: Call Amplify library in code command: | echo "$IMPORT_STATEMENT" | cat - << parameters.main-file-path >> | tee << parameters.main-file-path >> echo "$LIBRARY_STATEMENT" >> << parameters.main-file-path >> - - run: - name: Run in Dev Mode + - run-with-retry: + label: Run in Dev Mode command: npm run << parameters.dev-start >> & wait-on http://localhost:<< parameters.dev-port >> -t $MAX_WAIT_ON_TIMEOUT - unless: condition: << parameters.ssr >> steps: - - run: - name: Run in Prod Mode + - run-with-retry: + label: Run in Prod Mode command: npm run build && (serve -n -s << parameters.build-dir >> -l 4000 & wait-on http://localhost:4000 -t $MAX_WAIT_ON_TIMEOUT) - when: condition: << parameters.ssr >> steps: - - run: - name: Run in Prod Mode + - run-with-retry: + label: Run in Prod Mode command: npm run build && (npm start & wait-on http://localhost:3000 -t $MAX_WAIT_ON_TIMEOUT) rn-ios: @@ -1800,28 +1840,35 @@ orbs: xcode-version: type: string default: 13.4.0 + ios-device: + type: string + default: iPhone 13 macos: xcode: << parameters.xcode-version >> resource_class: large working_directory: ~/amplify_getting_started_<< parameters.framework >> steps: - - run: - name: Scaffold App + - run-with-retry: + label: Scaffold App command: cd ../ && rm -rf amplify_getting_started_<< parameters.framework >> && npx react-native@<< parameters.tag >> init amplify_getting_started_<< parameters.framework >> no_output_timeout: 10m - - run: - name: Install Amplify dependencies + - run-with-retry: + label: Install Amplify dependencies command: npm install aws-amplify aws-amplify-react-native amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage @react-native-picker/picker - - run: - name: Pod Install + - run-with-retry: + label: Pod Install command: npx pod-install - - run: - name: Call Amplify library in code + - run-with-retry: + label: Call Amplify library in code command: | echo "$IMPORT_STATEMENT" | cat - << parameters.main-file-path >> | tee << parameters.main-file-path >> echo "$LIBRARY_STATEMENT" >> << parameters.main-file-path >> - run: - name: Start App + background: true + name: Start iOS simulator (background) + command: xcrun simctl boot "<< parameters.ios-device >>" || true + - run-with-retry: + label: Start App command: npm run ios rn-android: @@ -1843,23 +1890,39 @@ orbs: sdkmanager "$SYSTEM_IMAGES" echo "no" | avdmanager --verbose create avd -n test -k "$SYSTEM_IMAGES" - run: - name: Scaffold App + name: Launch emulator + command: | + emulator -avd test -delay-adb -verbose -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim + background: true + - run: + name: Generate cache key + command: | + find . -name 'build.gradle' | sort | xargs cat | + shasum | awk '{print $1}' > /tmp/gradle_cache_seed + - run-with-retry: + label: Scaffold App command: cd ../ && rm -rf amplify_getting_started_<< parameters.framework >> && npx react-native@<< parameters.tag >> init amplify_getting_started_<< parameters.framework >> no_output_timeout: 10m - - run: - name: Install Amplify dependencies + - run-with-retry: + label: Install Amplify dependencies command: npm install aws-amplify aws-amplify-react-native amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage @react-native-picker/picker - - run: - name: Call Amplify library in code + - run-with-retry: + label: Call Amplify library in code command: | echo "$IMPORT_STATEMENT" | cat - << parameters.main-file-path >> | tee << parameters.main-file-path >> echo "$LIBRARY_STATEMENT" >> << parameters.main-file-path >> - run: - background: true - command: xcrun simctl boot "iPhone 13" || true - name: Start iOS simulator (background) + name: Wait for emulator to start + command: | + circle-android wait-for-boot - run: - name: Start App + name: Disable emulator animations + command: | + adb shell settings put global window_animation_scale 0.0 + adb shell settings put global transition_animation_scale 0.0 + adb shell settings put global animator_duration_scale 0.0 + - run-with-retry: + label: Start App command: npm run android expo: @@ -1875,22 +1938,22 @@ orbs: <<: *common_env_vars working_directory: ~/amplify_getting_started_<< parameters.framework >> steps: - - run: - name: Install Expo + - run-with-retry: + label: Install Expo command: npm i -g expo-cli@<< parameters.tag >> wait-on - - run: - name: Scaffold App + - run-with-retry: + label: Scaffold App command: cd ../ && rm -rf amplify_getting_started_<< parameters.framework >> && expo-cli init amplify_getting_started_<< parameters.framework >> --yes no_output_timeout: 5m - - run: - name: Install Amplify dependencies + - run-with-retry: + label: Install Amplify dependencies command: yarn add aws-amplify aws-amplify-react-native @react-native-community/netinfo @react-native-async-storage/async-storage @react-native-picker/picker - - run: - name: Call Amplify library in code + - run-with-retry: + label: Call Amplify library in code command: | echo "$IMPORT_STATEMENT" | cat - << parameters.main-file-path >> | tee << parameters.main-file-path >> echo "$LIBRARY_STATEMENT" >> << parameters.main-file-path >> - - run: - name: Start App + - run-with-retry: + label: Start App command: yarn web & wait-on http://localhost:19006 -t $MAX_WAIT_ON_TIMEOUT # End Canary Orb