Skip to content

Commit 88bf1c7

Browse files
committed
DevOps-Cheatsheet: feat(ci): Enhance PDF Generation Workflow
Add advanced PDF generation pipeline with improved features and automation: Features: - Selective category-based PDF generation - Custom PDF styling and formatting - Table of contents and metadata - Automatic versioning and releases - PDF caching for improved performance - Documentation auto-updates Technical Improvements: - Added workflow_dispatch for manual triggers - Implemented caching system for faster builds - Enhanced PDF formatting with LaTeX - Added error handling and logging - Automated release creation with versioning - Improved file organization and naming Configuration: - Custom headers and footers - Professional PDF styling - Code syntax highlighting - Category-based organization - Automated README updates - ZIP archive creation Environment: - Updated Node.js setup - Added required LaTeX packages - Configured GitHub token permissions - Set up PDF caching system Signed-off-by: NotHarshhaa <[email protected]>
1 parent aaace99 commit 88bf1c7

File tree

1 file changed

+173
-17
lines changed

1 file changed

+173
-17
lines changed

.github/workflows/generate-pdf.yml

Lines changed: 173 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,192 @@
1-
name: Generate PDFs
1+
name: DevOps Cheatsheet PDF Generator
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ main, master ]
6+
paths:
7+
- '**/*.md'
8+
- '.github/workflows/generate-pdf.yml'
79
pull_request:
8-
branches:
9-
- master
10+
branches: [ main, master ]
11+
paths:
12+
- '**/*.md'
1013
workflow_dispatch:
14+
inputs:
15+
specific_category:
16+
description: 'Generate PDFs for specific category (leave empty for all)'
17+
required: false
18+
type: string
1119

1220
jobs:
13-
pdf:
21+
generate-pdfs:
22+
name: Generate Cheatsheet PDFs
1423
runs-on: ubuntu-latest
15-
24+
1625
steps:
17-
- name: Checkout code
26+
- name: Checkout Repository
1827
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '18'
35+
cache: 'npm'
1936

