Skip to content

Commit 88961a0

Browse files
authored
chore: Caching dependencies when building and testing (#3168)
1 parent 6f14608 commit 88961a0

File tree

6 files changed

+296
-6
lines changed

6 files changed

+296
-6
lines changed

.github/composite_actions/run_xcodebuild/action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
required: false
2020
type: string
2121
default: 'iphonesimulator'
22+
disable_package_resolution:
23+
required: false
24+
type: boolean
25+
default: false
2226
other_flags:
2327
required: false
2428
type: string
@@ -39,6 +43,11 @@ runs:
3943
if [ ! -z "$XCODE_PATH" ]; then
4044
sudo xcode-select -s $XCODE_PATH
4145
fi
46+
47+
otherFlags="${{ inputs.other_flags }}"
48+
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
49+
otherFlags+=" -disableAutomaticPackageResolution"
50+
fi
4251
xcodebuild -version
43-
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
52+
xcodebuild build -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' $otherFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
4453
shell: bash

.github/composite_actions/run_xcodebuild_test/action.yml

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ inputs:
2727
required: false
2828
type: boolean
2929
default: false
30+
cloned_source_packages_path:
31+
required: false
32+
type: string
33+
default: ''
34+
derived_data_path:
35+
required: false
36+
type: string
37+
default: ''
38+
disable_package_resolution:
39+
required: false
40+
type: boolean
41+
default: false
42+
test_without_building:
43+
required: false
44+
type: boolean
45+
default: false
3046

3147
runs:
3248
using: "composite"
@@ -36,6 +52,8 @@ runs:
3652
SCHEME: ${{ inputs.scheme }}
3753
PROJECT_PATH: ${{ inputs.project_path }}
3854
XCODE_PATH: ${{ inputs.xcode_path }}
55+
CLONED_SOURCE_PACKAGES_PATH: ${{ inputs.cloned_source_packages_path }}
56+
DERIVED_DATA_PATH: ${{ inputs.derived_data_path }}
3957
run: |
4058
if [ ! -z "$PROJECT_PATH" ]; then
4159
cd $PROJECT_PATH
@@ -44,23 +62,66 @@ runs:
4462
echo "Using Xcode $XCODE_PATH"
4563
sudo xcode-select -s $XCODE_PATH
4664
fi
65+
66+
clonedSourcePackagesPath=""
67+
if [ ! -z "$CLONED_SOURCE_PACKAGES_PATH" ]; then
68+
echo "Using custom cloned source packages path"
69+
clonedSourcePackagesPath+="-clonedSourcePackagesDirPath $CLONED_SOURCE_PACKAGES_PATH"
70+
fi
71+
72+
derivedDataPath=""
73+
if [ ! -z "$DERIVED_DATA_PATH" ]; then
74+
echo "Using custom DerivedData path"
75+
derivedDataPath+="-derivedDataPath $DERIVED_DATA_PATH"
76+
fi
77+
4778
coverageFlags=""
4879
if [ "${{ inputs.generate_coverage }}" == "true" ]; then
4980
echo "Code Coverage is enabled!"
50-
coverageFlags+="-derivedDataPath Build/ -clonedSourcePackagesDirPath "~/Library/Developer/Xcode/DerivedData/$SCHEME" -enableCodeCoverage YES"
81+
coverageFlags+="-enableCodeCoverage YES"
82+
if [ -z "$clonedSourcePackagesPath" ]; then
83+
clonedSourcePackagesPath+="-clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify"
84+
fi
85+
86+
if [ -z "$derivedDataPath" ]; then
87+
derivedDataPath+="-derivedDataPath Build/"
88+
fi
89+
fi
90+
91+
if [ "${{ inputs.disable_package_resolution }}" == "true" ]; then
92+
echo "Disabling Automatic Package Resolution"
93+
clonedSourcePackagesPath+=" -disableAutomaticPackageResolution"
94+
fi
95+
96+
action="test"
97+
if [ "${{ inputs.test_without_building }}" == "true" ]; then
98+
echo "Testing without building..."
99+
action+="-without-building"
51100
fi
101+
52102
xcode-select -p
53103
xcodebuild -version
54-
xcodebuild test -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} $coverageFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
104+
xcodebuild $action -scheme $SCHEME -sdk '${{ inputs.sdk }}' -destination '${{ inputs.destination }}' ${{ inputs.other_flags }} $clonedSourcePackagesPath $derivedDataPath $coverageFlags | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
55105
shell: bash
56106

