Skip to content

Commit

Permalink
Convert the iOS build script into github workflow steps (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
muzuke authored Nov 20, 2024
1 parent 6a47b62 commit 7c45fb4
Showing 1 changed file with 86 additions and 23 deletions.
109 changes: 86 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,103 @@ env:
jobs:
build:
runs-on: macos-15-xlarge
env:
RUST_TOOLCHAIN: nightly-2024-01-11
RUST_COMPONENTS: "rust-std"
steps:
- uses: RDXWorks-actions/checkout@main
with:
fetch-depth: 0

- uses: RDXWorks-actions/setup-xcode@master
with:
xcode-version: "16.0.0"

- name: Install Rust Toolchain for aarch64-apple-darwin
uses: RDXWorks-actions/toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: ${{ env.RUST_COMPONENTS }}
target: aarch64-apple-darwin

- name: Install Rust Toolchain for aarch64-apple-ios
uses: RDXWorks-actions/toolchain@master
uses: RDXWorks-actions/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: ${{ env.RUST_COMPONENTS }}
target: aarch64-apple-ios
toolchain: nightly-2024-01-11
components: rust-std
target: aarch64-apple-ios,aarch64-apple-darwin,aarch64-apple-ios-sim

- name: Install Rust Toolchain for aarch64-apple-ios-sim
uses: RDXWorks-actions/toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: ${{ env.RUST_COMPONENTS }}
target: aarch64-apple-ios-sim
- name: Compute release tag
id: tags
run: |
set -euo pipefail
LAST_TAG=`git tag --sort=creatordate | tail -1`
NEXT_TAG=$(echo ${LAST_TAG} | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}')
echo "NEXT_TAG=$NEXT_TAG" >> "$GITHUB_OUTPUT"
echo "LAST_TAG=$LAST_TAG" >> "$GITHUB_OUTPUT"
echo "🚒 NEXT_TAG: $NEXT_TAG"
echo "🚒 LAST_TAG: $LAST_TAG"
- name: Build artifacts
id: build
run: |
set -euo pipefail
rustup target add aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim
echo "🚒 Switch 'useLocalFramework' to 'false' in Package.swift for release"
sed -i '' 's/let useLocalFramework = true/let useLocalFramework = false/' Package.swift
# output is: "<CHKSUM>;<$XCFRAME_ZIP_PATH>"
OUTPUT_OF_BUILD=$(bash scripts/ios/build-sargon.sh --release-tag "$NEXT_TAG" | tail -n 1) || exit $?
if [[ "$OUTPUT_OF_BUILD" == "BUILT_WITHOUT_RELEASE" ]]; then
echo "Error, failed to build, did you forget to pass '--release' to build script? Otherwise check if build-sargon.sh has recently been changed (to something incorrect...)"
exit 1;
fi
CHECKSUM=`echo "$OUTPUT_OF_BUILD" | cut -d ";" -f 1` || exit $?
XCFRAME_ZIP_PATH=`echo "$OUTPUT_OF_BUILD" | cut -d ";" -f 2` || exit $?
- name: Run iOS build script
echo "🚒 CHECKSUM: $CHECKSUM"
echo "🚒 XCFRAME_ZIP_PATH: $XCFRAME_ZIP_PATH"
echo "🚒 Ensuring Sargon build for release - that it will work for e.g. iOS wallet to archive."
sed -i '' 's/let useLocalFramework = false/let useLocalFramework = true/' Package.swift
swift build -c release || exit $?
echo "🚒 Swift Sargon builds for release βœ…"
echo "XCFRAME_ZIP_PATH=$XCFRAME_ZIP_PATH" >> "$GITHUB_OUTPUT"
env:
NEXT_TAG: ${{ steps.tags.outputs.NEXT_TAG }}

- name: Push release tag
if: github.ref == 'refs/heads/main'
run: |
set -euo pipefail
# We have .gitigored Sargon.swift because we dont need it in git history, but we
# need it for this release, so we must FORCE add it (since it is ignored).
echo "🚒 Staging changed files"
git add --force Package.swift apple/Sources/UniFFI/Sargon.swift
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
echo "🚒 Git commiting changes"
git status
git commit -m "Release of '$NEXT_TAG'" \
-m "Updated Package.swift with new checksum and path to zip on Github, and maybe apple/Sources/UniFFI/Sargon.swift." \
-m "This commit is not merged into main branch (and need not be)." \
--no-verify
echo "🚒 🏷️ πŸ“‘ Pushing tag: $NEXT_TAG, but only tag, not commit."
git push origin $NEXT_TAG
env:
NEXT_TAG: ${{ steps.tags.outputs.NEXT_TAG }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create release
if: github.ref == 'refs/heads/main'
run: |
rustup target add aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim
sh ./scripts/ios/release.sh
# This MUST match whatever you we have declared in Package.swift
SWIFT_SARGON_BINARY_ASSET_NAME="libsargon-rs.xcframework.zip"
GH_RELEASE_TITLE="v$NEXT_TAG"
gh release create $NEXT_TAG '$XCFRAME_ZIP_PATH#$SWIFT_SARGON_BINARY_ASSET_NAME' --generate-notes --notes-start-tag $LAST_TAG --title '$GH_RELEASE_TITLE'
env:
LAST_TAG: ${{ steps.tags.outputs.LAST_TAG }}
NEXT_TAG: ${{ steps.tags.outputs.NEXT_TAG }}
XCFRAME_ZIP_PATH: ${{ steps.build.outputs.XCFRAME_ZIP_PATH }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 7c45fb4

Please sign in to comment.