20-
- name: Install pandoc and LaTeX
37+
- name: Install Dependencies
2138
run: |
2239
sudo apt-get update
23-
sudo apt-get install -y pandoc
24-
sudo apt-get install -y texlive-xetex
40+
sudo apt-get install -y pandoc texlive-xetex texlive-fonts-recommended texlive-fonts-extra
41+
42+
- name: Cache PDF Generation
43+
uses: actions/cache@v3
44+
with:
45+
path: |
46+
.pdf-cache
47+
key: ${{ runner.os }}-pdf-${{ hashFiles('**/*.md') }}
48+
restore-keys: |
49+
${{ runner.os }}-pdf-
50+
51+
- name: Setup PDF Directory
52+
run: |
53+
mkdir -p pdfs
54+
mkdir -p .pdf-cache
2555
26-
- name: Generate PDF
56+
- name: Generate PDFs
2757
run: |
28-
for file in $(find . -name '*.md'); do
29-
pandoc "$file" -o "${file%.md}.pdf" --pdf-engine=xelatex
58+
# Function to generate PDF with custom styling
59+
generate_pdf() {
60+
local input_file="$1"
61+
local output_file="$2"
62+
local category="$(dirname "$input_file" | sed 's/.\///')"
63+
local title="$(basename "$input_file" .md)"
64+
65+
# Create header with metadata
66+
cat > header.yaml <<EOF
67+
---
68+
title: "${title//-/ } Cheatsheet"
69+
author: "DevOps Cheatsheet Hub"
70+
date: "$(date +'%B %d, %Y')"
71+
geometry: margin=2cm
72+
colorlinks: true
73+
linkcolor: blue
74+
urlcolor: blue
75+
toccolor: blue
76+
toc: true
77+
toc-depth: 2
78+
category: "${category}"
79+
header-includes:
80+
- \usepackage{fancyhdr}
81+
- \pagestyle{fancy}
82+
- \fancyhead[L]{DevOps Cheatsheet Hub}
83+
- \fancyhead[R]{${category}}
84+
- \fancyfoot[C]{\thepage}
85+
---
86+
EOF
87+
88+
# Combine header with content and generate PDF
89+
cat header.yaml "$input_file" | pandoc \
90+
-f markdown \
91+
-t pdf \
92+
--pdf-engine=xelatex \
93+
--highlight-style=tango \
94+
-o "$output_file" \
95+
--toc \
96+
--toc-depth=2 \
97+
--variable=geometry:margin=2cm
98+
}
99+
100+
# Process files based on input
101+
if [ -n "${{ github.event.inputs.specific_category }}" ]; then
102+
category="${{ github.event.inputs.specific_category }}"
103+
echo "Generating PDFs for category: $category"
104+
for file in "$category"/*.md; do
105+
if [ -f "$file" ]; then
106+
output_file="pdfs/$(basename "${file%.md}.pdf")"
107+
if [ ! -f ".pdf-cache/$(basename "$output_file")" ] || [ "$file" -nt ".pdf-cache/$(basename "$output_file")" ]; then
108+
echo "Generating PDF for $file"
109+
generate_pdf "$file" "$output_file"
110+
cp "$output_file" ".pdf-cache/"
111+
else
112+
echo "Using cached version for $file"
113+
cp ".pdf-cache/$(basename "$output_file")" "$output_file"
114+
fi
115+
fi
116+
done
117+
else
118+
echo "Generating PDFs for all categories"
119+
for file in */*.md; do
120+
if [ -f "$file" ]; then
121+
output_file="pdfs/$(dirname "$file")-$(basename "${file%.md}.pdf")"
122+
if [ ! -f ".pdf-cache/$(basename "$output_file")" ] || [ "$file" -nt ".pdf-cache/$(basename "$output_file")" ]; then
123+
echo "Generating PDF for $file"
124+
generate_pdf "$file" "$output_file"
125+
cp "$output_file" ".pdf-cache/"
126+
else
127+
echo "Using cached version for $file"
128+
cp ".pdf-cache/$(basename "$output_file")" "$output_file"
129+
fi
130+
fi
131+
done
132+
fi
133+
134+
- name: Create PDF Index
135+
run: |
136+
echo "# DevOps Cheatsheet PDFs" > pdfs/index.md
137+
echo "Generated on: $(date +'%B %d, %Y')" >> pdfs/index.md
138+
echo "" >> pdfs/index.md
139+
140+
for category in */; do
141+
if [ -d "$category" ]; then
142+
echo "## ${category%/}" >> pdfs/index.md
143+
for pdf in pdfs/${category%/}*.pdf; do
144+
if [ -f "$pdf" ]; then
145+
name=$(basename "$pdf" .pdf | sed 's/-/ /g')
146+
echo "- [$name]($pdf)" >> pdfs/index.md
147+
fi
148+
done
149+
echo "" >> pdfs/index.md
150+
fi
30151
done
31152
32-
- name: Upload PDF artifacts
153+
- name: Upload Individual PDFs
33154
uses: actions/upload-artifact@v4
34155
with:
35-
name: pdfs
36-
path: '**/*.pdf'
156+
name: cheatsheet-pdfs
157+
path: pdfs/*.pdf
158+
retention-days: 30
159+
160+
- name: Create Release
161+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
162+
run: |
163+
# Zip all PDFs
164+
cd pdfs
165+
zip -r ../cheatsheets.zip *.pdf
166+
cd ..
167+
168+
# Create release tag
169+
TAG="v$(date +'%Y.%m.%d-%H%M')"
170+
gh release create "$TAG" \
171+
--title "DevOps Cheatsheets $TAG" \
172+
--notes-file pdfs/index.md \
173+
cheatsheets.zip
174+
env:
175+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
176+
177+
- name: Update Documentation
178+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
179+
run: |
180+
git config --local user.email "[email protected]"
181+
git config --local user.name "GitHub Action"
182+
183+
# Update README with latest PDF links
184+
sed -i '/## Available PDFs/q' README.md
185+
echo "" >> README.md
186+
cat pdfs/index.md >> README.md
187+
188+
# Commit and push if there are changes
189+
git add README.md
190+
git diff --quiet && git diff --staged --quiet || (git commit -m "docs: Update PDF links [skip ci]" && git push)
191+
env:
192+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

0 commit comments

Comments
 (0)