Skip to content

Commit f041bdf

Browse files
feat: add github action to deploy docs (#142)
1 parent 4f4c96a commit f041bdf

4 files changed

Lines changed: 386 additions & 0 deletions

File tree

.github/workflows/publish-docs.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish docs
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
- '[0-9]*.[0-9]*.[0-9]*'
10+
11+
jobs:
12+
publish-docs:
13+
runs-on: macos-15
14+
name: Publish docs
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Select Xcode
21+
uses: maxim-lobanov/setup-xcode@v1
22+
with:
23+
xcode-version: '26.2'
24+
25+
- name: Resolve dependencies
26+
run: swift package resolve
27+
28+
- name: Build documentation
29+
run: bash scripts/docs-generator/build.sh
30+
31+
- name: Publish docs to Netlify
32+
# No published tags in netlify/actions, master is recommended.
33+
uses: netlify/actions/cli@master
34+
with:
35+
args: deploy --dir=docs --prod
36+
env:
37+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
38+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ builds/
8989
.ruby-version
9090
Examples/OnboardingsDemo-UIKit/Podfile.lock
9191
Examples/AdaptyRecipes-UIKit/Podfile.lock
92+
docs/

scripts/docs-generator/build.sh

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#!/bin/bash
2+
3+
# Script for installing dependencies and building HTML documentation for Adapty SDK
4+
# This script uses Swift Package Manager to generate DocC documentation
5+
6+
set -e # Exit on error
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
# Function to display informational messages
15+
info() {
16+
echo -e "${GREEN}[INFO]${NC} $1"
17+
}
18+
19+
# Function to display warnings
20+
warn() {
21+
echo -e "${YELLOW}[WARN]${NC} $1"
22+
}
23+
24+
# Function to display errors
25+
error() {
26+
echo -e "${RED}[ERROR]${NC} $1"
27+
}
28+
29+
# Check for required tools
30+
check_requirements() {
31+
info "Checking for required tools..."
32+
33+
# Check for Swift
34+
if ! command -v swift &> /dev/null; then
35+
error "swift not found. Please install Xcode Command Line Tools."
36+
exit 1
37+
fi
38+
39+
# Check Swift version (need 5.6+ for docc plugin)
40+
SWIFT_VERSION=$(swift --version | head -n 1 | awk '{print $4}')
41+
info "Swift version: $SWIFT_VERSION"
42+
43+
info "All required tools are installed ✓"
44+
}
45+
46+
# Get project root directory
47+
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
48+
info "Project root directory: $PROJECT_ROOT"
49+
50+
# Output directory for documentation
51+
OUTPUT_DIR="${PROJECT_ROOT}/docs"
52+
info "Documentation directory: $OUTPUT_DIR"
53+
54+
# Create documentation directory if it doesn't exist
55+
mkdir -p "$OUTPUT_DIR"
56+
57+
# Function to build documentation for a module using manual docc compilation
58+
build_documentation() {
59+
local module_name=$1
60+
info "Building documentation for module: $module_name"
61+
62+
# Map module name to source directory
63+
local SOURCE_DIR=""
64+
case "$module_name" in
65+
"Adapty")
66+
SOURCE_DIR="${PROJECT_ROOT}/Sources"
67+
;;
68+
"AdaptyUI")
69+
SOURCE_DIR="${PROJECT_ROOT}/Sources.AdaptyUI"
70+
;;
71+
"AdaptyLogger")
72+
SOURCE_DIR="${PROJECT_ROOT}/Sources.Logger"
73+
;;
74+
"AdaptyUIBuilder")
75+
SOURCE_DIR="${PROJECT_ROOT}/Sources.UIBuilder"
76+
;;
77+
"AdaptyPlugin")
78+
SOURCE_DIR="${PROJECT_ROOT}/Sources.AdaptyPlugin"
79+
;;
80+
*)
81+
error "Unknown module: $module_name"
82+
return 1
83+
;;
84+
esac
85+
86+
# Check if source directory exists
87+
if [ ! -d "$SOURCE_DIR" ]; then
88+
error "Source directory not found: $SOURCE_DIR"
89+
return 1
90+
fi
91+
92+
info "Source directory: $SOURCE_DIR"
93+
94+
# Build the module and generate symbol graph
95+
info "Building module and generating symbol graph..."
96+
97+
# Create module-specific symbol graphs directory (keep existing graphs for incremental builds)
98+
local SYMBOL_GRAPH_DIR="${PROJECT_ROOT}/.build/symbol-graphs/${module_name}"
99+
mkdir -p "$SYMBOL_GRAPH_DIR"
100+
101+
swift build --target "$module_name" \
102+
-Xswiftc -emit-symbol-graph \
103+
-Xswiftc -emit-symbol-graph-dir -Xswiftc "$SYMBOL_GRAPH_DIR" \
104+
|| {
105+
error "Failed to build $module_name and generate symbol graph"
106+
return 1
107+
}
108+
109+
# Fallback: incremental builds can skip compilation and not emit symbol graphs
110+
if ! compgen -G "$SYMBOL_GRAPH_DIR/*.symbols.json" > /dev/null; then
111+
warn "Symbol graphs were not generated. Forcing clean rebuild..."
112+
swift package clean
113+
rm -rf "$SYMBOL_GRAPH_DIR"
114+
mkdir -p "$SYMBOL_GRAPH_DIR"
115+
swift build --target "$module_name" \
116+
-Xswiftc -emit-symbol-graph \
117+
-Xswiftc -emit-symbol-graph-dir -Xswiftc "$SYMBOL_GRAPH_DIR" \
118+
|| {
119+
error "Failed to build $module_name and generate symbol graph"
120+
return 1
121+
}
122+
fi
123+
124+
info "Symbol graphs for $module_name and its dependencies generated ✓"
125+
126+
# Build documentation with docc
127+
local ARCHIVE_PATH="${PROJECT_ROOT}/.build/${module_name}.doccarchive"
128+
mkdir -p "${PROJECT_ROOT}/.build"
129+
rm -rf "$ARCHIVE_PATH"
130+
131+
info "Generating DocC archive..."
132+
xcrun docc convert "$SOURCE_DIR" \
133+
--allow-arbitrary-catalog-directories \
134+
--fallback-display-name "$module_name" \
135+
--fallback-bundle-identifier "io.adapty.${module_name}" \
136+
--fallback-bundle-version "1.0.0" \
137+
--additional-symbol-graph-dir "$SYMBOL_GRAPH_DIR" \
138+
--output-path "$ARCHIVE_PATH" \
139+
|| {
140+
error "Failed to generate documentation for $module_name"
141+
return 1
142+
}
143+
144+
info "Documentation archive created at $ARCHIVE_PATH"
145+
}
146+
147+
# Function to export documentation to HTML
148+
export_to_html() {
149+
local module_name=$1
150+
local ARCHIVE_PATH="${PROJECT_ROOT}/.build/${module_name}.doccarchive"
151+
152+
if [ ! -d "$ARCHIVE_PATH" ]; then
153+
error "Documentation archive for $module_name not found at $ARCHIVE_PATH, cannot export to HTML"
154+
return 1
155+
fi
156+
157+
info "Exporting $module_name documentation to HTML..."
158+
159+
# Ensure OUTPUT_DIR is clean and exists
160+
rm -rf "$OUTPUT_DIR"
161+
mkdir -p "$OUTPUT_DIR"
162+
163+
# Export to HTML using xcrun docc
164+
xcrun docc process-archive transform-for-static-hosting \
165+
"$ARCHIVE_PATH" \
166+
--output-path "$OUTPUT_DIR" \
167+
|| {
168+
error "Failed to export documentation for $module_name to HTML"
169+
return 1
170+
}
171+
172+
info "HTML documentation for $module_name created at $OUTPUT_DIR"
173+
}
174+
175+
# Main function
176+
main() {
177+
info "=== Starting Adapty SDK documentation build process ==="
178+
179+
# Check requirements
180+
check_requirements
181+
182+
# Navigate to project root directory
183+
cd "$PROJECT_ROOT"
184+
185+
# We only build AdaptyUI (it now includes Adapty docs)
186+
local module="AdaptyUI"
187+
188+
# 1. Build the archive
189+
build_documentation "$module" || exit 1
190+
191+
# 2. Export to HTML (Mandatory)
192+
export_to_html "$module" || exit 1
193+
194+
# 3. Use the landing template for the root index.html
195+
info "Setting up documentation hub (landing page)..."
196+
local template_path="${PROJECT_ROOT}/scripts/docs-generator/landing.html"
197+
if [ -f "$template_path" ]; then
198+
cp "$template_path" "${OUTPUT_DIR}/index.html"
199+
info "Documentation hub configured ✓"
200+
else
201+
warn "Landing template not found at $template_path, skipping..."
202+
fi
203+
204+
info "=== Documentation build completed successfully! ==="
205+
info "Final documentation saved to: ${OUTPUT_DIR}"
206+
info ""
207+
info "To view the documentation:"
208+
info " 1. Start a local server: cd ${OUTPUT_DIR} && python3 -m http.server 8080"
209+
info " 2. Open: http://localhost:8080/"
210+
}
211+
212+
# Run main function
213+
main "$@"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
7+
<title>Adapty iOS SDK Documentation</title>
8+
<style>
9+
:root {
10+
--color-fill: #ffffff;
11+
--color-figure-gray: #f5f5f7;
12+
--color-figure-gray-secondary: #86868b;
13+
--color-text: #1d1d1f;
14+
--color-link: #0066cc;
15+
--font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Icons", "Helvetica Neue", Helvetica, Arial, sans-serif;
16+
}
17+
18+
@media (prefers-color-scheme: dark) {
19+
:root {
20+
--color-fill: #000000;
21+
--color-figure-gray: #1c1c1e;
22+
--color-figure-gray-secondary: #98989d;
23+
--color-text: #f5f5f7;
24+
--color-link: #2997ff;
25+
}
26+
}
27+
28+
body {
29+
background-color: var(--color-fill);
30+
color: var(--color-text);
31+
font-family: var(--font-family);
32+
margin: 0;
33+
padding: 0;
34+
display: flex;
35+
flex-direction: column;
36+
align-items: center;
37+
justify-content: center;
38+
min-height: 100vh;
39+
}
40+
41+
.container {
42+
max-width: 980px;
43+
width: 100%;
44+
padding: 40px 20px;
45+
text-align: center;
46+
}
47+
48+
h1 {
49+
font-size: 48px;
50+
font-weight: 600;
51+
letter-spacing: -0.003em;
52+
margin-bottom: 60px;
53+
}
54+
55+
.grid {
56+
display: grid;
57+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
58+
gap: 30px;
59+
margin-top: 40px;
60+
}
61+
62+
.card {
63+
background-color: var(--color-figure-gray);
64+
border-radius: 20px;
65+
padding: 40px;
66+
text-decoration: none;
67+
color: inherit;
68+
transition: transform 0.3s ease, box-shadow 0.3s ease;
69+
display: flex;
70+
flex-direction: column;
71+
align-items: flex-start;
72+
text-align: left;
73+
}
74+
75+
.card:hover {
76+
transform: scale(1.02);
77+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
78+
}
79+
80+
.card h2 {
81+
font-size: 24px;
82+
font-weight: 600;
83+
margin: 0 0 10px 0;
84+
}
85+
86+
.card p {
87+
font-size: 17px;
88+
line-height: 1.47059;
89+
color: var(--color-figure-gray-secondary);
90+
margin: 0 0 20px 0;
91+
}
92+
93+
.card .link {
94+
color: var(--color-link);
95+
font-size: 17px;
96+
font-weight: 400;
97+
display: flex;
98+
align-items: center;
99+
}
100+
101+
.card .link::after {
102+
content: "›";
103+
margin-left: 5px;
104+
font-size: 20px;
105+
line-height: 0;
106+
}
107+
108+
footer {
109+
margin-top: 80px;
110+
font-size: 12px;
111+
color: var(--color-figure-gray-secondary);
112+
}
113+
</style>
114+
</head>
115+
116+
<body>
117+
<div class="container">
118+
<h1>Adapty SDK Documentation</h1>
119+
<div class="grid">
120+
<a href="./documentation/adapty/" class="card">
121+
<h2>Adapty Core</h2>
122+
<p>The main SDK for in-app purchases, subscriber attribution, and analytics.</p>
123+
<div class="link">View Documentation</div>
124+
</a>
125+
<a href="./documentation/adaptyui/" class="card">
126+
<h2>AdaptyUI</h2>
127+
<p>Visual paywalls and UI components for seamless integration.</p>
128+
<div class="link">View Documentation</div>
129+
</a>
130+
</div>
131+
</div>
132+
</body>
133+
134+
</html>

0 commit comments

Comments
 (0)