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

Cleanup Makefile targets #1104

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6c9835a
Add install-pkgx.sh
waliid Dec 12, 2024
aa34556
Add install-bundler.sh
waliid Dec 12, 2024
621d7e0
Set scripts permissions
waliid Dec 13, 2024
8ab42bd
Move archive-demo target in a dedicated script
waliid Dec 13, 2024
3426d00
Improve Makefile doc
waliid Dec 13, 2024
96d5556
Improve archive-demo.sh
waliid Dec 13, 2024
3d17426
Install pkgx and bundler before running archive
waliid Dec 13, 2024
26701f4
Print more information when the script fails
waliid Dec 13, 2024
2a48330
Use scripts to install pkgx and bundler
waliid Dec 13, 2024
aa3ac2e
Improve archive-demo script
waliid Dec 13, 2024
d38d740
Add deliver-demo script
waliid Dec 13, 2024
98eb6f3
Update nightly and release workflows to use non-interactive Makefile …
waliid Dec 13, 2024
1079732
Update Makefile help
waliid Dec 13, 2024
4340c26
Factorize interactive part
waliid Dec 13, 2024
fc0bca4
Avoid check quality issue
waliid Dec 14, 2024
6b7f280
Improve check-quality script
waliid Dec 14, 2024
3500098
Simplify server test targets
waliid Dec 14, 2024
b038b03
Fix install-bundler script by specifying gem as an environment binary
waliid Dec 15, 2024
5b0668b
Introduce dedicated script for tests
waliid Dec 15, 2024
6db834b
Simplify check-quality target
waliid Dec 16, 2024
75ed657
Harmonize done messages
waliid Dec 16, 2024
08c8db6
Simplify fix-quality target
waliid Dec 16, 2024
1e618ca
Remove unused/useless target
waliid Dec 16, 2024
13872ee
Move clean imports script to a dedicated file
waliid Dec 19, 2024
a5b3e2b
Move find dead code script in a dedicated file
waliid Dec 19, 2024
e9e04df
Move git hooks Makefile scripts in a dedicated files
waliid Dec 19, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightlies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
180 changes: 59 additions & 121 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
43 changes: 43 additions & 0 deletions Scripts/archive-demo.sh
Original file line number Diff line number Diff line change
@@ -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."
27 changes: 19 additions & 8 deletions Scripts/check-quality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
9 changes: 9 additions & 0 deletions Scripts/clean-imports.sh
Original file line number Diff line number Diff line change
@@ -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."
Loading