-
Notifications
You must be signed in to change notification settings - Fork 35
183 lines (161 loc) · 7.06 KB
/
Copy pathgenerate-api-docs.yml
File metadata and controls
183 lines (161 loc) · 7.06 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Generate TypeScript API Docs
on:
schedule:
# Check nightly — generation only runs if new versions are detected
- cron: "17 4 * * *"
workflow_dispatch:
inputs:
versions:
description: "Comma-separated versions. Use @sapui5/types@1.149.0 for SAPUI5, bare 1.149.0 defaults to OpenUI5. Leave empty for auto-detect."
required: false
default: ""
permissions:
contents: read
concurrency:
group: generate-api-docs
cancel-in-progress: false
jobs:
generate:
runs-on: ubuntu-latest
timeout-minutes: 90
permissions:
contents: write
steps:
- name: Checkout main (scripts + workflow)
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: main
path: main
- name: Checkout gh-pages (published site)
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: gh-pages
path: gh-pages
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "22.16.0"
- name: Install generator dependencies
working-directory: main/scripts/generate-api-docs
run: npm ci --ignore-scripts
- name: Determine versions to generate
id: versions
run: |
if [ -n "${{ inputs.versions }}" ]; then
# Manual dispatch with explicit versions
echo "versions=${{ inputs.versions }}" >> "$GITHUB_OUTPUT"
echo "Manual versions: ${{ inputs.versions }}"
else
# Auto-detect: fetch LTS + latest versions from version overview APIs
# Then find the latest patch of each that has a types package on npm
VERSIONS=""
for OVERVIEW_URL in "https://sdk.openui5.org/versionoverview.json" "https://ui5.sap.com/versionoverview.json"; do
# Get LTS versions + the latest (highest) maintenance version
# Filter: lts===true OR highest minor. Floor: types packages exist since 1.120.
MAINT_LINES=$(curl -sf "$OVERVIEW_URL" | node -e "
const data = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
const maintained = data.versions.filter(v => v.support === 'Maintenance');
const latest = maintained[0]; // first entry is always the newest
const lines = maintained
.filter(v => v.lts === true || v === latest)
.map(v => v.version.replace('.*',''))
.filter(v => {
const [maj, min] = v.split('.').map(Number);
return maj >= 2 || (maj === 1 && min >= 120);
});
console.log(lines.join(' '));
")
PKG=$( [[ "$OVERVIEW_URL" == *"openui5"* ]] && echo "@openui5/types" || echo "@sapui5/types" )
for LINE in $MAINT_LINES; do
# Get the latest published patch for this minor line.
# npm show with a range outputs "pkg@ver 'ver'" per match; extract the bare version.
LATEST=$(npm show "${PKG}@~${LINE}.0" version 2>/dev/null | tail -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | tail -1)
if [ -n "$LATEST" ]; then
VERSIONS="${VERSIONS}${VERSIONS:+,}${PKG}@${LATEST}"
fi
done
done
echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT"
echo "Detected versions: $VERSIONS"
fi
- name: Generate API docs
id: generate
working-directory: main/scripts/generate-api-docs
run: |
IFS=',' read -ra ENTRIES <<< "${{ steps.versions.outputs.versions }}"
GENERATED=""
for ENTRY in "${ENTRIES[@]}"; do
# Skip empty entries (from trailing commas or empty versions output)
[[ -z "$ENTRY" ]] && continue
# Parse: either "@openui5/types@1.148.1" or just "1.148.1" (defaults to @openui5/types)
if [[ "$ENTRY" == @* ]]; then
PKG=$(echo "$ENTRY" | sed 's/@[^@]*$//')
VERSION=$(echo "$ENTRY" | sed 's/.*@//')
else
PKG="@openui5/types"
VERSION="$ENTRY"
fi
FRAMEWORK=$( [[ "$PKG" == *"openui5"* ]] && echo "openui5" || echo "sapui5" )
DIR=$(echo "$VERSION" | sed 's/\([0-9]*\.[0-9]*\).*/\1/')
# Validate VERSION looks like semver and DIR like major.minor
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "⚠ Invalid version format: '$VERSION' — skipping"
continue
fi
# Check if this exact version is already generated
VERSION_FILE="../../../gh-pages/api/${FRAMEWORK}/${DIR}/.version"
if [ -f "$VERSION_FILE" ]; then
EXISTING=$(cat "$VERSION_FILE")
if [ "$EXISTING" = "$VERSION" ]; then
echo "✓ ${FRAMEWORK} ${VERSION} already up to date — skipping"
continue
else
echo "↻ ${FRAMEWORK} ${EXISTING} → ${VERSION} (updating)"
fi
else
echo "+ ${FRAMEWORK} ${VERSION} (new)"
fi
# Generate into a temp directory; only replace target on success
TEMP_OUT="../../../gh-pages/api/${FRAMEWORK}/${DIR}.tmp"
TARGET="../../../gh-pages/api/${FRAMEWORK}/${DIR}"
if node generate.mjs \
--package "$PKG" \
--version "$VERSION" \
--out "$TEMP_OUT" \
--base-url "https://ui5.github.io/typescript/api/${FRAMEWORK}/${DIR}/"; then
rm -rf "$TARGET"
mv "$TEMP_OUT" "$TARGET"
GENERATED="${GENERATED}${GENERATED:+, }${FRAMEWORK}@${VERSION}"
else
echo "⚠ FAILED: ${FRAMEWORK} ${VERSION} — keeping existing docs"
rm -rf "$TEMP_OUT"
fi
done
echo "generated=$GENERATED" >> "$GITHUB_OUTPUT"
if [ -z "$GENERATED" ]; then
echo "All versions up to date — nothing to generate"
fi
- name: Update index pages
working-directory: gh-pages
run: |
node ../main/scripts/generate-api-docs/generate-index-pages.mjs \
--api-dir api \
--site-root . \
--base-url https://ui5.github.io/typescript/api
- name: Commit and push to gh-pages
working-directory: gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add api/ sitemap.xml
if git diff --cached --quiet; then
echo "No changes to commit"
else
GENERATED="${{ steps.generate.outputs.generated }}"
if [ -n "$GENERATED" ]; then
git commit -m "docs: update TypeScript API reference: ${GENERATED}"
else
git commit -m "docs: update TypeScript API reference"
fi
git push
fi