forked from qiwihui/codelabs-site-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Add automated PDF generation workflow for documentation printing #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| name: Generate Documentation PDFs | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: # Allow manual triggering | ||
|
|
||
| jobs: | ||
| generate-pdfs: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| 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 | ||
| # Copy all PDFs to main artifacts directory | ||
| cp -r build/pdfs/* pdf-artifacts/ 2>/dev/null || true | ||
|
|
||
| # Organize PDFs by toolbox if they exist | ||
| # CoreBox PDFs for different languages | ||
| 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 | ||
|
|
||
| # Other toolbox PDFs | ||
| 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 | ||
|
|
||
| # List what was found | ||
| echo "Generated PDFs:" | ||
| find pdf-artifacts -name "*.pdf" -type f | sort | ||
|
|
||
| # Count PDFs | ||
| 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@v4 | ||
| with: | ||
| name: documentation-pdfs-${{ github.run_number }} | ||
| path: pdf-artifacts/ | ||
| if-no-files-found: warn | ||
|
|
||
| - name: Attach PDFs to release | ||
| if: github.event_name == 'release' && hashFiles('pdf-artifacts/**/*.pdf') != '' | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| files: pdf-artifacts/**/*.pdf | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Documentation PDF Generation | ||
|
|
||
| This repository now includes automated PDF generation for all toolbox documentation using the [docusaurus-plugin-papersaurus](https://github.com/simologos/docusaurus-plugin-papersaurus) plugin. | ||
|
|
||
| ## How it works | ||
|
|
||
| 1. **Automatic Generation**: PDFs are automatically generated when a new release is published via GitHub Actions | ||
| 2. **Manual Trigger**: The workflow can also be manually triggered from the Actions tab | ||
| 3. **Organized Output**: PDFs are organized by toolbox type for easy access | ||
|
|
||
| ## Generated PDFs | ||
|
|
||
| The workflow generates PDFs for the following documentation: | ||
|
|
||
| ### CoreBox (with language variants) | ||
| - English documentation | ||
| - German documentation (Deutsch) | ||
| - French documentation (Français) | ||
| - Spanish documentation (Español) | ||
| - Arabian documentation | ||
|
|
||
| ### Other Toolboxes | ||
| - ElectronicsBox | ||
| - InfinityBox | ||
| - DiscoveryFluorescence | ||
| - LightsheetBox | ||
| - QBox | ||
| - SeeedMicroscope | ||
|
|
||
| ## Accessing PDFs | ||
|
|
||
| Generated PDFs are available in two ways: | ||
|
|
||
| 1. **Release Assets**: Attached to each GitHub release | ||
| 2. **Workflow Artifacts**: Available as artifacts from the GitHub Actions workflow | ||
|
|
||
| ## For Maintainers | ||
|
|
||
| ### Manual PDF Generation | ||
|
|
||
| To manually generate PDFs locally (requires Chrome/Chromium): | ||
|
|
||
| 1. Install Chrome or Chromium browser | ||
| 2. Set environment variable: `export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser` | ||
| 3. Enable PDF generation in `docusaurus.config.js`: `autoBuildPdfs: true` | ||
| 4. Run: `npm run build` | ||
| 5. PDFs will be generated in `build/pdfs/` | ||
|
|
||
| ### Workflow Configuration | ||
|
|
||
| The PDF generation workflow is located at `.github/workflows/generate-pdfs.yml` and: | ||
|
|
||
| - Installs required dependencies including Chrome | ||
| - Builds the documentation with PDF generation enabled | ||
| - Organizes PDFs by toolbox type | ||
| - Uploads artifacts and attaches to releases | ||
|
|
||
| ## Technical Details | ||
|
|
||
| - **Plugin**: docusaurus-plugin-papersaurus v2.0.3 | ||
| - **PDF Engine**: Puppeteer with Chrome/Chromium | ||
| - **Organization**: Automated sorting by toolbox folder structure | ||
| - **Trigger**: Release events and manual workflow dispatch | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.