Skip to content

Commit

Permalink
Merge pull request #147 from fermoya/feat/extract-ci-scripts
Browse files Browse the repository at this point in the history
Extracting scripts and updating ci flows
  • Loading branch information
fermoya authored Nov 2, 2020
2 parents 0fc02a9 + ccd0647 commit 7df2bc9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 58 deletions.
21 changes: 1 addition & 20 deletions .github/workflows/build-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ jobs:
DEFAULT_BUMP: none
WITH_V: false
PRERELEASE_SUFFIX: beta
VERBOSE: false
19 changes: 9 additions & 10 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ jobs:
- uses: actions/checkout@v2

- name: Create XCFramework
uses: fermoya/[email protected]
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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 1 addition & 27 deletions .github/workflows/rebase-legacy-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
name: Rebase branch legacy-projects

on:
# Trigger the workflow on push pull request or manually
push:
branches: [ develop ]

Expand All @@ -22,29 +21,4 @@ jobs:
USER_EMAIL: [email protected]
OUTDATED_BRANCH: legacy-projects
BASE_BRANCH: develop
run: |
FOLDER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)
git clone https://x-access-token:[email protected]/$GITHUB_REPOSITORY.git
cd $FOLDER
git checkout $OUTDATED_BRANCH
echo Adding origin as $GITHUB_REPOSITORY
git remote set-url origin https://x-access-token:[email protected]/$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
2 changes: 1 addition & 1 deletion SwiftUIPager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
20 changes: 20 additions & 0 deletions scripts/build_platforms.sh
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions scripts/build_xcframework.sh
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions scripts/rebase.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7df2bc9

Please sign in to comment.