Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
153 lines (125 loc) · 4.78 KB
/
Copy pathaction.yml
File metadata and controls
153 lines (125 loc) · 4.78 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
153
name: 'Build DocC Documentation'
description: 'Build Swift DocC documentation with versioning support'
author: 'Nikita Vasilev'
inputs:
schemes:
description: 'JSON array of schemes to build (e.g. ["MyLib", "MyUI"])'
required: true
version:
description: 'Documentation version'
required: false
default: 'latest'
xcode-version:
description: 'Xcode version'
required: false
default: 'latest-stable'
keep-old-versions:
description: 'Keep old versions in docs/'
required: false
default: 'true'
outputs:
docs-path:
description: 'Path to the generated docs folder'
value: ${{ steps.build.outputs.docs_path }}
version:
description: 'Version used for build'
value: ${{ steps.parse.outputs.version }}
runs:
using: 'composite'
steps:
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ inputs.xcode-version }}
- name: Parse Configuration
id: parse
shell: bash
run: |
SCHEMES='${{ inputs.schemes }}'
echo "schemes=$SCHEMES" >> $GITHUB_OUTPUT
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
PROJECT_NAME="${{ inputs.project-name }}"
if [ -z "$PROJECT_NAME" ]; then
PROJECT_NAME="$REPO_NAME"
fi
echo "project_name=$PROJECT_NAME" >> $GITHUB_OUTPUT
VERSION="${{ inputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📘 Documentation Build Configuration:"
echo " Repository: $REPO_NAME"
echo " Project: $PROJECT_NAME"
echo " Version: $VERSION"
echo " Schemes: $SCHEMES"
- name: Preserve Old Versions
shell: bash
run: |
if [ "${{ inputs.keep-old-versions }}" == "true" ] && [ -d "docs" ]; then
echo "📦 Saving existing documentation versions..."
mv docs docs-old
else
echo "🗑️ Old versions will not be preserved"
if [ -d "docs" ]; then
echo "🗑️ Removing existing docs directory..."
rm -rf docs
fi
fi
- name: Build DocC
id: build
shell: bash
run: |
set -o pipefail
set -e
VERSION="${{ steps.parse.outputs.version }}"
REPO_NAME="${{ steps.parse.outputs.repo_name }}"
SCHEMES=$(echo '${{ steps.parse.outputs.schemes }}' | jq -r '.[]')
BUILD="build"
DOCS_DIR="docs"
echo "📘 Building DocC for repository: $REPO_NAME"
echo "📘 Version: $VERSION"
# Clean build directory
rm -rf "$BUILD"
mkdir -p "$BUILD"
# Prepare docs directory
mkdir -p "$DOCS_DIR/$VERSION"
# Copy old versions if keeping them
if [ "${{ inputs.keep-old-versions }}" == "true" ] && [ -d "docs-old" ]; then
echo "📦 Restoring old documentation versions..."
cp -r docs-old/* "$DOCS_DIR/" 2>/dev/null || true
rm -rf docs-old
fi
# Generate DocC for each scheme
for SCHEME in $SCHEMES; do
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📘 Building DocC for $SCHEME ..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
DERIVED_DATA="$BUILD/$SCHEME"
xcodebuild docbuild \
-scheme "$SCHEME" \
-destination 'platform=macOS' \
-derivedDataPath "$DERIVED_DATA"
ARCHIVE_PATH=$(find "$DERIVED_DATA" -name "$SCHEME.doccarchive" -type d | head -n 1)
if [ -z "$ARCHIVE_PATH" ]; then
echo "❌ No doccarchive for $SCHEME"
find "$DERIVED_DATA" -name "*.doccarchive" -type d || echo "No archives found"
exit 1
fi
echo "✅ Found archive: $ARCHIVE_PATH"
OUTPUT_PATH="$DOCS_DIR/$VERSION/$SCHEME"
mkdir -p "$OUTPUT_PATH"
HOSTING_BASE_PATH="$REPO_NAME/$VERSION/$SCHEME"
echo "📘 Using hosting base path: $HOSTING_BASE_PATH"
$(xcrun --find docc) process-archive \
transform-for-static-hosting \
"$ARCHIVE_PATH" \
--output-path "$OUTPUT_PATH" \
--hosting-base-path "$HOSTING_BASE_PATH"
echo "✅ $SCHEME docs ready at $OUTPUT_PATH"
done
echo "docs_path=$DOCS_DIR" >> $GITHUB_OUTPUT
echo ""
echo "🎉 Documentation generated for $REPO_NAME version $VERSION"
branding:
icon: 'book'
color: 'purple'