diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10c588e22..447ccc136 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: ${{ secrets.APP_STORE_CONNECT_API_KEY }} - name: Archive the demo - run: make archive-demo-${{ matrix.platform }} + run: make archive-demo-${{ matrix.platform }} MODE="--non-interactive" env: TEAM_ID: ${{ secrets.TEAM_ID }} KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} diff --git a/.github/workflows/nightlies.yml b/.github/workflows/nightlies.yml index 3eda4af04..bde9bdaa9 100644 --- a/.github/workflows/nightlies.yml +++ b/.github/workflows/nightlies.yml @@ -34,7 +34,8 @@ jobs: - name: Deliver the demo run: | - make deliver-demo-nightly-${{ matrix.platform }} + make deliver-demo-nightly-${{ matrix.platform }} \ + MODE="--non-interactive" env: TEAM_ID: ${{ secrets.TEAM_ID }} KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 418c0e4be..acdff5d03 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -34,7 +34,8 @@ jobs: - name: Deliver the demo run: | - make deliver-demo-release-${{ matrix.platform }} + make deliver-demo-release-${{ matrix.platform }} \ + MODE="--non-interactive" env: TEAM_ID: ${{ secrets.TEAM_ID }} KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} diff --git a/Makefile b/Makefile index 1f7b95cce..210958f6e 100644 --- a/Makefile +++ b/Makefile @@ -3,167 +3,105 @@ .PHONY: all all: help -.PHONY: install-pkgx -install-pkgx: - @echo "Installing pkgx..." - @curl -Ssf https://pkgx.sh | sh &> /dev/null - @echo "... done.\n" - -.PHONY: install-bundler -install-bundler: - @echo "Installing bundler..." - @pkgx bundle config set path '.bundle' - @pkgx bundle install - @echo "... done.\n" - -.PHONY: fastlane -fastlane: install-pkgx install-bundler - @pkgx bundle exec fastlane .PHONY: archive-demo-ios -archive-demo-ios: install-pkgx install-bundler - @pkgx bundle exec fastlane archive_demo_ios +archive-demo-ios: + @Scripts/archive-demo.sh $(MODE) --platform ios .PHONY: archive-demo-tvos -archive-demo-tvos: install-pkgx install-bundler - @pkgx bundle exec fastlane archive_demo_tvos +archive-demo-tvos: + @Scripts/archive-demo.sh $(MODE) --platform tvos .PHONY: deliver-demo-nightly-ios -deliver-demo-nightly-ios: install-pkgx install-bundler - @echo "Delivering demo nightly build for iOS..." - @pkgx +magick +rsvg-convert bundle exec fastlane deliver_demo_nightly_ios - @echo "... done.\n" +deliver-demo-nightly-ios: + @Scripts/deliver-demo.sh $(MODE) --platform ios --configuration nightly .PHONY: deliver-demo-nightly-tvos -deliver-demo-nightly-tvos: install-pkgx install-bundler - @echo "Delivering demo nightly build for tvOS..." - @pkgx +magick +rsvg-convert bundle exec fastlane deliver_demo_nightly_tvos - @echo "... done.\n" +deliver-demo-nightly-tvos: + @Scripts/deliver-demo.sh $(MODE) --platform tvos --configuration nightly .PHONY: deliver-demo-release-ios -deliver-demo-release-ios: install-pkgx install-bundler - @echo "Delivering demo release build for iOS..." - @pkgx bundle exec fastlane deliver_demo_release_ios - @echo "... done.\n" +deliver-demo-release-ios: + @Scripts/deliver-demo.sh $(MODE) --platform ios --configuration release .PHONY: deliver-demo-release-tvos install-bundler -deliver-demo-release-tvos: install-pkgx - @echo "Delivering demo release build for tvOS..." - @pkgx bundle exec fastlane deliver_demo_release_tvos - @echo "... done.\n" +deliver-demo-release-tvos: + @Scripts/deliver-demo.sh $(MODE) --platform tvos --configuration release .PHONY: test-streams-start -test-streams-start: install-pkgx - @echo "Starting test streams" +test-streams-start: @Scripts/test-streams.sh -s - @echo "... done.\n" .PHONY: test-streams-stop -test-streams-stop: install-pkgx - @echo "Stopping test streams" +test-streams-stop: @Scripts/test-streams.sh -k - @echo "... done.\n" .PHONY: test-ios -test-ios: install-pkgx install-bundler - @echo "Running unit tests..." - @Scripts/test-streams.sh -s - @pkgx bundle exec fastlane test_ios - @Scripts/test-streams.sh -k - @echo "... done.\n" +test-ios: + @Scripts/test.sh --platform ios .PHONY: test-tvos -test-tvos: install-pkgx install-bundler - @echo "Running unit tests..." - @Scripts/test-streams.sh -s - @pkgx bundle exec fastlane test_tvos - @Scripts/test-streams.sh -k - @echo "... done.\n" +test-tvos: + @Scripts/test.sh --platform tvos .PHONY: check-quality -check-quality: install-pkgx - @echo "Checking quality..." +check-quality: @Scripts/check-quality.sh - @echo "... done.\n" .PHONY: fix-quality -fix-quality: install-pkgx - @echo "Fixing quality..." +fix-quality: @Scripts/fix-quality.sh - @echo "... done.\n" .PHONY: git-hook-install git-hook-install: - @echo "Installing git hooks..." - @git config core.hooksPath hooks - @echo "... done.\n" + @Scripts/git-hooks.sh --install .PHONY: git-hook-uninstall git-hook-uninstall: - @echo "Uninstalling git hooks..." - @git config --unset core.hooksPath - @echo "... done.\n" - -.PHONY: spm-reload -spm-reload: - @echo "Remove dependencies..." - @swift package reset - @echo "... done.\n" - @echo "Reload dependencies..." - @swift package update - @echo "... done.\n" + @Scripts/git-hooks.sh --uninstall .PHONY: clean-imports clean-imports: - @echo "Cleaning imports..." - @mkdir -p .build - @xcodebuild -scheme Pillarbox -destination generic/platform=ios > ./.build/xcodebuild.log - @pkgx swiftlint analyze --fix --compiler-log-path ./.build/xcodebuild.log - @xcodebuild -scheme Pillarbox-demo -project ./Demo/Pillarbox-demo.xcodeproj -destination generic/platform=iOS > ./.build/xcodebuild.log - @pkgx swiftlint analyze --fix --compiler-log-path ./.build/xcodebuild.log - @echo "... done.\n" + @Scripts/clean-imports.sh .PHONY: find-dead-code find-dead-code: - @echo "Start checking dead code..." - @mkdir -p .build - @xcodebuild -scheme Pillarbox -destination generic/platform=iOS -derivedDataPath ./.build/derived-data clean build &> /dev/null - @pkgx periphery scan --retain-public --skip-build --index-store-path ./.build/derived-data/Index.noindex/DataStore/ - @xcodebuild -scheme Pillarbox-demo -project ./Demo/Pillarbox-demo.xcodeproj -destination generic/platform=iOS -derivedDataPath ./.build/derived-data clean build &> /dev/null - @pkgx periphery scan --project ./Demo/Pillarbox-demo.xcodeproj --schemes Pillarbox-demo --targets Pillarbox-demo --skip-build --index-store-path ./.build/derived-data/Index.noindex/DataStore/ - @echo "... done.\n" + @Scripts/find-dead-code.sh .PHONY: help help: - @echo "The following targets are available:" - @echo "" - @echo " all Default target" - @echo "" - @echo " fastlane Run fastlane" - @echo "" - @echo " archive-demo-ios Archive the iOS demo (for all configurations)" - @echo " archive-demo-tvos Archive the tvOS demo (for all configurations)" - @echo "" - @echo " deliver-demo-nightly-ios Deliver a demo nightly build for iOS" - @echo " deliver-demo-nightly-tvos Deliver a demo nightly build for tvOS" - @echo "" - @echo " deliver-demo-release-ios Deliver a demo release build for iOS" - @echo " deliver-demo-release-tvos Deliver a demo release build for tvOS" - @echo "" - @echo " test-streams-start Start servicing test streams" - @echo " test-streams-stop Stop servicing test streams" - @echo "" - @echo " test-ios Build and run unit tests for iOS" - @echo " test-tvos Build and run unit tests for tvOS" - @echo "" - @echo " check-quality Run quality checks" - @echo " fix-quality Fix quality automatically (if possible)" - @echo "" - @echo " git-hook-install Use hooks located in ./hooks" - @echo " git-hook-uninstall Use default hooks located in .git/hooks" - @echo "" - @echo " spm-reload Reload SPM dependencies" - @echo " clean-imports Remove useless imports from the project" - @echo " find-dead-code Find dead code" - @echo "" - @echo " help Display this help message" + @echo "Available targets:" + @echo + @echo "Default:" + @echo " all Default target" + @echo + @echo "Archive:" + @echo " archive-demo-ios Archive iOS demo [MODE=\"--non-interactive\"]" + @echo " archive-demo-tvos Archive tvOS demo [MODE=\"--non-interactive\"]" + @echo + @echo "Deliver:" + @echo " deliver-demo-nightly-ios Deliver nightly iOS demo build [MODE=\"--non-interactive\"]" + @echo " deliver-demo-nightly-tvos Deliver nightly tvOS demo build [MODE=\"--non-interactive\"]" + @echo " deliver-demo-release-ios Deliver release iOS demo build [MODE=\"--non-interactive\"]" + @echo " deliver-demo-release-tvos Deliver release tvOS demo build [MODE=\"--non-interactive\"]" + @echo + @echo "Test:" + @echo " test-streams-start Start test streams" + @echo " test-streams-stop Stop test streams" + @echo " test-ios Build & run iOS unit tests" + @echo " test-tvos Build & run tvOS unit tests" + @echo + @echo "Quality:" + @echo " check-quality Run quality checks" + @echo " fix-quality Automatically fix quality issues" + @echo + @echo "Git Hooks:" + @echo " git-hook-install Install custom hooks from ./hooks" + @echo " git-hook-uninstall Revert to default hooks" + @echo + @echo "Utilities:" + @echo " clean-imports Remove unused imports" + @echo " find-dead-code Locate dead code" + @echo + @echo "Other:" + @echo " help Show this help message" diff --git a/Scripts/archive-demo.sh b/Scripts/archive-demo.sh new file mode 100755 index 000000000..505405fdf --- /dev/null +++ b/Scripts/archive-demo.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "[!] Usage: $0 [--non-interactive] --platform [ios | tvos]" + echo + echo " Params:" + echo " --non-interactive: (Optional) Avoid setting the ENV variables interactively (interactive by default)." + echo " --platform: (Required) Platform for which to archive the demo." + echo + exit 1 +} + +PLATFORM="" +IS_INTERACTIVE=true + +if [[ $1 == "--non-interactive" && $2 == "--platform" ]]; then + IS_INTERACTIVE=false + PLATFORM="$3" +elif [[ $1 == "--platform" ]]; then + PLATFORM="$2" +else + usage +fi + +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +echo -e "Archiving $PLATFORM demo..." + +if [[ $IS_INTERACTIVE == true ]]; then + source Scripts/set-apple-api-env-interactively.sh + Scripts/configure-environment.sh "$APPLE_API_KEY_BASE64" +fi + +Scripts/install-pkgx.sh +Scripts/install-bundler.sh + +pkgx bundle exec fastlane "archive_demo_$PLATFORM" +echo "... done." \ No newline at end of file diff --git a/Scripts/check-quality.sh b/Scripts/check-quality.sh index e31a467b5..e44b19734 100755 --- a/Scripts/check-quality.sh +++ b/Scripts/check-quality.sh @@ -2,20 +2,31 @@ set -e +echo "Checking quality..." + +Scripts/install-pkgx.sh + eval "$(pkgx --shellcode)" -env +swiftlint +rubocop +shellcheck +markdownlint +yamllint echo "... checking Swift code..." -if [ $# -eq 0 ]; then - swiftlint --quiet --strict -elif [[ "$1" == "only-changes" ]]; then +env +swiftlint +if [[ "$1" == "--only-changes" ]]; then git diff --staged --name-only | grep ".swift$" | xargs swiftlint lint --quiet --strict +else + swiftlint --quiet --strict fi + echo "... checking Ruby scripts..." -rubocop --format quiet +rm -rf ~/.pkgx/sqlite.org # Avoid https://github.com/pkgxdev/pkgx/issues/1059 +pkgx rubocop --format quiet + echo "... checking Shell scripts..." -shellcheck Scripts/*.sh hooks/* Artifacts/**/*.sh +pkgx shellcheck Scripts/*.sh hooks/* Artifacts/**/*.sh + echo "... checking Markdown documentation..." -markdownlint --ignore fastlane . +pkgx markdownlint --ignore fastlane . + echo "... checking YAML files..." -yamllint .*.yml .github +pkgx yamllint .*.yml .github + +echo "... done." \ No newline at end of file diff --git a/Scripts/clean-imports.sh b/Scripts/clean-imports.sh new file mode 100755 index 000000000..51d7fcf8b --- /dev/null +++ b/Scripts/clean-imports.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "Cleaning imports..." +mkdir -p .build +xcodebuild -scheme Pillarbox -destination generic/platform=ios > ./.build/xcodebuild.log +pkgx swiftlint analyze --fix --compiler-log-path ./.build/xcodebuild.log +xcodebuild -scheme Pillarbox-demo -project ./Demo/Pillarbox-demo.xcodeproj -destination generic/platform=iOS > ./.build/xcodebuild.log +pkgx swiftlint analyze --fix --compiler-log-path ./.build/xcodebuild.log +echo "... done." \ No newline at end of file diff --git a/Scripts/deliver-demo.sh b/Scripts/deliver-demo.sh new file mode 100755 index 000000000..5908fd18d --- /dev/null +++ b/Scripts/deliver-demo.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "[!] Usage: $0 [--non-interactive] --platform [ios | tvos] --configuration [nightly | release]" + echo + echo " Params:" + echo " --non-interactive: (Optional) Avoid setting the ENV variables interactively (interactive by default)." + echo " --platform: (Required) Platform for which to deliver the demo." + echo " --configuration: (Required) Configuration for which to deliver the demo." + echo + exit 1 +} + +PLATFORM="" +CONFIGURATION="" +IS_INTERACTIVE=true + +if [[ $1 == "--non-interactive" && $2 == "--platform" && $4 == "--configuration" ]]; then + IS_INTERACTIVE=false + PLATFORM="$3" + CONFIGURATION="$5" +elif [[ $1 == "--platform" && $3 == "--configuration" ]]; then + PLATFORM="$2" + CONFIGURATION="$4" +else + usage +fi + +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +if [[ $CONFIGURATION != "nightly" && $CONFIGURATION != "release" ]]; then + usage +fi + +echo -e "Delivering demo $CONFIGURATION build for $PLATFORM..." + +if [[ $IS_INTERACTIVE == true ]]; then + source Scripts/set-apple-api-env-interactively.sh + Scripts/configure-environment.sh "$APPLE_API_KEY_BASE64" +fi + +Scripts/install-pkgx.sh +Scripts/install-bundler.sh + +eval "$(pkgx --shellcode)" +env +bundle +magick +rsvg-convert + +bundle exec fastlane "deliver_demo_${CONFIGURATION}_${PLATFORM}" +echo "... done." \ No newline at end of file diff --git a/Scripts/find-dead-code.sh b/Scripts/find-dead-code.sh new file mode 100755 index 000000000..d349300f7 --- /dev/null +++ b/Scripts/find-dead-code.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "Start checking dead code..." +mkdir -p .build +xcodebuild -scheme Pillarbox -destination generic/platform=iOS -derivedDataPath ./.build/derived-data clean build &> /dev/null +pkgx periphery scan --retain-public --skip-build --index-store-path ./.build/derived-data/Index.noindex/DataStore/ +xcodebuild -scheme Pillarbox-demo -project ./Demo/Pillarbox-demo.xcodeproj -destination generic/platform=iOS -derivedDataPath ./.build/derived-data clean build &> /dev/null +pkgx periphery scan --project ./Demo/Pillarbox-demo.xcodeproj --schemes Pillarbox-demo --targets Pillarbox-demo --skip-build --index-store-path ./.build/derived-data/Index.noindex/DataStore/ +echo "... done." \ No newline at end of file diff --git a/Scripts/fix-quality.sh b/Scripts/fix-quality.sh index 270647ef5..024c35375 100755 --- a/Scripts/fix-quality.sh +++ b/Scripts/fix-quality.sh @@ -2,7 +2,11 @@ set -e +Scripts/install-pkgx.sh + eval "$(pkgx --shellcode)" env +swiftlint +echo "Fixing quality..." swiftlint --fix && swiftlint +echo "... done." \ No newline at end of file diff --git a/Scripts/git-hooks.sh b/Scripts/git-hooks.sh new file mode 100755 index 000000000..fd83555ef --- /dev/null +++ b/Scripts/git-hooks.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ $1 == '--install' ]]; then + echo "Installing git hooks..." + git config core.hooksPath hooks + echo "... done." +elif [[ $1 == '--uninstall' ]]; then + echo "Uninstalling git hooks..." + git config --unset core.hooksPath + echo "... done." +else + echo "[!] Usage: $0 [--install | --uninstall]" +fi \ No newline at end of file diff --git a/Scripts/install-bundler.sh b/Scripts/install-bundler.sh new file mode 100755 index 000000000..036b4e046 --- /dev/null +++ b/Scripts/install-bundler.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +eval "$(pkgx --shellcode)" + +env +gem +bundle + +echo "Installing bundler..." +bundle config set path '.bundle' +bundle install +echo "... done." diff --git a/Scripts/install-pkgx.sh b/Scripts/install-pkgx.sh new file mode 100755 index 000000000..35036b3fc --- /dev/null +++ b/Scripts/install-pkgx.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +echo "Installing pkgx..." +curl -Ssf https://pkgx.sh | sh &> /dev/null +echo "... done." diff --git a/Scripts/set-apple-api-env-interactively.sh b/Scripts/set-apple-api-env-interactively.sh new file mode 100755 index 000000000..890fe7c7d --- /dev/null +++ b/Scripts/set-apple-api-env-interactively.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +TEAM_ID="" +KEY_ISSUER_ID="" +KEY_ID="" +APPLE_API_KEY_BASE64="" + +echo "Please provide information related to your Apple account:" +echo +read -rp " TEAM_ID: " TEAM_ID +read -rp " KEY_ISSUER_ID: " KEY_ISSUER_ID +read -rp " KEY_ID: " KEY_ID +read -rp " APPLE_API_KEY_BASE64: " APPLE_API_KEY_BASE64 + +if [[ -z "$TEAM_ID" || -z "$KEY_ISSUER_ID" || -z "$KEY_ID" || -z "$APPLE_API_KEY_BASE64" ]]; then + echo + [[ -z "$TEAM_ID" ]] && echo " TEAM_ID is missing!" + [[ -z "$KEY_ISSUER_ID" ]] && echo " KEY_ISSUER_ID is missing!" + [[ -z "$KEY_ID" ]] && echo " KEY_ID is missing!" + [[ -z "$APPLE_API_KEY_BASE64" ]] && echo " APPLE_API_KEY_BASE64 is missing!" + exit 1 +fi +echo + +export TEAM_ID +export KEY_ISSUER_ID +export KEY_ID +export APPLE_API_KEY_BASE64 \ No newline at end of file diff --git a/Scripts/test-streams.sh b/Scripts/test-streams.sh index d3c292836..2078153e9 100755 --- a/Scripts/test-streams.sh +++ b/Scripts/test-streams.sh @@ -3,6 +3,7 @@ SCRIPT_NAME=$(basename "$0") SCRIPT_DIR=$(dirname "$0") +Scripts/install-pkgx.sh eval "$(pkgx --shellcode)" env +python +ffmpeg +packager @@ -142,9 +143,11 @@ function usage { while getopts sk OPT; do case "$OPT" in s) + echo "Starting test streams" serve_test_streams "$GENERATED_DIR" ;; k) + echo "Stopping test streams" kill_test_streams "$GENERATED_DIR" ;; *) @@ -153,3 +156,5 @@ while getopts sk OPT; do ;; esac done + +echo "... done." \ No newline at end of file diff --git a/Scripts/test.sh b/Scripts/test.sh new file mode 100755 index 000000000..658376505 --- /dev/null +++ b/Scripts/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "[!] Usage: $0 --platform [ios | tvos]" + echo + exit 1 +} + +if [[ "$1" != "--platform" ]]; then + usage +fi + +PLATFORM="$2" +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +Scripts/test-streams.sh -s + +Scripts/install-pkgx.sh +Scripts/install-bundler.sh + +echo "Running unit tests..." +pkgx +xcodes bundle exec fastlane "test_$PLATFORM" +echo "... done." + +Scripts/test-streams.sh -k \ No newline at end of file diff --git a/hooks/pre-commit b/hooks/pre-commit index b9a31b506..e68d777fc 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,7 +1,7 @@ #!/bin/sh # Quality check -if Scripts/check-quality.sh only-changes; then +if Scripts/check-quality.sh --only-changes; then echo "✅ Quality checked" else echo "❌ Quality check failed"