Skip to content

Commit

Permalink
chore(workflows): caching one build for Amplify-Package instead of on…
Browse files Browse the repository at this point in the history
…e for each plugin (#3342)
  • Loading branch information
ruisebas authored Nov 9, 2023
1 parent bffb88a commit ae59b0a
Show file tree
Hide file tree
Showing 46 changed files with 757 additions and 752 deletions.
22 changes: 22 additions & 0 deletions .github/composite_actions/run_xcodebuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ 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
Expand All @@ -36,6 +44,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 @@ -46,8 +56,20 @@ runs:
otherFlags="${{ inputs.other_flags }}"
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
echo "Disabling Automatic Package Resolution"
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
xcodebuild -version
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' $otherFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
shell: bash
177 changes: 47 additions & 130 deletions .github/workflows/build_amplify_swift.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
name: Build | Amplify Swift
name: Build Amplify-Package for the given platform
on:
workflow_call:
inputs:
identifier:
required: true
platform:
type: string
workflow_dispatch:
push:
branches-ignore:
- main
- release
required: true

permissions:
contents: read

concurrency:
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main'}}
contents: read
actions: write

jobs:
build-amplify-swift-iOS:
build-amplify-swift:
name: Build Amplify-Package | ${{ inputs.platform }}
runs-on: macos-13
timeout-minutes: 20
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Attempt to restore dependencies cache
id: cache-packages

- name: Get build parameters for ${{ inputs.platform }}
id: platform
uses: ./.github/composite_actions/get_platform_parameters
with:
platform: ${{ inputs.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
Expand All @@ -36,131 +37,47 @@ jobs:
key: amplify-packages-${{ hashFiles('Package.resolved') }}
restore-keys: |
amplify-packages-
- name: Build Amplify Swift for iOS
uses: ./.github/composite_actions/run_xcodebuild
with:
scheme: Amplify-Package
destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4'
xcode_path: '/Applications/Xcode_14.3.app'
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
- name: Save the dependencies cache if necessary
if: steps.cache-packages.outputs.cache-hit != 'true' && github.ref_name == 'main'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: ${{ steps.cache-packages.outputs.cache-primary-key }}
build-amplify-swift-macOS:
runs-on: macos-13
timeout-minutes: 20
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Attempt to restore dependencies cache
id: cache-packages
- name: Attempt to restore the build cache from main
id: build-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 Swift for macOS
uses: ./.github/composite_actions/run_xcodebuild
with:
scheme: Amplify-Package
destination: platform=macOS,arch=x86_64
sdk: macosx
xcode_path: '/Applications/Xcode_14.3.app'
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
- name: Save the dependencies cache if necessary
if: steps.cache-packages.outputs.cache-hit != 'true' && github.ref_name == 'main'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: ${{ steps.cache-packages.outputs.cache-primary-key }}
path: ${{ github.workspace }}/Build
key: Amplify-${{ inputs.platform }}-build-cache

build-amplify-swift-tvOS:
runs-on: macos-13
timeout-minutes: 20
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Attempt to restore dependencies cache
timeout-minutes: 4
id: cache-packages
- name: Build Amplify for Swift
id: build-package
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 Swift for tvOS
uses: ./.github/composite_actions/run_xcodebuild
with:
scheme: Amplify-Package
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=16.4
sdk: appletvsimulator
xcode_path: '/Applications/Xcode_14.3.app'
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
- name: Save the dependencies cache if necessary
if: steps.cache-packages.outputs.cache-hit != 'true' && github.ref_name == 'main'
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 }}

- name: Save the dependencies cache in main
if: steps.dependencies-cache.outputs.cache-hit != 'true' && github.ref_name == 'main'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: ${{ steps.cache-packages.outputs.cache-primary-key }}

build-amplify-swift-watchOS:
runs-on: macos-13
timeout-minutes: 20
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Attempt to restore dependencies cache
id: cache-packages
timeout-minutes: 4
key: ${{ steps.dependencies-cache.outputs.cache-primary-key }}

- name: Delete the old build cache
if: steps.build-cache.outputs.cache-hit && github.ref_name == 'main'
env:
GH_TOKEN: ${{ github.token }}
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 Swift for watchOS
uses: ./.github/composite_actions/run_xcodebuild
with:
scheme: Amplify-Package
destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=9.4
sdk: watchsimulator
xcode_path: '/Applications/Xcode_14.3.app'
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
- name: Save the dependencies cache if necessary
if: steps.cache-packages.outputs.cache-hit != 'true' && github.ref_name == 'main'
run: |
gh cache delete ${{ steps.build-cache.outputs.cache-primary-key }}
- name: Save the build cache
if: github.ref_name == 'main'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/Library/Developer/Xcode/DerivedData/Amplify
key: ${{ steps.cache-packages.outputs.cache-primary-key }}

confirm-pass:
runs-on: ubuntu-latest
name: Confirm Passing Build Steps
if: ${{ !cancelled() }}
needs: [
build-amplify-swift-iOS,
build-amplify-swift-macOS,
build-amplify-swift-tvOS,
build-amplify-swift-watchOS
]
env:
EXIT_CODE: ${{ contains(needs.*.result, 'failure') && 1 || 0 }}
steps:
- run: exit $EXIT_CODE
path: ${{ github.workspace }}/Build
key: ${{ steps.build-cache.outputs.cache-primary-key }}
67 changes: 67 additions & 0 deletions .github/workflows/build_amplify_swift_platforms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build | Amplify Swift
on:
workflow_call:
inputs:
identifier:
required: true
type: string
workflow_dispatch:
inputs:
ios:
description: '📱 iOS'
required: true
default: true
type: boolean
macos:
description: '💻 macOS'
required: true
default: true
type: boolean
tvos:
description: '📺 tvOS'
required: true
default: true
type: boolean
watchos:
description: '⌚️ watchOS'
required: true
default: true
type: boolean
push:
branches-ignore:
- main
- release

permissions:
contents: read
actions: write

concurrency:
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref_name != 'main'}}

