Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaland committed Nov 1, 2023
1 parent 99d1e82 commit ee9474f
Show file tree
Hide file tree
Showing 4 changed files with 708 additions and 285 deletions.
35 changes: 34 additions & 1 deletion .github/composite_actions/run_xcodebuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ inputs:
required: false
type: string
default: 'iphonesimulator'
cloned_source_packages_path:
required: false
type: string
default: ''
derived_data_path:
required: false
type: string
default: ''
disable_package_resolution:
required: false
type: boolean
default: false
build_for_testing:
required: false
type: boolean
default: false
other_flags:
required: false
type: string
Expand All @@ -36,6 +48,8 @@ runs:
SCHEME: ${{ inputs.scheme }}
PROJECT_PATH: ${{ inputs.project_path }}
XCODE_PATH: ${{ inputs.xcode_path }}
CLONED_SOURCE_PACKAGES_PATH: ${{ inputs.cloned_source_packages_path }}
DERIVED_DATA_PATH: ${{ inputs.derived_data_path }}
run: |
if [ ! -z "$PROJECT_PATH" ]; then
cd $PROJECT_PATH
Expand All @@ -48,6 +62,25 @@ runs:
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
otherFlags+=" -disableAutomaticPackageResolution"
fi
if [ ! -z "$DERIVED_DATA_PATH" ]; then
echo "Using custom DerivedData path"
otherFlags+=" -derivedDataPath $DERIVED_DATA_PATH"
fi
if [ ! -z "$CLONED_SOURCE_PACKAGES_PATH" ]; then
echo "Using custom cloned source packages path"
otherFlags+=" -clonedSourcePackagesDirPath $CLONED_SOURCE_PACKAGES_PATH"
fi
xcode-select -p
xcodebuild -version
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' $otherFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
action="build"
if [ "${{ inputs.build_for_testing }}" == "true" ]; then
echo "Building for testing..."
action+="-for-testing"
fi
xcodebuild $action -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' $otherFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
shell: bash
138 changes: 138 additions & 0 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Run Unit Tests for the given parameters
on:
workflow_call:
inputs:
scheme:
description: 'The scheme to run the tests'
required: true
type: string
platform:
description: 'The platform in which to run these tests'
required: true
type: string
project_path:
required: false
type: string
xcode_version:
description: 'The version of Xcode used to run these tests'
required: true
type: string
timeout-minutes:
description: 'The timeout for each execution'
required: false
type: number
default: 30
generate_coverage_report:
description: 'Whether to generate and report code coverage'
required: false
type: boolean
default: false
build_cache_key:
description: 'The key used to retrieve the build cache'
required: false
default: ''
type: string
test_without_building:
type: boolean
required: false
default: false

permissions:
contents: read
actions: write

jobs:
unit-tests:
name: ${{ inputs.platform }} Tests | ${{ inputs.scheme }}
runs-on: macos-13
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false

- name: Get build parameters for ${{ inputs.platform}}
id: platform
uses: ./.github/composite_actions/get_platform_parameters
with:
platform: ${{ inputs.platform }}
xcode_version: ${{ inputs.xcode_version }}

- name: Attempt to use the dependencies cache
id: dependencies-cache
timeout-minutes: 4
continue-on-error: true
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: amplify-packages-${{ hashFiles('Package.resolved') }}
restore-keys: |
amplify-packages-
- name: Attempt to restore the build cache
id: build-cache
timeout-minutes: 4
continue-on-error: true
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ${{ github.workspace }}/Build
key: ${{ inputs.build_cache_key || format('{0}-{1}-latest-build-main', inputs.scheme, inputs.platform) }}

- name: Run ${{ inputs.platform }} Unit Tests
id: run-tests
continue-on-error: true
uses: ./.github/composite_actions/run_xcodebuild_test
with:
scheme: ${{ inputs.scheme }}
destination: ${{ steps.platform.outputs.destination }}
sdk: ${{ steps.platform.outputs.sdk }}
xcode_path: /Applications/Xcode_${{ inputs.xcode_version }}.app
generate_coverage: ${{ inputs.generate_coverage_report }}
cloned_source_packages_path: ~/Library/Developer/Xcode/DerivedData/Amplify
derived_data_path: ${{ github.workspace }}/Build
disable_package_resolution: ${{ steps.dependencies-cache.outputs.cache-hit }}
test_without_building: ${{ inputs.test_without_building && steps.dependencies-cache.outputs.cache-hit }}
other_flags: -test-iterations 3 -retry-tests-on-failure

