Skip to content

Commit 5cc9fbb

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Automate SwiftPM updates. (#6836)
Summary: Let's make the versioning daily and create a new dedicated branch with swiftpm packages for it, so that the clients can pin themselves to a specific version and never run into checksum mismatch issues when we overwrite the binaries on S3. Differential Revision: D65908021
1 parent 6f63893 commit 5cc9fbb

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

.github/workflows/apple.yml

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ concurrency:
2626
cancel-in-progress: true
2727

2828
jobs:
29+
set-version:
30+
runs-on: ubuntu-22.04
31+
outputs:
32+
version: ${{ steps.set_version.outputs.version }}
33+
steps:
34+
- name: Set VERSION variable
35+
id: set_version
36+
shell: bash
37+
run: |
38+
VERSION="0.4.0-$(date +%Y%m%d)"
39+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
40+
2941
build-demo-ios:
3042
name: build-demo-ios
3143
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
@@ -39,6 +51,8 @@ jobs:
3951
secrets-env: BUILD_CERTIFICATE_BASE64 EXECUTORCH_DEMO_BUILD_PROVISION_PROFILE_BASE64 KEYCHAIN_PASSWORD
4052
upload-artifact: ios-apps
4153
script: |
54+
set -eux
55+
4256
BUILD_TOOL=cmake
4357
4458
.ci/scripts/setup-conda.sh
@@ -57,7 +71,7 @@ jobs:
5771
5872
# Build and test iOS Demo App
5973
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
60-
build/test_ios_ci.sh ${ARTIFACTS_DIR_NAME}
74+
build/test_ios_ci.sh "${ARTIFACTS_DIR_NAME}"
6175
6276
# Upload the test demo app to S3
6377
upload-demo-ios:
@@ -75,6 +89,7 @@ jobs:
7589
shell: bash
7690
working-directory: ${{ runner.temp }}/artifacts/
7791
run: |
92+
set -eux
7893
ls -lah ./
7994
8095
- name: Upload the artifacts to S3
@@ -112,6 +127,7 @@ jobs:
112127

113128
build-frameworks-ios:
114129
name: build-frameworks-ios
130+
needs: set-version
115131
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
116132
with:
117133
runner: macos-latest-xlarge
@@ -121,8 +137,10 @@ jobs:
121137
upload-artifact: executorch-frameworks-ios
122138
timeout: 90
123139
script: |
140+
set -eux
141+
124142
BUILD_TOOL=cmake
125-
VERSION="latest"
143+
VERSION="${{ needs.set-version.outputs.version }}"
126144
FRAMEWORKS=(
127145
"executorch"
128146
"backend_coreml"
@@ -171,7 +189,7 @@ jobs:
171189
172190
upload-frameworks-ios:
173191
runs-on: ubuntu-22.04
174-
needs: build-frameworks-ios
192+
needs: [build-frameworks-ios, set-version]
175193
timeout-minutes: 30
176194
permissions:
177195
id-token: write
@@ -182,11 +200,11 @@ jobs:
182200
with:
183201
python-version: '3.11'
184202
cache: pip
185-
- name: configure aws credentials
186-
uses: aws-actions/[email protected]
187-
with:
188-
role-to-assume: arn:aws:iam::308535385114:role/gha_executorch_upload-frameworks-ios
189-
aws-region: us-east-1
203+
# - name: configure aws credentials
204+
# uses: aws-actions/[email protected]
205+
# with:
206+
# role-to-assume: arn:aws:iam::308535385114:role/gha_executorch_upload-frameworks-ios
207+
# aws-region: us-east-1
190208
- name: Download the artifact
191209
uses: actions/download-artifact@v3
192210
with:
@@ -197,12 +215,12 @@ jobs:
197215
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
198216
shell: bash
199217
run: |
200-
set -eux
201218
echo "UPLOAD_ON_MAIN=1" >> "${GITHUB_ENV}"
202219
- name: Upload the artifact to ossci-ios S3 bucket
203220
shell: bash
204221
run: |
205222
set -eux
223+
VERSION="${{ needs.set-version.outputs.version }}"
206224
207225
pip install awscli==1.32.18
208226
@@ -211,11 +229,45 @@ jobs:
211229
AWS_CMD="aws s3 cp"
212230
fi
213231
232+
declare -A CHECKSUMS
214233
for FILENAME in "${RUNNER_TEMP}"/frameworks-ios/*.zip; do
215234
[ -e "${FILENAME}" ] || continue
216-
shasum -a 256 "${FILENAME}"
235+
FRAMEWORK_NAME=$(basename "${FILENAME}" | sed "s/-${VERSION}.zip//")
236+
CHECKSUM=$(shasum -a 256 "${FILENAME}" | cut -d ' ' -f1)
217237
${AWS_CMD} "${FILENAME}" s3://ossci-ios/executorch/ --acl public-read
238+
CHECKSUMS["${FRAMEWORK_NAME}"]="${CHECKSUM}"
218239
done
240+
echo "${CHECKSUMS[@]}" > "${RUNNER_TEMP}/checksums.txt"
241+
242+
- name: Update SwiftPM
243+
shell: bash
244+
run: |
245+
set -eux
246+
VERSION="${{ needs.set-version.outputs.version }}"
247+
248+
git clone https://github.com/pytorch/executorch.git --branch swiftpm --depth 1 "${RUNNER_TEMP}/executorch"
249+
cd "${RUNNER_TEMP}/executorch"
250+
if git show-ref --verify --quiet refs/heads/swiftpm-${VERSION}; then
251+
git checkout "swiftpm-${VERSION}"
252+
else
253+
git checkout -b "swiftpm-${VERSION}"
254+
fi
255+
256+
cp -f Package.swift.template Package.swift
257+
sed -i "s/__VERSION__/${VERSION}/g" Package.swift
258+
259+
while read -r FRAMEWORK CHECKSUM; do
260+
sed -i "s/__SHA256_${FRAMEWORK}__/${CHECKSUM}/g" Package.swift
261+
done < "${RUNNER_TEMP}/checksums.txt"
262+
263+
if [[ "${UPLOAD_ON_MAIN:-0}" == "1" ]]; then
264+
git add Package.swift
265+
git commit -m "Update Package.swift to version ${VERSION}"
266+
git push origin "swiftpm-${VERSION}"
267+
else
268+
echo "Draft Package.swift:"
269+
cat Package.swift
270+
fi
219271
220272
build-benchmark-app:
221273
name: build-benchmark-app
@@ -281,5 +333,5 @@ jobs:
281333
echo "::group::Build ExecuTorch benchmark app"
282334
mkdir -p extension/benchmark/apple/Benchmark/Models
283335
${CONDA_RUN} --no-capture-output \
284-
build/build_apple_llm_demo.sh ${ARTIFACTS_DIR_NAME}
336+
build/build_apple_llm_demo.sh "${ARTIFACTS_DIR_NAME}"
285337
echo "::endgroup::"

0 commit comments

Comments
 (0)