Add PDF file #107
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
| name: Deploy locally generated course assets | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - '*.html' | |
| - 'assets/**' | |
| - '*.yml' | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 2 # Need previous commit to compare changes | |
| - name: Detect changed YAML files and missing HTML | |
| id: changes | |
| run: | | |
| echo "=== Detecting Changes ===" | |
| # Get changed YAML files from last commit | |
| changed_yamls=$(git diff --name-only HEAD~1 HEAD | grep '\.yml$' | grep -v '^\.github/' || true) | |
| echo "Changed YAML files: $changed_yamls" | |
| # Initialize arrays for processing | |
| courses_to_generate="" | |
| missing_html="" | |
| # Check each course YAML file | |
| for yaml_file in *.yml; do | |
| course_name=$(basename "$yaml_file" .yml) | |
| html_file="${course_name}.html" | |
| # Check if YAML was changed or HTML is missing | |
| if echo "$changed_yamls" | grep -q "$yaml_file" || [ ! -f "$html_file" ]; then | |
| echo "Course '$course_name' needs regeneration:" | |
| if echo "$changed_yamls" | grep -q "$yaml_file"; then | |
| echo " - YAML file was changed" | |
| fi | |
| if [ ! -f "$html_file" ]; then | |
| echo " - HTML file is missing" | |
| missing_html="$missing_html $course_name" | |
| fi | |
| courses_to_generate="$courses_to_generate $course_name" | |
| else | |
| echo "Course '$course_name' is up to date" | |
| fi | |
| done | |
| echo "courses_to_generate=$courses_to_generate" >> $GITHUB_OUTPUT | |
| echo "missing_html=$missing_html" >> $GITHUB_OUTPUT | |
| - name: Setup Node.js (if needed) | |
| if: steps.changes.outputs.courses_to_generate != '' | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| - name: Install LiaScript exporter (if needed) | |
| if: steps.changes.outputs.courses_to_generate != '' | |
| run: npm install -g @liascript/exporter | |
| - name: Generate missing course websites | |
| if: steps.changes.outputs.courses_to_generate != '' | |
| run: | | |
| echo "=== Generating Courses ===" | |
| courses="${{ steps.changes.outputs.courses_to_generate }}" | |
| for course in $courses; do | |
| yaml_file="${course}.yml" | |
| html_file="${course}.html" | |
| if [ -f "$yaml_file" ]; then | |
| echo "Generating $html_file from $yaml_file..." | |
| # Different parameters based on course type | |
| # Check if PDFs already exist | |
| pdf_dir="assets/${course}/pdf" | |
| needs_pdfs=false | |
| if [ "$course" != "index" ]; then | |
| if [ ! -d "$pdf_dir" ] || [ -z "$(ls -A $pdf_dir 2>/dev/null)" ]; then | |
| needs_pdfs=true | |
| echo "📄 PDFs missing for $course - will generate" | |
| else | |
| echo "✅ PDFs already exist for $course - skipping generation" | |
| fi | |
| fi | |
| case "$course" in | |
| "index") | |
| liaex -i "$yaml_file" -o "$course" --format project --project-category-blur | |
| ;; | |
| "digitalesysteme"|"prozprog"|"softwareentwicklung"|"robotikprojekt") | |
| if [ "$needs_pdfs" = true ]; then | |
| echo "🔨 Generating course with PDFs..." | |
| liaex -i "$yaml_file" -o "$course" --format project --project-generate-cache --project-generate-pdf --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur | |
| else | |
| echo "🔨 Generating course without PDFs..." | |
| liaex -i "$yaml_file" -o "$course" --format project --project-generate-cache --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur | |
| fi | |
| ;; | |
| *) | |
| liaex -i "$yaml_file" -o "$course" --format project --project-category-blur | |
| ;; | |
| esac | |
| if [ -f "$html_file" ]; then | |
| echo "✅ Successfully generated $html_file" | |
| else | |
| echo "❌ Failed to generate $html_file" | |
| fi | |
| else | |
| echo "⚠️ YAML file $yaml_file not found" | |
| fi | |
| done | |
| - name: Display deployment summary | |
| run: | | |
| echo "=== Deployment Summary ===" | |
| echo "HTML files to deploy:" | |
| ls -la *.html 2>/dev/null || echo "No HTML files" | |
| echo "" | |
| echo "Asset directories:" | |
| find assets/ -type d 2>/dev/null || echo "No asset directories" | |
| echo "" | |
| echo "PDF counts per course:" | |
| for dir in assets/*/pdf; do | |
| if [ -d "$dir" ] 2>/dev/null; then | |
| course=$(basename $(dirname "$dir")) | |
| count=$(ls -1 "$dir"/*.pdf 2>/dev/null | wc -l) | |
| echo " $course: $count PDFs" | |
| fi | |
| done 2>/dev/null || echo " No PDF directories found" | |
| echo "" | |
| echo "Generated in this run:" | |
| courses="${{ steps.changes.outputs.courses_to_generate }}" | |
| if [ -n "$courses" ]; then | |
| for course in $courses; do | |
| echo " - $course" | |
| done | |
| else | |
| echo " - No courses needed regeneration" | |
| fi | |
| echo "=== End Summary ===" |