diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10c588e22..9afe74c93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Add Apple certificate run: | - Scripts/add-apple-certificate.sh \ + Scripts/private/add-apple-certificate.sh \ $RUNNER_TEMP \ ${{ secrets.KEYCHAIN_PASSWORD }} \ ${{ secrets.APPLE_DEV_CERTIFICATE }} \ @@ -59,11 +59,11 @@ jobs: - name: Configure environment run: | - Scripts/configure-environment.sh \ + Scripts/private/configure-environment.sh \ ${{ secrets.APP_STORE_CONNECT_API_KEY }} - name: Archive the demo - run: make archive-demo-${{ matrix.platform }} + run: Scripts/private/archive-demo.sh -p ${{ matrix.platform }} 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..ac6710982 100644 --- a/.github/workflows/nightlies.yml +++ b/.github/workflows/nightlies.yml @@ -21,7 +21,7 @@ jobs: - name: Add Apple certificate run: | - Scripts/add-apple-certificate.sh \ + Scripts/private/add-apple-certificate.sh \ $RUNNER_TEMP \ ${{ secrets.KEYCHAIN_PASSWORD }} \ ${{ secrets.APPLE_DEV_CERTIFICATE }} \ @@ -29,12 +29,12 @@ jobs: - name: Configure environment run: | - Scripts/configure-environment.sh \ + Scripts/private/configure-environment.sh \ ${{ secrets.APP_STORE_CONNECT_API_KEY }} - name: Deliver the demo run: | - make deliver-demo-nightly-${{ matrix.platform }} + Scripts/private/deliver-demo.sh -p ${{ matrix.platform }} -c nightly 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..46110d944 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -21,7 +21,7 @@ jobs: - name: Add Apple certificate run: | - Scripts/add-apple-certificate.sh \ + Scripts/private/add-apple-certificate.sh \ $RUNNER_TEMP \ ${{ secrets.KEYCHAIN_PASSWORD }} \ ${{ secrets.APPLE_DEV_CERTIFICATE }} \ @@ -29,12 +29,12 @@ jobs: - name: Configure environment run: | - Scripts/configure-environment.sh \ + Scripts/private/configure-environment.sh \ ${{ secrets.APP_STORE_CONNECT_API_KEY }} - name: Deliver the demo run: | - make deliver-demo-release-${{ matrix.platform }} + Scripts/private/deliver-demo.sh -p ${{ matrix.platform }} -c release env: TEAM_ID: ${{ secrets.TEAM_ID }} KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }} diff --git a/Makefile b/Makefile index 1f7b95cce..cda4ce04e 100644 --- a/Makefile +++ b/Makefile @@ -3,167 +3,74 @@ .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 - -.PHONY: archive-demo-tvos -archive-demo-tvos: install-pkgx install-bundler - @pkgx bundle exec fastlane archive_demo_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" - -.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" - -.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" - -.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" - .PHONY: test-streams-start -test-streams-start: install-pkgx - @echo "Starting test streams" - @Scripts/test-streams.sh -s - @echo "... done.\n" +test-streams-start: + @Scripts/public/test-streams.sh -s .PHONY: test-streams-stop -test-streams-stop: install-pkgx - @echo "Stopping test streams" - @Scripts/test-streams.sh -k - @echo "... done.\n" +test-streams-stop: + @Scripts/public/test-streams.sh -k .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/public/test-streams.sh -s + @Scripts/public/test.sh -p ios + @Scripts/public/test-streams.sh -k .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/public/test-streams.sh -s + @Scripts/public/test.sh -p tvos + @Scripts/public/test-streams.sh -k .PHONY: check-quality -check-quality: install-pkgx - @echo "Checking quality..." - @Scripts/check-quality.sh - @echo "... done.\n" +check-quality: + @Scripts/public/check-quality.sh .PHONY: fix-quality -fix-quality: install-pkgx - @echo "Fixing quality..." - @Scripts/fix-quality.sh - @echo "... done.\n" +fix-quality: + @Scripts/public/fix-quality.sh .PHONY: git-hook-install git-hook-install: - @echo "Installing git hooks..." - @git config core.hooksPath hooks - @echo "... done.\n" + @Scripts/public/git-hooks.sh -i .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/public/git-hooks.sh -u .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/public/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/public/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 "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/check-quality.sh b/Scripts/check-quality.sh deleted file mode 100755 index e31a467b5..000000000 --- a/Scripts/check-quality.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -e - -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 - git diff --staged --name-only | grep ".swift$" | xargs swiftlint lint --quiet --strict -fi -echo "... checking Ruby scripts..." -rubocop --format quiet -echo "... checking Shell scripts..." -shellcheck Scripts/*.sh hooks/* Artifacts/**/*.sh -echo "... checking Markdown documentation..." -markdownlint --ignore fastlane . -echo "... checking YAML files..." -yamllint .*.yml .github diff --git a/Scripts/fix-quality.sh b/Scripts/fix-quality.sh deleted file mode 100755 index 270647ef5..000000000 --- a/Scripts/fix-quality.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -e - -eval "$(pkgx --shellcode)" -env +swiftlint - -swiftlint --fix && swiftlint diff --git a/Scripts/add-apple-certificate.sh b/Scripts/private/add-apple-certificate.sh similarity index 100% rename from Scripts/add-apple-certificate.sh rename to Scripts/private/add-apple-certificate.sh diff --git a/Scripts/private/archive-demo.sh b/Scripts/private/archive-demo.sh new file mode 100755 index 000000000..9d85bd92c --- /dev/null +++ b/Scripts/private/archive-demo.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "Usage: $0 -p [ios | tvos]" + echo + exit 1 +} + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +bundle +} + +if [[ -z "$1" ]]; then + usage +fi + +while getopts p: OPT; do + case "$OPT" in + p) + PLATFORM=$OPTARG + ;; + *) + usage + ;; + esac +done + +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +install_tools + +echo -e "Archiving $PLATFORM demo..." +bundle config set path '.bundle' +bundle install +bundle exec fastlane "archive_demo_$PLATFORM" +echo "... done." \ No newline at end of file diff --git a/Scripts/configure-environment.sh b/Scripts/private/configure-environment.sh similarity index 100% rename from Scripts/configure-environment.sh rename to Scripts/private/configure-environment.sh diff --git a/Scripts/private/deliver-demo.sh b/Scripts/private/deliver-demo.sh new file mode 100755 index 000000000..eb3aa967e --- /dev/null +++ b/Scripts/private/deliver-demo.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "Usage: $0 -p [ios | tvos] -c [nightly | release]" + echo + exit 1 +} + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +bundle +magick +rsvg-convert +} + +while getopts p:c: OPT; do + case "$OPT" in + p) + PLATFORM=$OPTARG + ;; + c) + CONFIGURATION=$OPTARG + ;; + *) + usage + ;; + esac +done + +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +if [[ $CONFIGURATION != "nightly" && $CONFIGURATION != "release" ]]; then + usage +fi + +install_tools + +echo -e "Delivering demo $CONFIGURATION build for $PLATFORM..." +bundle config set path '.bundle' +bundle install +bundle exec fastlane "deliver_demo_${CONFIGURATION}_${PLATFORM}" +echo "... done." \ No newline at end of file diff --git a/Scripts/private/fix-quality.sh b/Scripts/private/fix-quality.sh new file mode 100755 index 000000000..64a8a741e --- /dev/null +++ b/Scripts/private/fix-quality.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +swiftlint +} + +install_tools + +echo "Fixing quality..." +swiftlint --fix && swiftlint +echo "... done." \ No newline at end of file diff --git a/Scripts/public/check-quality.sh b/Scripts/public/check-quality.sh new file mode 100755 index 000000000..44dcd3420 --- /dev/null +++ b/Scripts/public/check-quality.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "Usage: $0 [OPTION]" + echo " -c check only changes." + echo + exit 1 +} + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +swiftlint +shellcheck +markdownlint +} + +while getopts c OPT; do + case "$OPT" in + c) + ONLY_CHANGES=true + ;; + *) + usage + ;; + esac +done + +install_tools + +echo "Checking quality..." + +echo "... checking Swift code..." +if [[ "$ONLY_CHANGES" == true ]]; then + git diff --staged --name-only | grep ".swift$" | xargs swiftlint lint --quiet --strict +else + swiftlint --quiet --strict +fi + +echo "... checking Ruby scripts..." +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 + +echo "... checking Markdown documentation..." +markdownlint --ignore fastlane . + +echo "... checking YAML files..." +pkgx yamllint .*.yml .github + +echo "... done." \ No newline at end of file diff --git a/Scripts/public/clean-imports.sh b/Scripts/public/clean-imports.sh new file mode 100755 index 000000000..e30f9da82 --- /dev/null +++ b/Scripts/public/clean-imports.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +swiftlint +} + +install_tools + +echo "Cleaning imports..." +mkdir -p .build +xcodebuild -scheme Pillarbox -destination generic/platform=ios > ./.build/xcodebuild.log +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 +swiftlint analyze --fix --compiler-log-path ./.build/xcodebuild.log +echo "... done." \ No newline at end of file diff --git a/Scripts/public/find-dead-code.sh b/Scripts/public/find-dead-code.sh new file mode 100755 index 000000000..f2e722db6 --- /dev/null +++ b/Scripts/public/find-dead-code.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +periphery +} + +install_tools + +echo "Start checking dead code..." +mkdir -p .build +xcodebuild -scheme Pillarbox -destination generic/platform=iOS -derivedDataPath ./.build/derived-data clean build &> /dev/null +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 +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/public/git-hooks.sh b/Scripts/public/git-hooks.sh new file mode 100755 index 000000000..4d32fb16f --- /dev/null +++ b/Scripts/public/git-hooks.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +function usage { + echo + echo "Usage: $0 [OPTION]" + echo " -i install git hooks." + echo " -u uninstall git hooks." + echo + exit 1 +} + +if [[ -z "$1" ]]; then + usage +fi + +while getopts iu OPT; do + case "$OPT" in + i) + echo "Installing git hooks..." + git config core.hooksPath hooks + echo "... done." + ;; + u) + echo "Uninstalling git hooks..." + git config --unset core.hooksPath + echo "... done." + ;; + *) + usage + ;; + esac +done \ No newline at end of file diff --git a/Scripts/test-streams.sh b/Scripts/public/test-streams.sh similarity index 91% rename from Scripts/test-streams.sh rename to Scripts/public/test-streams.sh index d3c292836..8217767b2 100755 --- a/Scripts/test-streams.sh +++ b/Scripts/public/test-streams.sh @@ -1,14 +1,10 @@ #!/bin/bash -SCRIPT_NAME=$(basename "$0") SCRIPT_DIR=$(dirname "$0") -eval "$(pkgx --shellcode)" -env +python +ffmpeg +packager - GENERATED_DIR="/tmp/pillarbox" -METADATA_DIR="$SCRIPT_DIR/../metadata" +METADATA_DIR="$SCRIPT_DIR/../../metadata" SUBTITLES_DIR="$METADATA_DIR/subtitles" JSON_DIR="$METADATA_DIR/json" @@ -130,26 +126,40 @@ function kill_test_streams { } function usage { - echo "Generate test streams and manage an HTTP server to serve them locally." - echo "" - echo "Usage: $SCRIPT_NAME [-s] [-k]" - echo "" - echo "Options:" - echo " -s: Start serving test streams." - echo " -k: Kill the server." + echo + echo "Usage: $0 [OPTION]" + echo " -s start serving test streams." + echo " -k kill the server." + echo + exit 1 +} + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +python +ffmpeg +packager } +if [[ -z "$1" ]]; then + usage +fi + while getopts sk OPT; do case "$OPT" in s) + echo "Starting test streams" + install_tools serve_test_streams "$GENERATED_DIR" + echo "... done." ;; k) + echo "Stopping test streams" + install_tools kill_test_streams "$GENERATED_DIR" + echo "... done." ;; *) usage - exit 1 ;; esac -done +done \ No newline at end of file diff --git a/Scripts/public/test.sh b/Scripts/public/test.sh new file mode 100755 index 000000000..2558632ad --- /dev/null +++ b/Scripts/public/test.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +function usage { + echo + echo "Usage: $0 -p [ios | tvos]" + echo + exit 1 +} + +function install_tools { + curl -Ssf https://pkgx.sh | sh &> /dev/null + eval "$(pkgx --shellcode)" + env +ruby +bundle +xcodes +} + +if [[ -z "$1" ]]; then + usage +fi + +while getopts p: OPT; do + case "$OPT" in + p) + PLATFORM=$OPTARG + ;; + *) + usage + ;; + esac +done + +if [[ $PLATFORM != "ios" && $PLATFORM != "tvos" ]]; then + usage +fi + +install_tools + +echo "Running unit tests..." +bundle config set path '.bundle' +bundle install +bundle exec fastlane "test_$PLATFORM" +echo "... done." \ No newline at end of file diff --git a/hooks/pre-commit b/hooks/pre-commit index b9a31b506..b79280206 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/public/check-quality.sh -c; then echo "✅ Quality checked" else echo "❌ Quality check failed"