Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPM validation in each PR #2181

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion azure_pipelines/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,62 @@ jobs:
testResultsFiles: '$(Agent.BuildDirectory)/s/build/reports/*'
diegojerezba marked this conversation as resolved.
Show resolved Hide resolved
failTaskOnFailedTests: true
testRunTitle: 'Test Run - $(target)'


- job: 'Validate_SPM_Integration'
displayName: Validate SPM Integration
pool:
vmImage: 'macOS-13'
timeOutInMinutes: 15
workspace:
clean: all

steps:

- checkout: self
clean: true
submodules: true
fetchDepth: 1
persistCredentials: true
nilo-ms marked this conversation as resolved.
Show resolved Hide resolved
path: s

- script: |
/bin/bash -c "sudo xcode-select -s /Applications/Xcode_14.3.app"
displayName: 'Switch to use Xcode 14.3'

- task: Bash@3
displayName: Set variable BRANCH_NAME to a temporary branch
inputs:
targetType: 'inline'
script: |
BRANCH_NAME_LOCAL="$(Build.SourceBranchName)-temp"
echo "##vso[task.setvariable variable=BRANCH_NAME]${BRANCH_NAME_LOCAL}"

- task: Bash@3
displayName: Checkout to temporary branch
inputs:
targetType: 'inline'
script: |
git checkout -b "${BRANCH_NAME}"

- task: Bash@3
displayName: Run SPM integration test script
inputs:
targetType: 'inline'
script: |
sh spm-integration-test.sh "${BRANCH_NAME}"
continueOnError: false

- task: Bash@3
condition: always()
displayName: Cleanup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add condition: always() for this task so that it always runs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, thank you.

inputs:
targetType: 'inline'
script:
cd ../..
rm -rf "$SAMPLE_APP_TEMP_DIR" archive framework MSAL.zip
git checkout -- .
git fetch --quiet
git switch "$(Build.SourceBranchName)"
git branch -D "$BRANCH_NAME"
git push origin --delete "$BRANCH_NAME"

59 changes: 59 additions & 0 deletions spm-integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BRANCH_NAME="$1"
SAMPLE_APP_TEMP_DIR="NativeAuthSampleAppTemp"
current_date=$(date +"%Y-%m-%d %H:%M:%S")

set -e

# Build framework

echo "Building framework"

xcodebuild -sdk iphonesimulator -configuration Release -workspace MSAL.xcworkspace -scheme "MSAL (iOS Framework)" archive SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -archivePath archive/iOSSimulator CODE_SIGNING_ALLOWED=NO -quiet > build.log 2>&1
nilo-ms marked this conversation as resolved.
Show resolved Hide resolved
xcodebuild -sdk iphoneos -configuration Release -workspace MSAL.xcworkspace -scheme "MSAL (iOS Framework)" archive SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -archivePath archive/iOS CODE_SIGNING_ALLOWED=NO -quiet > build.log 2>&1
xcodebuild -sdk macosx -configuration Release -workspace MSAL.xcworkspace -scheme "MSAL (Mac Framework)" archive SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES -archivePath archive/macOS CODE_SIGNING_ALLOWED=NO -quiet > build.log 2>&1

xcodebuild -create-xcframework -framework archive/iOSSimulator.xcarchive/Products/Library/Frameworks/MSAL.framework -framework archive/iOS.xcarchive/Products/Library/Frameworks/MSAL.framework -framework archive/macOS.xcarchive/Products/Library/Frameworks/MSAL.framework -output framework/MSAL.xcframework > build.log 2>&1

echo "Creating MSAL.zip"
zip -r MSAL.zip framework/MSAL.xcframework -y -v

echo "Calculating checksum"
CHECKSUM=$(swift package compute-checksum MSAL.zip)
if [ -z "$CHECKSUM" ]; then
echo "** Checksum could not be obtained **"
exit 1
fi

echo "Updating Package.swift"

NEW_URL="https://github.com/AzureAD/microsoft-authentication-library-for-objc/raw/$BRANCH_NAME/MSAL.zip"

sed -i '' "s#url: \"[^\"]*\"#url: \"$NEW_URL\"#" Package.swift
sed -i '' "s#checksum: \"[^\"]*\"#checksum: \"$CHECKSUM\"#" Package.swift

echo "Pushing MSAL.zip and Package.swift to $BRANCH_NAME"

git add MSAL.zip Package.swift

git commit -m "Publish temporary Swift Package $current_date"
git push -f origin "$BRANCH_NAME"

# Download Sample App

echo "Downloading and updating Sample App to use temporary Swift Package"

mkdir -p "$SAMPLE_APP_TEMP_DIR"
cd "$SAMPLE_APP_TEMP_DIR"

git clone https://github.com/Azure-Samples/ms-identity-ciam-native-auth-ios-sample.git
cd ms-identity-ciam-native-auth-ios-sample

sed -i '' 's#kind = upToNextMinorVersion;#kind = branch;#' NativeAuthSampleApp.xcodeproj/project.pbxproj
sed -i '' "s#minimumVersion = [0-9.]*;#branch = $BRANCH_NAME;#" NativeAuthSampleApp.xcodeproj/project.pbxproj

rm -f NativeAuthSampleApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

echo "Running the Sample App with the temporary Swift Package"

xcodebuild -resolvePackageDependencies
xcodebuild -scheme NativeAuthSampleApp -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14,OS=16.4' clean build