-
Notifications
You must be signed in to change notification settings - Fork 7
162 lines (145 loc) · 6.99 KB
/
Copy pathgenerate-pdfs.yml
File metadata and controls
162 lines (145 loc) · 6.99 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
name: Generate Documentation PDFs
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag name for the release (e.g., v1.2.3)'
required: true
release_name:
description: 'Release title'
required: false
body:
description: 'Release notes/body'
required: false
prerelease:
description: 'Mark as prerelease'
type: boolean
required: false
default: false
jobs:
generate-pdfs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '19'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Chrome for Puppeteer
run: |
sudo apt-get update
sudo apt-get install -y chromium-browser xvfb
- name: Configure Chrome for headless mode
run: |
echo "PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser" >> $GITHUB_ENV
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Start virtual display
run: |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- name: Enable PDF generation in config
run: |
sed -i 's/autoBuildPdfs: false/autoBuildPdfs: true/' docusaurus.config.js
- name: Build documentation with PDFs
run: npm run build
- name: Create PDF artifacts directory structure
run: |
mkdir -p pdf-artifacts/CoreBox
mkdir -p pdf-artifacts/ElectronicsBox
mkdir -p pdf-artifacts/InfinityBox
mkdir -p pdf-artifacts/DiscoveryFluorescence
mkdir -p pdf-artifacts/LightsheetBox
mkdir -p pdf-artifacts/QBox
mkdir -p pdf-artifacts/SeeedMicroscope
- name: Copy generated PDFs
run: |
if [ -d "build/pdfs" ]; then
cp -r build/pdfs/* pdf-artifacts/ 2>/dev/null || true
find build/pdfs -name "*CoreBox*EN*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*CoreBox*DE*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*CoreBox*FR*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*CoreBox*ES*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*CoreBox*AR*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*core*" -exec cp {} pdf-artifacts/CoreBox/ \; 2>/dev/null || true
find build/pdfs -name "*Electronics*" -exec cp {} pdf-artifacts/ElectronicsBox/ \; 2>/dev/null || true
find build/pdfs -name "*electronics*" -exec cp {} pdf-artifacts/ElectronicsBox/ \; 2>/dev/null || true
find build/pdfs -name "*Infinity*" -exec cp {} pdf-artifacts/InfinityBox/ \; 2>/dev/null || true
find build/pdfs -name "*infinity*" -exec cp {} pdf-artifacts/InfinityBox/ \; 2>/dev/null || true
find build/pdfs -name "*Fluorescence*" -exec cp {} pdf-artifacts/DiscoveryFluorescence/ \; 2>/dev/null || true
find build/pdfs -name "*fluorescence*" -exec cp {} pdf-artifacts/DiscoveryFluorescence/ \; 2>/dev/null || true
find build/pdfs -name "*Lightsheet*" -exec cp {} pdf-artifacts/LightsheetBox/ \; 2>/dev/null || true
find build/pdfs -name "*lightsheet*" -exec cp {} pdf-artifacts/LightsheetBox/ \; 2>/dev/null || true
find build/pdfs -name "*QBox*" -exec cp {} pdf-artifacts/QBox/ \; 2>/dev/null || true
find build/pdfs -name "*qbox*" -exec cp {} pdf-artifacts/QBox/ \; 2>/dev/null || true
find build/pdfs -name "*Seeed*" -exec cp {} pdf-artifacts/SeeedMicroscope/ \; 2>/dev/null || true
find build/pdfs -name "*seeed*" -exec cp {} pdf-artifacts/SeeedMicroscope/ \; 2>/dev/null || true
echo "Generated PDFs:"
find pdf-artifacts -name "*.pdf" -type f | sort
PDF_COUNT=$(find pdf-artifacts -name "*.pdf" -type f | wc -l)
echo "Total PDFs generated: $PDF_COUNT"
else
echo "No PDFs directory found in build output"
echo "Checking build structure:"
ls -la build/ 2>/dev/null || echo "No build directory found"
fi
- name: Upload PDFs as artifacts
uses: actions/upload-artifact@v7
with:
name: documentation-pdfs-${{ github.run_number }}
path: pdf-artifacts/
if-no-files-found: warn
- name: Prepare release variables
id: relvars
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
TITLE="${{ inputs.release_name != '' && inputs.release_name || inputs.tag }}"
BODY='${{ inputs.body }}'
if [ -z "$BODY" ]; then BODY=""; fi
echo "title=$TITLE" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "prerelease=${{ inputs.prerelease && 'true' || 'false' }}" >> $GITHUB_OUTPUT
else
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
echo "title=${{ github.event.release.name }}" >> $GITHUB_OUTPUT
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "${{ github.event.release.body }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "prerelease=${{ github.event.release.prerelease && 'true' || 'false' }}" >> $GITHUB_OUTPUT
fi
- name: Create/update release and upload PDFs
if: hashFiles('pdf-artifacts/**/*.pdf') != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
# create or update release
if gh release view "${{ steps.relvars.outputs.tag }}" >/dev/null 2>&1; then
gh release edit "${{ steps.relvars.outputs.tag }}" \
--title "${{ steps.relvars.outputs.title }}" \
--notes "${{ steps.relvars.outputs.body }}" \
$([ "${{ steps.relvars.outputs.prerelease }}" = "true" ] && echo "--prerelease" || echo "--draft=false")
else
gh release create "${{ steps.relvars.outputs.tag }}" \
--title "${{ steps.relvars.outputs.title }}" \
--notes "${{ steps.relvars.outputs.body }}" \
$([ "${{ steps.relvars.outputs.prerelease }}" = "true" ] && echo "--prerelease")
fi
# upload assets (retry to avoid transient failures)
for f in $(find pdf-artifacts -type f -name '*.pdf'); do
echo "Uploading $f"
for i in 1 2 3; do
if gh release upload "${{ steps.relvars.outputs.tag }}" "$f" --clobber; then
break
fi
echo "Retry $i for $f ..."
sleep 2
done
done