Skip to content

Commit

Permalink
chore: Caching dependencies when building and testing (#3168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas authored Aug 23, 2023
1 parent 6f14608 commit 88961a0
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 6 deletions.
11 changes: 10 additions & 1 deletion .github/composite_actions/run_xcodebuild/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
required: false
type: string
default: 'iphonesimulator'
disable_package_resolution:
required: false
type: boolean
default: false
other_flags:
required: false
type: string
Expand All @@ -39,6 +43,11 @@ runs:
if [ ! -z "$XCODE_PATH" ]; then
sudo xcode-select -s $XCODE_PATH
fi
otherFlags="${{ inputs.other_flags }}"
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
otherFlags+=" -disableAutomaticPackageResolution"
fi
xcodebuild -version
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' $otherFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
shell: bash
69 changes: 65 additions & 4 deletions .github/composite_actions/run_xcodebuild_test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ inputs:
required: false
type: boolean
default: false
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
test_without_building:
required: false
type: boolean
default: false

runs:
using: "composite"
Expand All @@ -36,6 +52,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 @@ -44,23 +62,66 @@ runs:
echo "Using Xcode $XCODE_PATH"
sudo xcode-select -s $XCODE_PATH
fi
clonedSourcePackagesPath=""
if [ ! -z "$CLONED_SOURCE_PACKAGES_PATH" ]; then
echo "Using custom cloned source packages path"
clonedSourcePackagesPath+="-clonedSourcePackagesDirPath $CLONED_SOURCE_PACKAGES_PATH"
fi
derivedDataPath=""
if [ ! -z "$DERIVED_DATA_PATH" ]; then
echo "Using custom DerivedData path"
derivedDataPath+="-derivedDataPath $DERIVED_DATA_PATH"
fi
coverageFlags=""
if [ "${{ inputs.generate_coverage }}" == "true" ]; then
echo "Code Coverage is enabled!"
coverageFlags+="-derivedDataPath Build/ -clonedSourcePackagesDirPath "~/Library/Developer/Xcode/DerivedData/$SCHEME" -enableCodeCoverage YES"
coverageFlags+="-enableCodeCoverage YES"
if [ -z "$clonedSourcePackagesPath" ]; then
clonedSourcePackagesPath+="-clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify"
fi
if [ -z "$derivedDataPath" ]; then
derivedDataPath+="-derivedDataPath Build/"
fi
fi
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
echo "Disabling Automatic Package Resolution"
clonedSourcePackagesPath+=" -disableAutomaticPackageResolution"
fi
action="test"
if [ "${{ inputs.test_without_building }}" == "true" ]; then
echo "Testing without building..."
action+="-without-building"
fi
xcode-select -p
xcodebuild -version
xcodebuild test -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} $coverageFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
xcodebuild $action -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} $clonedSourcePackagesPath $derivedDataPath $coverageFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
shell: bash

- name: Generate Coverage report
if: ${{ inputs.generate_coverage == 'true' }}
env:
SCHEME: ${{ inputs.scheme }}
DERIVED_DATA_PATH: ${{ inputs.derived_data_path }}
run: |
echo "Generating Coverage report..."
cd Build/Build/ProfileData
derivedDataPath=""
if [ ! -z "$DERIVED_DATA_PATH" ]; then
derivedDataPath="$DERIVED_DATA_PATH"
else
derivedDataPath="Build"
fi
cd $derivedDataPath/Build/ProfileData
cd $(ls -d */|head -n 1)
pathCoverage=Build/Build/ProfileData/${PWD##*/}/Coverage.profdata
cd ${{ github.workspace }}
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage Build/Build/Products/Debug-${{ inputs.sdk }}/$SCHEME.o > $SCHEME-Coverage.lcov
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage $derivedDataPath/Build/Products/Debug-${{ inputs.sdk }}/$SCHEME.o > $SCHEME-Coverage.lcov
shell: bash
51 changes: 51 additions & 0 deletions .github/workflows/build_amplify_swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@ jobs:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Attempt to restore dependencies cache
id: cache-packages
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 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
Expand All @@ -36,13 +54,24 @@ jobs:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Cache packages
id: cache-packages
timeout-minutes: 4
uses: actions/cache@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'

build-amplify-swift-tvOS:
runs-on: macos-13
Expand All @@ -51,13 +80,24 @@ jobs:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Cache packages
timeout-minutes: 4
id: cache-packages
uses: actions/cache@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'

build-amplify-swift-watchOS:
runs-on: macos-13
Expand All @@ -66,13 +106,24 @@ jobs:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
with:
persist-credentials: false
- name: Cache packages
id: cache-packages
timeout-minutes: 4
uses: actions/cache@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'

confirm-pass:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ permissions:
contents: write

jobs:
build-amplify-swift:
name: Build Amplify package
uses: ./.github/workflows/build_amplify_swift.yml

unit-tests:
name: Run Plugins Unit Tests
uses: ./.github/workflows/unit_test.yml
Expand Down
Loading

0 comments on commit 88961a0

Please sign in to comment.