From ccd0647c9a39eaf34c4419e95f3a2913471302f7 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Mon, 2 Nov 2020 16:41:54 +0000 Subject: [PATCH] Extracting scripts and updating ci flows --- .github/workflows/build-platforms.yml | 21 +-------- .github/workflows/bump-version.yml | 1 + .github/workflows/create-release.yml | 19 ++++---- .github/workflows/rebase-legacy-branch.yml | 28 +----------- SwiftUIPager.xcodeproj/project.pbxproj | 2 +- scripts/build_platforms.sh | 20 +++++++++ scripts/build_xcframework.sh | 51 ++++++++++++++++++++++ scripts/rebase.sh | 25 +++++++++++ 8 files changed, 109 insertions(+), 58 deletions(-) create mode 100755 scripts/build_platforms.sh create mode 100755 scripts/build_xcframework.sh create mode 100755 scripts/rebase.sh diff --git a/.github/workflows/build-platforms.yml b/.github/workflows/build-platforms.yml index cec3d0f..50a7929 100644 --- a/.github/workflows/build-platforms.yml +++ b/.github/workflows/build-platforms.yml @@ -16,23 +16,4 @@ jobs: - uses: actions/checkout@v2 - name: Run script - run: | - gem install xcpretty - - SCHEMES=( SwiftUIPager_Catalyst SwiftUIPager_macOS SwiftUIPager_iOS SwiftUIPager_watchOS SwiftUIPager_tvOS ) - PLATFORMS=( "platform=macOS,variant=Mac Catalyst" "platform=macOS" "generic/platform=iOS" "generic/platform=watchOS" "generic/platform=tvOS" ) - DIR=$(xcodebuild -project SwiftUIPager.xcodeproj -showBuildSettings | grep -m 1 "BUILD_DIR" | grep -oEi "\/.*") - - for i in ${!SCHEMES[@]}; do - xcodebuild clean build -scheme ${SCHEMES[$i]} \ - -project SwiftUIPager.xcodeproj \ - -destination "${PLATFORMS[$i]}" | xcpretty - - COUNT=$(find $DIR -maxdepth 1 -type d | wc -l) - if [ $COUNT -eq 2 ]; then - echo "$(tput setaf 2)Build succeded for target ${SCHEMES[$i]}$(tput sgr0)" - else - echo "$(tput setaf 1)Build failed for target ${SCHEMES[$i]}$(tput sgr0)" - exit 1 - fi - done + run: ./scripts/build_platforms.sh diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index db0c39e..371e7a4 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -28,3 +28,4 @@ jobs: DEFAULT_BUMP: none WITH_V: false PRERELEASE_SUFFIX: beta + VERBOSE: false diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index f8ea1e8..e570248 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -18,9 +18,14 @@ jobs: - uses: actions/checkout@v2 - name: Create XCFramework - uses: fermoya/swift-create-xcframework@v1.5.0 + id: xcframework + run: ./scripts/build_xcframework.sh + + - name: Upload artifact + uses: actions/upload-artifact@v2 with: - platforms: ios, macos, maccatalyst, tvos, watchos + name: SwiftUIPager.xcframework.zip + path: ${{ steps.xcframework.outputs.path }} create_release: name: Create Release and Upload artfifacts @@ -34,11 +39,7 @@ jobs: run: | name=VERSION::${GITHUB_REF/refs\/tags\//} echo "Tag: $name" - if [[ "$name" == *"beta"* ]]; then - prerelease=true - else - prerelease=false - fi + if [[ "$name" == *"beta"* ]]; then prerelease=true; else prerelease=false; fi echo ::set-output name=prerelease::$prerelease - name: Create Release @@ -57,10 +58,8 @@ jobs: - name: Download artifact uses: actions/download-artifact@v2 with: - name: SwiftUIPager.zip + name: SwiftUIPager.xcframework.zip path: ./ - - - run: mv SwiftUIPager.zip SwiftUIPager.xcframework.zip - name: Upload Release Asset id: upload-release-asset diff --git a/.github/workflows/rebase-legacy-branch.yml b/.github/workflows/rebase-legacy-branch.yml index b4fe0f5..a29dbad 100644 --- a/.github/workflows/rebase-legacy-branch.yml +++ b/.github/workflows/rebase-legacy-branch.yml @@ -3,7 +3,6 @@ name: Rebase branch legacy-projects on: - # Trigger the workflow on push pull request or manually push: branches: [ develop ] @@ -22,29 +21,4 @@ jobs: USER_EMAIL: fmdr.ct@gmail.com OUTDATED_BRANCH: legacy-projects BASE_BRANCH: develop - run: | - FOLDER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2) - - git clone https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git - cd $FOLDER - git checkout $OUTDATED_BRANCH - - echo Adding origin as $GITHUB_REPOSITORY - git remote set-url origin https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git - git config --global user.email "$USER_EMAIL" - git config --global user.name "$USER_NAME" - - git fetch origin $BASE_BRANCH - - echo git pull --rebase origin $OUTDATED_BRANCH - git pull --rebase origin $OUTDATED_BRANCH - - echo Rebasing $BASE_BRANCH onto $OUTDATED_BRANCH - echo git rebase origin/$BASE_BRANCH - git rebase origin/$BASE_BRANCH - - echo git push --force-with-lease origin $OUTDATED_BRANCH - git push --force-with-lease origin $OUTDATED_BRANCH - - cd .. - rm -rf $FOLDER + run: ./scripts/rebase.sh diff --git a/SwiftUIPager.xcodeproj/project.pbxproj b/SwiftUIPager.xcodeproj/project.pbxproj index 88423d1..e135f61 100644 --- a/SwiftUIPager.xcodeproj/project.pbxproj +++ b/SwiftUIPager.xcodeproj/project.pbxproj @@ -548,7 +548,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "rm -rd \"SwiftUIPager.xcframework\"\nxcodebuild archive -scheme SwiftUIPager_macOS \\\n -destination \"platform=macOS\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.macOS.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_iOS \\\n -destination \"generic/platform=iOS\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.iOS.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_iOS \\\n -destination \"generic/platform=iOS Simulator\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.iOS-simulator.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_Catalyst \\\n -destination \"platform=macOS,variant=Mac Catalyst\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.macCatalyst.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_watchOS \\\n -destination \"generic/platform=watchOS\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager//SwiftUIPager.watchOS.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_watchOS \\\n -destination \"generic/platform=watchOS Simulator\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager//SwiftUIPager.watchOS-simulator.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_tvOS \\\n -destination \"generic/platform=tvOS\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.tvOS.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild archive -scheme SwiftUIPager_tvOS \\\n -destination \"generic/platform=tvOS Simulator\" \\\n -archivePath \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.tvOS-simulator.xcarchive\" \\\n SKIP_INSTALL=NO \\\n BUILD_LIBRARY_FOR_DISTRIBUTION=YES\n\nxcodebuild -create-xcframework \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.macOS.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.iOS.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.iOS-simulator.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.macCatalyst.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.watchOS.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.watchOS-simulator.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.tvOS.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -framework \"$TEMP_DIR/SwiftUIPager/SwiftUIPager.tvOS-simulator.xcarchive/Products/Library/Frameworks/SwiftUIPager.framework\" \\\n -output \"SwiftUIPager.xcframework\"\n"; + shellScript = "./scripts/build_xcframework.sh\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/scripts/build_platforms.sh b/scripts/build_platforms.sh new file mode 100755 index 0000000..a632413 --- /dev/null +++ b/scripts/build_platforms.sh @@ -0,0 +1,20 @@ +gem install xcpretty + +SCHEMES=( SwiftUIPager_Catalyst SwiftUIPager_macOS SwiftUIPager_iOS SwiftUIPager_watchOS SwiftUIPager_tvOS ) +PLATFORMS=( "platform=macOS,variant=Mac Catalyst" "platform=macOS" "generic/platform=iOS" "generic/platform=watchOS" "generic/platform=tvOS" ) +DIR=$(xcodebuild -project SwiftUIPager.xcodeproj -showBuildSettings | grep -m 1 "BUILD_DIR" | grep -oEi "\/.*") +rm -rd $DIR + +for i in ${!SCHEMES[@]}; do + xcodebuild clean build -scheme ${SCHEMES[$i]} \ + -project SwiftUIPager.xcodeproj \ + -destination "${PLATFORMS[$i]}" | xcpretty + + COUNT=$(find $DIR -maxdepth 1 -type d | wc -l) + if [ $COUNT -eq 2 ]; then + echo "$(tput setaf 2)Build succeded for target ${SCHEMES[$i]}$(tput sgr0)" + else + echo "$(tput setaf 1)Build failed for target ${SCHEMES[$i]}$(tput sgr0)" + exit 1 + fi +done \ No newline at end of file diff --git a/scripts/build_xcframework.sh b/scripts/build_xcframework.sh new file mode 100755 index 0000000..a781d05 --- /dev/null +++ b/scripts/build_xcframework.sh @@ -0,0 +1,51 @@ +gem install xcpretty + +LIB_NAME="SwiftUIPager" +PROJ_PATH="$LIB_NAME.xcodeproj" +BUILD_PATH=".build" +FRAMEWORKS_PATH="$BUILD_PATH/frameworks" +XCFRAMEWORK_PATH="$BUILD_PATH/$LIB_NAME.xcframework" +XCFRAMEWORK_ZIP_PATH="$XCFRAMEWORK_PATH.zip" +rm $XCFRAMEWORK_ZIP_PATH + +SCHEMES=( SwiftUIPager_Catalyst SwiftUIPager_macOS SwiftUIPager_iOS SwiftUIPager_watchOS SwiftUIPager_tvOS ) +PLATFORMS=( + "platform=macOS,variant=Mac Catalyst" + "platform=macOS" + "generic/platform=iOS;generic/platform=iOS Simulator" + "generic/platform=watchOS;generic/platform=watchOS Simulator" + "generic/platform=tvOS;generic/platform=tvOS Simulator" +) +ARCHIVES=( + "$LIB_NAME.macCatalyst.xcarchive" + "$LIB_NAME.macos.xcarchive" + "$LIB_NAME.iOS.xcarchive;SwiftUIPager.iOS-simulator.xcarchive" + "$LIB_NAME.watchOS.xcarchive;SwiftUIPager.watchOS-simulator.xcarchive" + "$LIB_NAME.tvOS.xcarchive;SwiftUIPager.tvOS-simulator.xcarchive" +) + +COMMAND="xcodebuild -create-xcframework " +xcodebuild clean -project $PROJ_PATH +for i in ${!SCHEMES[@]}; do + IFS=";" read -r -a PLATFORM <<< "${PLATFORMS[i]}" + IFS=";" read -r -a ARCHIVE <<< "${ARCHIVES[i]}" + + for j in ${!PLATFORM[@]}; do + ARCHIVE_PATH="$FRAMEWORKS_PATH/${ARCHIVE[$j]}" + xcodebuild archive -scheme ${SCHEMES[$i]} \ + -project $PROJ_PATH \ + -destination "${PLATFORM[$j]}" \ + -archivePath $ARCHIVE_PATH \ + SKIP_INSTALL=NO \ + BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcpretty + + COMMAND="$COMMAND -framework $ARCHIVE_PATH/Products/Library/Frameworks/$LIB_NAME.framework" + done + +done +COMMAND="$COMMAND -output $XCFRAMEWORK_PATH" +$COMMAND | xcpretty +rm -rd $FRAMEWORKS_PATH +zip -r $XCFRAMEWORK_ZIP_PATH $XCFRAMEWORK_PATH +rm -rd $XCFRAMEWORK_PATH +echo ::set-output name=path::$XCFRAMEWORK_ZIP_PATH \ No newline at end of file diff --git a/scripts/rebase.sh b/scripts/rebase.sh new file mode 100755 index 0000000..a934e98 --- /dev/null +++ b/scripts/rebase.sh @@ -0,0 +1,25 @@ +FOLDER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2) + +git clone https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git +cd $FOLDER +git checkout $OUTDATED_BRANCH + +echo Adding origin as $GITHUB_REPOSITORY +git remote set-url origin https://x-access-token:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git +git config --global user.email "$USER_EMAIL" +git config --global user.name "$USER_NAME" + +git fetch origin $BASE_BRANCH + +echo git pull --rebase origin $OUTDATED_BRANCH +git pull --rebase origin $OUTDATED_BRANCH + +echo Rebasing $BASE_BRANCH onto $OUTDATED_BRANCH +echo git rebase origin/$BASE_BRANCH +git rebase origin/$BASE_BRANCH + +echo git push --force-with-lease origin $OUTDATED_BRANCH +git push --force-with-lease origin $OUTDATED_BRANCH + +cd .. +rm -rf $FOLDER \ No newline at end of file