-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (158 loc) · 6.6 KB
/
Copy pathupdate-device-docs.yml
File metadata and controls
181 lines (158 loc) · 6.6 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
name: Update Device Docs
on:
repository_dispatch:
types: [docs-update]
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Validate payload
run: |
if [ -z "${{ github.event.client_payload.device }}" ]; then
echo "::error::Missing client_payload.device"
exit 1
fi
if [ -z "${{ github.event.client_payload.firmware_version }}" ]; then
echo "::error::Missing client_payload.firmware_version"
exit 1
fi
if [ -z "${{ github.event.client_payload.docs_url }}" ]; then
echo "::error::Missing client_payload.docs_url"
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BUILD_STATION_TOKEN }}
- name: Resolve device path
id: device
run: |
DEVICE="${{ github.event.client_payload.device }}"
case "$DEVICE" in
bridge4) DEVICE_PATH="docs/devices/bridge/bridge4" ;;
bridge6) DEVICE_PATH="docs/devices/bridge/bridge6" ;;
aero) DEVICE_PATH="docs/devices/bridge/aero" ;;
click) DEVICE_PATH="docs/devices/click/click" ;;
scribble) DEVICE_PATH="docs/devices/scribble/scribble" ;;
*)
echo "::error::Unknown device: $DEVICE"
exit 1
;;
esac
echo "path=$DEVICE_PATH" >> "$GITHUB_OUTPUT"
echo "Resolved device '$DEVICE' to path '$DEVICE_PATH'"
- name: Parse firmware version
id: version
run: |
FW_VERSION="${{ github.event.client_payload.firmware_version }}"
# Extract major.minor from version string (e.g., "2.1.0" -> "2.1.x")
VERSION_DIR=$(echo "$FW_VERSION" | sed -E 's/^([0-9]+\.[0-9]+)\..*/\1.x/')
echo "dir=$VERSION_DIR" >> "$GITHUB_OUTPUT"
echo "Firmware $FW_VERSION -> directory $VERSION_DIR"
- name: Download artifact
env:
GH_TOKEN: ${{ secrets.BUILD_STATION_TOKEN }}
run: |
# Parse owner/repo, tag, and filename from the browser URL
# Format: https://github.com/{owner}/{repo}/releases/download/{tag}/{filename}
URL="${{ github.event.client_payload.docs_url }}"
SOURCE_REPO=$(echo "$URL" | sed -E 's|https://github.com/([^/]+/[^/]+)/releases/.*|\1|')
TAG=$(echo "$URL" | sed -E 's|.*/releases/download/([^/]+)/.*|\1|')
FILENAME=$(basename "$URL")
gh release download "$TAG" --repo "$SOURCE_REPO" --pattern "$FILENAME" --dir .
mv "$FILENAME" artifact.tar.gz
echo "Downloaded artifact ($(stat -c%s artifact.tar.gz) bytes)"
- name: Extract and place files
run: |
DEST="${{ steps.device.outputs.path }}/${{ steps.version.outputs.dir }}"
mkdir -p "$DEST"
tar -xzf artifact.tar.gz -C "$DEST" --strip-components=1
echo "Extracted to $DEST"
ls -la "$DEST"
- name: Ensure .pages file exists
run: |
PAGES_FILE="${{ steps.device.outputs.path }}/.pages"
if [ ! -f "$PAGES_FILE" ]; then
echo "order: desc" > "$PAGES_FILE"
echo "Created $PAGES_FILE"
fi
- name: Validate artifacts
run: |
DEST="${{ steps.device.outputs.path }}/${{ steps.version.outputs.dir }}"
# index.md must exist
if [ ! -f "$DEST/index.md" ]; then
echo "::error::Missing index.md in artifact"
exit 1
fi
# index.md must contain required sections
for section in "## Device Properties" "## Device Schema" "## Templates"; do
if ! grep -q "$section" "$DEST/index.md"; then
echo "::error::Missing section '$section' in index.md"
exit 1
fi
done
# render_templates() macro must be present
if ! grep -q 'render_templates()' "$DEST/index.md"; then
echo "::error::Missing render_templates() macro call in index.md"
exit 1
fi
# All .json files must be valid JSON
for f in "$DEST"/*.json; do
[ -f "$f" ] || continue
if ! python3 -c "import json; json.load(open('$f'))"; then
echo "::error::Invalid JSON: $f"
exit 1
fi
done
echo "All validations passed"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
- name: Install Python deps
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build check
run: mkdocs build --strict
- name: Commit and push
run: |
DEVICE="${{ github.event.client_payload.device }}"
VERSION="${{ steps.version.outputs.dir }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add "${{ steps.device.outputs.path }}/"
git commit -m "docs($DEVICE): update $VERSION device API docs
Automated update from firmware station dispatch.
Firmware version: ${{ github.event.client_payload.firmware_version }}
Device: $DEVICE"
git push
- name: Notify success
if: success()
run: |
DEVICE="${{ github.event.client_payload.device }}"
VERSION="${{ steps.version.outputs.dir }}"
FW_VERSION="${{ github.event.client_payload.firmware_version }}"
curl -s \
-H "Title: Docs updated: ${DEVICE} ${VERSION}" \
-H "Priority: min" \
-H "Tags: white_check_mark" \
-d "Device API docs for ${DEVICE} firmware ${FW_VERSION} deployed successfully.
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
"ntfy.sh/${{ secrets.NTFY_TOPIC }}"
- name: Notify failure
if: failure()
run: |
DEVICE="${{ github.event.client_payload.device }}"
FW_VERSION="${{ github.event.client_payload.firmware_version }}"
curl -s \
-H "Title: Docs update failed: ${DEVICE:-unknown}" \
-H "Priority: high" \
-H "Tags: x" \
-d "Failed to update Device API docs for ${DEVICE:-unknown device} firmware ${FW_VERSION:-unknown version}.
Check the run for details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
"ntfy.sh/${{ secrets.NTFY_TOPIC }}"