Skip to content

Commit c65904f

Browse files
author
Di Wu
authored
ci: use shallow checkout with depth 1 (#2830)
1 parent 6f62290 commit c65904f

File tree

1 file changed

+37
-73
lines changed

1 file changed

+37
-73
lines changed

.circleci/config.yml

Lines changed: 37 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ parameters:
1212

1313
orbs:
1414
aws-cli: circleci/[email protected]
15+
ruby: circleci/[email protected]
1516
# Using inline orb for now
1617
getting-started-smoke-test:
1718
orbs:
@@ -96,34 +97,31 @@ orbs:
9697
defaults: &defaults
9798
macos:
9899
xcode: '14.0.0'
99-
working_directory: ~/amplify-swift
100100
environment:
101-
BUNDLE_PATH: vendor/bundle
102-
103-
references:
104-
repo_cache_key: &repo_cache_key v2-repo-{{ .Branch }}-{{ .Revision }}
105-
106-
restore_repo: &restore_repo
107-
restore_cache:
108-
keys:
109-
- *repo_cache_key
110-
- v2-repo-{{ .Branch }}
111-
- v2-repo
101+
BUNDLE_JOBS: 4
102+
BUNDLE_RETRY: 3
112103

113104
commands:
114-
115-
restore_gems:
116-
steps:
117-
- restore_cache:
118-
keys:
119-
- v2-gems-{{ checksum "~/amplify-swift/Gemfile.lock" }}
120-
- v2-gems-
121-
122-
check_bundle:
105+
shallow_checkout:
123106
steps:
124107
- run:
125-
name: Check bundle
126-
command: bundle check --path $BUNDLE_PATH || bundle install --path $BUNDLE_PATH
108+
name: Checkout code shallow and change to working directory
109+
command: |
110+
git clone --depth 1 "$CIRCLE_REPOSITORY_URL" --branch "$CIRCLE_BRANCH" $CIRCLE_WORKING_DIRECTORY
111+
cd $CIRCLE_WORKING_DIRECTORY
112+
113+
if [ -n "$CIRCLE_TAG" ]; then
114+
echo 'Fetch tag'
115+
git fetch --depth 1 --force origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
116+
elif [[ $(echo $CIRCLE_PULL_REQUEST | grep -E "${CIRCLE_BRANCH}$") ]]; then
117+
echo 'Fetch pull request'
118+
git fetch --depth 1 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH"
119+
else
120+
echo 'Fetch branch'
121+
git fetch --depth 1 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
122+
fi
123+
echo "Checking out the CI HEAD"
124+
git reset --hard "$CIRCLE_SHA1"
127125
128126
make_artifacts_directory:
129127
steps:
@@ -137,44 +135,18 @@ commands:
137135
path: artifacts
138136

139137
jobs:
140-
checkout_code:
141-
<<: *defaults
142-
steps:
143-
- *restore_repo
144-
- checkout
145-
- save_cache:
146-
key: *repo_cache_key
147-
paths:
148-
- ~/amplify-swift
149-
150-
install_gems:
151-
<<: *defaults
152-
steps:
153-
- *restore_repo
154-
- restore_gems
155-
- run:
156-
name: Bundle install
157-
command: bundle check --path $BUNDLE_PATH || bundle install --path $BUNDLE_PATH
158-
environment:
159-
BUNDLE_JOBS: 4
160-
BUNDLE_RETRY: 3
161-
- save_cache:
162-
key: v2-gems-{{ checksum "~/amplify-swift/Gemfile.lock" }}
163-
paths:
164-
- vendor/bundle
165-
166138
build_amplify_ios_spm:
167139
<<: *defaults
168140
steps:
169-
- *restore_repo
141+
- shallow_checkout
170142
- make_artifacts_directory
171143
- run:
172144
name: Build amplify for ios SPM
173145
command: xcodebuild build -scheme Amplify-Package -sdk iphonesimulator -destination "<< pipeline.parameters.ios-destination >>" | tee "artifacts/build-Ampify-for-ios-SPM.log" | xcpretty
174146
build_amplify_macos_spm:
175147
<<: *defaults
176148
steps:
177-
- *restore_repo
149+
- shallow_checkout
178150
- make_artifacts_directory
179151
- run:
180152
name: Build amplify for macos SPM
@@ -194,7 +166,7 @@ jobs:
194166
type: string
195167
description: << parameters.scheme >> unit test
196168
steps:
197-
- *restore_repo
169+
- shallow_checkout
198170
- make_artifacts_directory
199171
- run:
200172
name: Build << parameters.scheme >>
@@ -204,20 +176,19 @@ jobs:
204176
command: xcodebuild test -scheme <<parameters.scheme>> -sdk << parameters.sdk >> -destination "<<parameters.destination>>" | tee "artifacts/test-<< parameters.scheme >>-<< parameters.sdk >>.log" | xcpretty --simple --color --report junit
205177
- run:
206178
name: Upload << parameters.scheme >> coverage report to Codecov
207-
command: bash ~/amplify-swift/build-support/codecov.sh -F << parameters.scheme >>_unit_test -J '^<< parameters.scheme >>$'
179+
command: bash $CIRCLE_WORKING_DIRECTORY/build-support/codecov.sh -F << parameters.scheme >>_unit_test -J '^<< parameters.scheme >>$'
208180
- store_test_results:
209181
path: build/reports
210182
- upload_artifacts
211183

212184
generate_api_docs:
213185
<<: *defaults
214186
steps:
215-
- *restore_repo
216-
- restore_gems
217-
- check_bundle
187+
- shallow_checkout
188+
- ruby/install-deps
218189
- run:
219190
name: Jazzy API doc generation
220-
command: bash ~/amplify-swift/CircleciScripts/jazzy_doc_gen.sh
191+
command: bash $CIRCLE_WORKING_DIRECTORY/CircleciScripts/jazzy_doc_gen.sh
221192

222193
deploy:
223194
<<: *defaults
@@ -230,18 +201,17 @@ jobs:
230201
- add_ssh_keys:
231202
fingerprints:
232203
- '3f:b4:9f:aa:0b:d7:c5:16:fb:44:44:35:cb:a7:70:e0'
233-
- *restore_repo
234-
- restore_gems
235-
- check_bundle
204+
- shallow_checkout
205+
- ruby/install-deps
236206
- run:
237207
name: Release Amplify for Swift
238208
command: bundle exec fastlane << parameters.lane >>
239209
no_output_timeout: 60m
240-
210+
241211
fortify_scan:
242212
<<: *defaults
243213
steps:
244-
- *restore_repo
214+
- shallow_checkout
245215
- run:
246216
name: Make source directory
247217
command: |
@@ -269,8 +239,8 @@ jobs:
269239
name: Run Installer
270240
command: |
271241
Fortify_SCA_and_Apps_22.1.1_osx_x64.app/Contents/MacOS/installbuilder.sh --mode unattended --installdir Fortify --InstallSamples 0 --fortify_license_path fortify.license --MigrateSCA 0
272-
export PATH=~/amplify-swift/Fortify/bin:$PATH
273-
echo "export PATH=~/amplify-swift/Fortify/bin:\$PATH" >> "$BASH_ENV"
242+
export PATH=$CIRCLE_WORKING_DIRECTORY/Fortify/bin:$PATH
243+
echo "export PATH=$CIRCLE_WORKING_DIRECTORY/Fortify/bin:\$PATH" >> "$BASH_ENV"
274244
fortifyupdate -acceptKey
275245
sourceanalyzer -version
276246
- run:
@@ -309,21 +279,15 @@ workflows:
309279
not:
310280
equal: [ scheduled_pipeline, << pipeline.trigger_source >> ]
311281
jobs:
312-
- checkout_code
313-
- install_gems:
314-
requires:
315-
- checkout_code
316282
- fortify_scan:
317283
context:
318284
- amplify-swift-aws-s3-download
319-
requires:
320-
- install_gems
321285
- build_amplify_ios_spm:
322286
requires:
323287
- fortify_scan
324288
- build_amplify_macos_spm:
325289
requires:
326-
- fortify_scan
290+
- fortify_scan
327291
- unit_test:
328292
name: ios_unit_test_amplify
329293
scheme: Amplify
@@ -456,7 +420,7 @@ workflows:
456420
filters:
457421
branches:
458422
only:
459-
- main
423+
- main
460424
- deploy:
461425
name: deploy stable
462426
lane: release
@@ -489,4 +453,4 @@ workflows:
489453
- getting-started-smoke-test/ios:
490454
xcode-version: "13.4.1"
491455
simulator-os-version: "15.5"
492-
simulator-device: "iPhone 13 Pro"
456+
simulator-device: "iPhone 13 Pro"

0 commit comments

Comments
 (0)