57107
- name: Generate Coverage report
58108
if: ${{ inputs.generate_coverage == 'true' }}
109+
env:
110+
SCHEME: ${{ inputs.scheme }}
111+
DERIVED_DATA_PATH: ${{ inputs.derived_data_path }}
59112
run: |
60113
echo "Generating Coverage report..."
61-
cd Build/Build/ProfileData
114+
115+
derivedDataPath=""
116+
if [ ! -z "$DERIVED_DATA_PATH" ]; then
117+
derivedDataPath="$DERIVED_DATA_PATH"
118+
else
119+
derivedDataPath="Build"
120+
fi
121+
122+
cd $derivedDataPath/Build/ProfileData
62123
cd $(ls -d */|head -n 1)
63124
pathCoverage=Build/Build/ProfileData/${PWD##*/}/Coverage.profdata
64125
cd ${{ github.workspace }}
65-
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage Build/Build/Products/Debug-${{ inputs.sdk }}/$SCHEME.o > $SCHEME-Coverage.lcov
126+
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage $derivedDataPath/Build/Products/Debug-${{ inputs.sdk }}/$SCHEME.o > $SCHEME-Coverage.lcov
66127
shell: bash

.github/workflows/build_amplify_swift.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ jobs:
2222
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
2323
with:
2424
persist-credentials: false
25+
- name: Attempt to restore dependencies cache
26+
id: cache-packages
27+
timeout-minutes: 4
28+
continue-on-error: true
29+
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
30+
with:
31+
path: ~/Library/Developer/Xcode/DerivedData/Amplify
32+
key: amplify-packages-${{ hashFiles('Package.resolved') }}
33+
restore-keys: |
34+
amplify-packages-
2535
- name: Build Amplify Swift for iOS
2636
uses: ./.github/composite_actions/run_xcodebuild
2737
with:
2838
scheme: Amplify-Package
2939
destination: 'platform=iOS Simulator,name=iPhone 14,OS=16.4'
3040
xcode_path: '/Applications/Xcode_14.3.app'
41+
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
42+
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
43+
- name: Save the dependencies cache if necessary
44+
if: steps.cache-packages.outputs.cache-hit != 'true' && github.ref_name == 'main'
45+
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
46+
with:
47+
path: ~/Library/Developer/Xcode/DerivedData/Amplify
48+
key: ${{ steps.cache-packages.outputs.cache-primary-key }}
3149

3250
build-amplify-swift-macOS:
3351
runs-on: macos-13
@@ -36,13 +54,24 @@ jobs:
3654
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
3755
with:
3856
persist-credentials: false
57+
- name: Cache packages
58+
id: cache-packages
59+
timeout-minutes: 4
60+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
61+
with:
62+
path: ~/Library/Developer/Xcode/DerivedData/Amplify
63+
key: amplify-packages-${{ hashFiles('Package.resolved') }}
64+
restore-keys: |
65+
amplify-packages-
3966
- name: Build Amplify Swift for macOS
4067
uses: ./.github/composite_actions/run_xcodebuild
4168
with:
4269
scheme: Amplify-Package
4370
destination: platform=macOS,arch=x86_64
4471
sdk: macosx
4572
xcode_path: '/Applications/Xcode_14.3.app'
73+
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
74+
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
4675

4776
build-amplify-swift-tvOS:
4877
runs-on: macos-13
@@ -51,13 +80,24 @@ jobs:
5180
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
5281
with:
5382
persist-credentials: false
83+
- name: Cache packages
84+
timeout-minutes: 4
85+
id: cache-packages
86+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
87+
with:
88+
path: ~/Library/Developer/Xcode/DerivedData/Amplify
89+
key: amplify-packages-${{ hashFiles('Package.resolved') }}
90+
restore-keys: |
91+
amplify-packages-
5492
- name: Build Amplify Swift for tvOS
5593
uses: ./.github/composite_actions/run_xcodebuild
5694
with:
5795
scheme: Amplify-Package
5896
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=16.4
5997
sdk: appletvsimulator
6098
xcode_path: '/Applications/Xcode_14.3.app'
99+
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
100+
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
61101

62102
build-amplify-swift-watchOS:
63103
runs-on: macos-13
@@ -66,13 +106,24 @@ jobs:
66106
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3
67107
with:
68108
persist-credentials: false
109+
- name: Cache packages
110+
id: cache-packages
111+
timeout-minutes: 4
112+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
113+
with:
114+
path: ~/Library/Developer/Xcode/DerivedData/Amplify
115+
key: amplify-packages-${{ hashFiles('Package.resolved') }}
116+
restore-keys: |
117+
amplify-packages-
69118
- name: Build Amplify Swift for watchOS
70119
uses: ./.github/composite_actions/run_xcodebuild
71120
with:
72121
scheme: Amplify-Package
73122
destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=9.4
74123
sdk: watchsimulator
75124
xcode_path: '/Applications/Xcode_14.3.app'
125+
disable_package_resolution: ${{ steps.cache-packages.outputs.cache-hit }}
126+
other_flags: '-derivedDataPath Build -clonedSourcePackagesDirPath ~/Library/Developer/Xcode/DerivedData/Amplify'
76127

77128
confirm-pass:
78129
runs-on: ubuntu-latest

.github/workflows/deploy_package.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ permissions:
1313
contents: write
1414

1515
jobs:
16+
build-amplify-swift:
17+
name: Build Amplify package
18+
uses: ./.github/workflows/build_amplify_swift.yml
19+
1620
unit-tests:
1721
name: Run Plugins Unit Tests
1822
uses: ./.github/workflows/unit_test.yml

0 commit comments

Comments
 (0)