jobs:
build-amplify-swift:
name: Build Amplify Swift for ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [iOS, macOS, tvOS, watchOS]
exclude:
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'None' }}
- platform: ${{ github.event.inputs.macos == 'false' && 'macOS' || 'None' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'None' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'None' }}
uses: ./.github/workflows/build_amplify_swift.yml
with:
platform: ${{ matrix.platform }}

confirm-pass:
runs-on: ubuntu-latest
name: Confirm Passing Build Steps
if: ${{ !cancelled() }}
needs: [ build-amplify-swift ]
env:
EXIT_CODE: ${{ contains(needs.*.result, 'failure') && 1 || 0 }}
steps:
- run: exit $EXIT_CODE
2 changes: 1 addition & 1 deletion .github/workflows/deploy_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:
jobs:
build-amplify-swift:
name: Build Amplify package
uses: ./.github/workflows/build_amplify_swift.yml
uses: ./.github/workflows/build_amplify_swift_platforms.yml
with:
identifier: 'workflow-call-build-amplify-swift'

Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/integ_test_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ jobs:
matrix:
platform: [iOS, tvOS, watchOS]
exclude:
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'None' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'None' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'None' }}
uses: ./.github/workflows/run_integration_tests.yml
with:
scheme: ${{ matrix.platform == 'watchOS' && 'AWSPinpointAnalyticsPluginIntegrationTestsWatch' || 'AWSPinpointAnalyticsPluginIntegrationTests' }}
platform: ${{ matrix.platform }}
build_cache_key: AWSPinpointAnalyticsPlugin-${{ matrix.platform }}-latest-build-main
project_path: ./AmplifyPlugins/Analytics/Tests/AnalyticsHostApp
xcode_version: '14.3'
resource_subfolder: analytics
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/integ_test_api_functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ jobs:
matrix:
platform: [iOS, tvOS, watchOS]
exclude:
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'None' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'None' }}
- platform: ${{ github.event.inputs.watchos == 'false' && 'watchOS' || 'None' }}
uses: ./.github/workflows/run_integration_tests.yml
with:
scheme: ${{ matrix.platform == 'watchOS' && 'AWSAPIPluginFunctionalTestsWatch' || 'AWSAPIPluginFunctionalTests' }}
platform: ${{ matrix.platform }}
build_cache_key: AWSAPIPlugin-${{ matrix.platform }}-latest-build-main
project_path: ./AmplifyPlugins/API/Tests/APIHostApp
xcode_version: '14.3'
resource_subfolder: api
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/integ_test_api_graphql_auth_directive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ jobs:
matrix:
platform: [iOS, tvOS, watchOS]
exclude:
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'Dummy' }}
- platform: ${{ github.event.inputs.ios == 'false' && 'iOS' || 'None' }}
- platform: ${{ github.event.inputs.tvos == 'false' && 'tvOS' || 'None' }}
uses: ./.github/workflows/run_integration_tests.yml
with:
scheme: AWSAPIPluginGraphQLAuthDirectiveTests
platform: ${{ matrix.platform }}
build_cache_key: AWSAPIPlugin-${{ matrix.platform }}-latest-build-main
project_path: ./AmplifyPlugins/API/Tests/APIHostApp
xcode_version: '14.3'
resource_subfolder: api
Expand Down
Loading

0 comments on commit ae59b0a

Please sign in to comment.