Section 12/171 menit
12. Tips: Caching, Mirror, Registry
12. Tips: Caching, Mirror, Registry
CI Build Cache
Di CI (GitHub Actions, Xcode Cloud), cache folder berikut untuk speedup:
swift
# GitHub Actions example
- uses: actions/cache@v3
with:
path: |
~/Library/Caches/org.swift.swiftpm
.build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
Key dari Package.resolved hash → invalidasi cache otomatis saat dependency berubah.
Dependency Mirror
Untuk perusahaan dengan firewall ketat atau ingin mirror dependency:
swift
# Setup mirror dari github.com/apple/swift-collections ke internal Git server
swift package config set-mirror \
--original-url https://github.com/apple/swift-collections.git \
--mirror-url https://git.company.com/mirrors/swift-collections.git
Package Registry (Swift 5.7+)
Alternatif git-based dependency: registry yang mirip npm/PyPI.
swift
// swift-tools-version: 5.7
dependencies: [
.package(id: "apple.swift-collections", from: "1.0.0"),
]
Configure registry:
swift
swift package-registry set https://registry.company.com
Manfaat: lebih cepat (tarball vs git clone), bisa di-cache di binary, otorisasi enterprise.
Offline Build
swift
# Resolve sekali saat online
swift package resolve
# Build offline (gunakan checkouts yang sudah ada)
swift build --skip-update