-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (130 loc) · 6.17 KB
/
Makefile
File metadata and controls
152 lines (130 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
.PHONY: setup format format-check lint lint-fix check install-tools install-hooks install-xcode-template-macros create-example-local-secrets-plists set-example-pk test test-integration help create-env install-1password-cli fetch-test-keys update-swiftformat update-swiftlint
SWIFTFORMAT := $(CURDIR)/.tools/bin/swiftformat
SWIFTLINT := $(CURDIR)/.tools/bin/swiftlint
# Default target
help:
@echo "Available commands:"
@echo " make setup - Install tools/hooks and configure Xcode file headers"
@echo " make fetch-test-keys - Fetch integration test keys from 1Password (optional, for Clerk employees; auto-installs CLI if needed)"
@echo " make format - Format all Swift files using SwiftFormat"
@echo " make format-check - Check formatting without modifying files (for CI)"
@echo " make lint - Run SwiftLint to check code quality"
@echo " make lint-fix - Run SwiftLint with auto-fix where possible"
@echo " make check - Run both format-check and lint (for CI)"
@echo " make test - Run unit tests"
@echo " make test-integration - Run only integration tests"
@echo " make install-tools - Install pinned SwiftFormat and SwiftLint"
@echo " make update-swiftformat - Update pinned SwiftFormat to the latest release"
@echo " make update-swiftlint - Update pinned SwiftLint to the latest release"
@echo " make install-hooks - Set up pre-commit hook to auto-format staged Swift files"
@echo " make install-xcode-template-macros - Sync Xcode file header templates for workspace and package views"
@echo " make create-example-local-secrets-plists - Create LocalSecrets.plist files for examples from templates"
@echo " make set-example-pk pk_test_... - Set CLERK_PUBLISHABLE_KEY for all example LocalSecrets.plist files"
# Main setup command - installs tools and hooks
setup: install-tools install-hooks install-xcode-template-macros create-example-local-secrets-plists
@echo "✅ Setup complete!"
@echo " Clerk employees: Run 'make fetch-test-keys' to populate integration test keys from 1Password"
# Create .keys.json file with blank integration test key if it doesn't exist
create-env:
@./scripts/create-keys-json.sh
# Create LocalSecrets.plist files for all example apps from templates if missing
create-example-local-secrets-plists:
@./scripts/create-example-local-secrets-plists.sh
# Set CLERK_PUBLISHABLE_KEY in all example LocalSecrets.plist files.
# Captures the argument from the raw make command line so keys ending in '$' are preserved.
# make set-example-pk pk_test_...
set-example-pk: create-example-local-secrets-plists
@raw_make_command="$$(ps -o command= -p $$PPID)"; \
publishable_key="$$(printf '%s\n' "$$raw_make_command" | awk '{ for (i = 1; i <= NF; i++) if ($$i == "set-example-pk") { print $$(i + 1); exit } }')"; \
if [ -z "$$publishable_key" ]; then \
echo "Usage: make set-example-pk pk_test_..."; \
exit 1; \
fi; \
./scripts/set-example-publishable-key.sh "$$publishable_key"
ifneq (,$(filter set-example-pk,$(MAKECMDGOALS)))
%:
@:
endif
# Install the repo-pinned SwiftFormat and SwiftLint
install-tools:
@./scripts/install-swiftformat.sh
@./scripts/install-swiftlint.sh
update-swiftformat:
@./scripts/update-swiftformat-to-latest.sh
update-swiftlint:
@./scripts/update-swiftlint-to-latest.sh
# Install pre-commit hook
install-hooks:
@set -e; \
hooks_dir="$$(git rev-parse --git-path hooks)"; \
source_hook=".githooks/pre-commit"; \
if [ -e "$$hooks_dir" ] && [ ! -d "$$hooks_dir" ]; then \
echo "⚠️ Skipping pre-commit hook install because hooks path is not a directory: $$hooks_dir"; \
exit 0; \
fi; \
target_hook="$$hooks_dir/pre-commit"; \
mkdir -p "$$hooks_dir"; \
source_abs="$$(cd "$$(dirname "$$source_hook")" && pwd)/$$(basename "$$source_hook")"; \
target_abs="$$(cd "$$(dirname "$$target_hook")" && pwd)/$$(basename "$$target_hook")"; \
if [ "$$source_abs" != "$$target_abs" ]; then \
cp "$$source_hook" "$$target_hook"; \
fi; \
chmod +x "$$target_hook"; \
echo "✅ Pre-commit hook installed"
# Install Xcode file header macros in both workspace and Swift package workspace
install-xcode-template-macros:
@if [ ! -f Clerk.xcworkspace/xcshareddata/IDETemplateMacros.plist ]; then \
echo "❌ Missing Clerk.xcworkspace/xcshareddata/IDETemplateMacros.plist"; \
exit 1; \
fi
@mkdir -p .swiftpm/xcode/package.xcworkspace/xcshareddata
@cp Clerk.xcworkspace/xcshareddata/IDETemplateMacros.plist .swiftpm/xcode/package.xcworkspace/xcshareddata/IDETemplateMacros.plist
@echo "✅ Xcode file header macros configured"
# Install 1Password CLI via Homebrew (optional, for Clerk employees)
install-1password-cli:
@echo "Checking for 1Password CLI..."
@if ! command -v op > /dev/null; then \
echo "Installing 1Password CLI via Homebrew..."; \
brew install 1password-cli; \
else \
echo "✅ 1Password CLI installed"; \
fi
# Fetch integration test keys from 1Password (optional, for Clerk employees only)
# Automatically installs 1Password CLI if not present
fetch-test-keys: install-1password-cli create-env
@./scripts/fetch-1password-secrets.sh
# Format all Swift files
format:
@echo "Formatting Swift files..."
@./scripts/install-swiftformat.sh > /dev/null
@"$(SWIFTFORMAT)" .
# Check formatting without modifying files
format-check:
@echo "Checking Swift file formatting..."
@./scripts/install-swiftformat.sh > /dev/null
@"$(SWIFTFORMAT)" --lint .
# Run SwiftLint
lint:
@echo "Running SwiftLint..."
@./scripts/install-swiftlint.sh > /dev/null
@"$(SWIFTLINT)"
# Run SwiftLint with auto-fix
lint-fix:
@echo "Running SwiftLint with auto-fix..."
@./scripts/install-swiftlint.sh > /dev/null
@"$(SWIFTLINT)" --fix
# Run both format-check and lint
check: format-check lint
@echo "✅ All checks passed!"
# Run unit tests
test:
@echo "Running unit tests..."
swift test --skip Integration
@echo "✅ Unit tests completed!"
# Run only integration tests
# Tests decide which key to use from .keys.json (each test can specify its own key)
# In CI, .keys.json is created from CLERK_TEST_KEYS_JSON GitHub Actions secret
# Locally, only Clerk employees can run integration tests (they have 1Password vault access)
# OSS contributors: Integration tests will run automatically in CI
test-integration:
@./scripts/run-integration-tests.sh