- name: Retry ${{ inputs.platform }} Unit Tests
if: steps.run-tests.outcome=='failure'
id: retry-tests
uses: ./.github/composite_actions/run_xcodebuild_test
with:
scheme: ${{ inputs.scheme }}
destination: ${{ steps.platform.outputs.destination }}
sdk: ${{ steps.platform.outputs.sdk }}
xcode_path: /Applications/Xcode_${{ inputs.xcode_version }}.app
project_path: ${{ inputs.project_path }}
generate_coverage: true
cloned_source_packages_path: ~/Library/Developer/Xcode/DerivedData/Amplify
derived_data_path: ${{ github.workspace }}/Build
disable_package_resolution: true
test_without_building: ${{ inputs.test_without_building && steps.dependencies-cache.outputs.cache-hit}}
other_flags: -test-iterations 3 -retry-tests-on-failure

- name: Delete the old build cache on main
if: github.ref_name == 'main' && steps.build-cache.outputs.cache-hit
env:
GH_TOKEN: ${{ github.token }}
continue-on-error: true
run: |
gh cache delete ${{ steps.build-cache.outputs.cache-primary-key }}
shell: bash

- name: Save the new build cache on main
if: github.ref_name == 'main'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ${{ github.workspace }}/Build
key: ${{ steps.build-cache.outputs.cache-primary-key }}

- name: Store Coverage Report File
if: ${{ inputs.generate_coverage_report == true }}
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce #v3.1.2
with:
name: ${{ inputs.scheme }}-Coverage-${{ github.sha }}
path: ${{ github.workspace }}/${{ inputs.scheme }}-Coverage.lcov
if-no-files-found: error
retention-days: 1
102 changes: 102 additions & 0 deletions .github/workflows/run_unit_tests_without_building.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Run All Unit Tests without Building
on:
- push

permissions:
contents: read
actions: write

jobs:
build-for-testing:
name: Build Amplify-Package for testing
runs-on: macos-13
strategy:
fail-fast: false
matrix:
platform: [iOS, macOS, tvOS, watchOS]
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false

- name: Get build parameters for ${{ matrix.platform }}
id: platform
uses: ./.github/composite_actions/get_platform_parameters
with:
platform: ${{ matrix.platform }}
xcode_version: '14.3'

- name: Attempt to use the dependencies cache
id: dependencies-cache
timeout-minutes: 4
continue-on-error: true
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: amplify-packages-${{ hashFiles('Package.resolved') }}
restore-keys: |
amplify-packages-
- name: Build Amplify-Package for testing
id: run-tests
continue-on-error: true
uses: ./.github/composite_actions/run_xcodebuild
with:
scheme: Amplify-Package
destination: ${{ steps.platform.outputs.destination }}
sdk: ${{ steps.platform.outputs.sdk }}
xcode_path: /Applications/Xcode_14.3.app
cloned_source_packages_path: ~/Library/Developer/Xcode/DerivedData/Amplify
derived_data_path: ${{ github.workspace }}/Build
disable_package_resolution: ${{ steps.dependencies-cache.outputs.cache-hit }}
build_for_testing: true

- name: Save the build cache
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ${{ github.workspace }}/Build
key: Amplify-${{ matrix.platform }}-cache-${{ github.ref_name }}

test-without-building:
name: ${{ matrix.scheme }} Unit Tests
needs: [build-for-testing]
strategy:
fail-fast: false
matrix:
platform: [iOS, macOS, tvOS, watchOS]
scheme: [
Amplify,
AWSPluginsCore,
AWSAPIPlugin,
AWSCloudWatchLoggingPlugin,
AWSCognitoAuthPlugin,
AWSDataStorePlugin,
AWSLocationGeoPlugin,
AWSPredictionsPlugin,
AWSPinpointAnalyticsPlugin,
AWSPinpointPushNotificationsPlugin,
AWSS3StoragePlugin,
CoreMLPredictionsPlugin
]
uses: ./.github/workflows/run_unit_tests.yml
with:
scheme: ${{ matrix.scheme }}
platform: ${{ matrix.platform }}
xcode_version: '14.3'
generate_coverage_report: ${{ matrix.platform == 'iOS' }}
build_cache_key: Amplify-${{ matrix.platform }}-cache-${{ github.ref_name }}
test_without_building: true

delete-package-cache:
if: github.ref_name != 'main'
runs-on: ubuntu-latest
needs: [test-without-building]
strategy:
fail-fast: false
matrix:
platform: [iOS, macOS, tvOS, watchOS]
steps:
- run: |
gh cache delete Amplify-${{ matrix.platform }}-cache-${{ github.ref_name }}
shell: bash
Loading

0 comments on commit ee9474f

Please sign in to comment.