|
1 | | -name: Regenerate course overview |
| 1 | +name: Deploy locally generated course assets |
2 | 2 |
|
3 | 3 | on: |
4 | | - repository_dispatch: |
5 | | - types: [new_version] |
6 | 4 | push: |
7 | | - |
8 | | -env: |
9 | | - EXPORTFOLDER: 'assets' |
10 | | - REPOSITORYFOLDER: 'repository' |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - '*.html' |
| 8 | + - 'assets/**' |
| 9 | + - '*.yml' |
| 10 | + workflow_dispatch: |
11 | 11 |
|
12 | 12 | jobs: |
13 | | - prepare: |
| 13 | + deploy: |
14 | 14 | runs-on: ubuntu-latest |
15 | 15 | steps: |
16 | | - - name: Check out current repository |
| 16 | + - name: Check out repository |
17 | 17 | uses: actions/checkout@v3 |
18 | 18 | with: |
19 | | - path: repository |
20 | | - |
21 | | - - name: Delete and redefine folder for exports |
22 | | - run: | |
23 | | - rm -rf ${REPOSITORYFOLDER}/${EXPORTFOLDER} |
24 | | - mkdir -p ${REPOSITORYFOLDER}/${EXPORTFOLDER} |
25 | | -
|
26 | | - - name: Cache repository |
27 | | - uses: actions/cache@v3 |
28 | | - with: |
29 | | - path: repository |
30 | | - key: repository-${{ github.sha }} |
31 | | - |
32 | | - run_index: |
33 | | - needs: prepare |
34 | | - runs-on: ubuntu-latest |
35 | | - steps: |
36 | | - - name: Restore repository |
37 | | - uses: actions/cache@v3 |
38 | | - with: |
39 | | - path: repository |
40 | | - key: repository-${{ github.sha }} |
41 | | - |
42 | | - - name: Setup Node.js |
43 | | - uses: actions/setup-node@v3 |
44 | | - with: |
45 | | - node-version: '18' |
46 | | - # Removed npm cache that was causing failures |
47 | | - |
48 | | - - name: Install LiaScript exporter |
49 | | - run: npm install -g @liascript/exporter |
50 | | - |
51 | | - - name: Run exporter for index |
52 | | - run: | |
53 | | - cd ${REPOSITORYFOLDER} |
54 | | - liaex -i index.yml -o index --format project --project-category-blur |
55 | | -
|
56 | | - run_prozprog: |
57 | | - needs: prepare |
58 | | - runs-on: ubuntu-latest |
59 | | - steps: |
60 | | - - name: Restore repository |
61 | | - uses: actions/cache@v3 |
62 | | - with: |
63 | | - path: repository |
64 | | - key: repository-${{ github.sha }} |
65 | | - |
66 | | - - name: Setup Node.js |
67 | | - uses: actions/setup-node@v3 |
68 | | - with: |
69 | | - node-version: '18' |
70 | | - # Removed npm cache that was causing failures |
71 | | - |
72 | | - - name: Install LiaScript exporter |
73 | | - run: npm install -g @liascript/exporter |
74 | | - |
75 | | - - name: Run exporter for prozprog |
76 | | - run: | |
77 | | - cd ${REPOSITORYFOLDER} |
78 | | - liaex -i prozprog.yml -o prozprog --format project --project-generate-cache --project-generate-pdf --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur |
79 | | -
|
80 | | - run_softwareentwicklung: |
81 | | - needs: prepare |
82 | | - runs-on: ubuntu-latest |
83 | | - steps: |
84 | | - - name: Restore repository |
85 | | - uses: actions/cache@v3 |
86 | | - with: |
87 | | - path: repository |
88 | | - key: repository-${{ github.sha }} |
89 | | - |
90 | | - - name: Setup Node.js |
91 | | - uses: actions/setup-node@v3 |
92 | | - with: |
93 | | - node-version: '18' |
94 | | - # Removed npm cache that was causing failures |
95 | | - |
96 | | - - name: Install LiaScript exporter |
97 | | - run: npm install -g @liascript/exporter |
| 19 | + fetch-depth: 2 # Need previous commit to compare changes |
98 | 20 |
|
99 | | - - name: Run exporter for softwareentwicklung |
| 21 | + - name: Detect changed YAML files and missing HTML |
| 22 | + id: changes |
100 | 23 | run: | |
101 | | - cd ${REPOSITORYFOLDER} |
102 | | - liaex -i softwareentwicklung.yml -o softwareentwicklung --format project --project-generate-cache --project-generate-pdf --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur |
103 | | -
|
104 | | - run_robotikprojekt: |
105 | | - needs: prepare |
106 | | - runs-on: ubuntu-latest |
107 | | - steps: |
108 | | - - name: Restore repository |
109 | | - uses: actions/cache@v3 |
110 | | - with: |
111 | | - path: repository |
112 | | - key: repository-${{ github.sha }} |
113 | | - |
114 | | - - name: Setup Node.js |
| 24 | + echo "=== Detecting Changes ===" |
| 25 | + |
| 26 | + # Get changed YAML files from last commit |
| 27 | + changed_yamls=$(git diff --name-only HEAD~1 HEAD | grep '\.yml$' | grep -v '^\.github/' || true) |
| 28 | + echo "Changed YAML files: $changed_yamls" |
| 29 | + |
| 30 | + # Initialize arrays for processing |
| 31 | + courses_to_generate="" |
| 32 | + missing_html="" |
| 33 | + |
| 34 | + # Check each course YAML file |
| 35 | + for yaml_file in *.yml; do |
| 36 | + course_name=$(basename "$yaml_file" .yml) |
| 37 | + html_file="${course_name}.html" |
| 38 | + |
| 39 | + # Check if YAML was changed or HTML is missing |
| 40 | + if echo "$changed_yamls" | grep -q "$yaml_file" || [ ! -f "$html_file" ]; then |
| 41 | + echo "Course '$course_name' needs regeneration:" |
| 42 | + if echo "$changed_yamls" | grep -q "$yaml_file"; then |
| 43 | + echo " - YAML file was changed" |
| 44 | + fi |
| 45 | + if [ ! -f "$html_file" ]; then |
| 46 | + echo " - HTML file is missing" |
| 47 | + missing_html="$missing_html $course_name" |
| 48 | + fi |
| 49 | + courses_to_generate="$courses_to_generate $course_name" |
| 50 | + else |
| 51 | + echo "Course '$course_name' is up to date" |
| 52 | + fi |
| 53 | + done |
| 54 | + |
| 55 | + echo "courses_to_generate=$courses_to_generate" >> $GITHUB_OUTPUT |
| 56 | + echo "missing_html=$missing_html" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: Setup Node.js (if needed) |
| 59 | + if: steps.changes.outputs.courses_to_generate != '' |
115 | 60 | uses: actions/setup-node@v3 |
116 | 61 | with: |
117 | 62 | node-version: '18' |
118 | | - # Removed npm cache that was causing failures |
119 | 63 |
|
120 | | - - name: Install LiaScript exporter |
| 64 | + - name: Install LiaScript exporter (if needed) |
| 65 | + if: steps.changes.outputs.courses_to_generate != '' |
121 | 66 | run: npm install -g @liascript/exporter |
122 | 67 |
|
123 | | - - name: Run exporter for robotikprojekt |
| 68 | + - name: Generate missing course websites |
| 69 | + if: steps.changes.outputs.courses_to_generate != '' |
124 | 70 | run: | |
125 | | - cd ${REPOSITORYFOLDER} |
126 | | - liaex -i robotikprojekt.yml -o robotikprojekt --format project --project-generate-cache --project-generate-pdf --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur |
127 | | -
|
128 | | - run_digitalesysteme: |
129 | | - needs: prepare |
130 | | - runs-on: ubuntu-latest |
131 | | - steps: |
132 | | - - name: Restore repository |
133 | | - uses: actions/cache@v3 |
134 | | - with: |
135 | | - path: repository |
136 | | - key: repository-${{ github.sha }} |
137 | | - |
138 | | - - name: Setup Node.js |
139 | | - uses: actions/setup-node@v3 |
140 | | - with: |
141 | | - node-version: '18' |
142 | | - # Removed npm cache that was causing failures |
143 | | - |
144 | | - - name: Install LiaScript exporter |
145 | | - run: npm install -g @liascript/exporter |
146 | | - |
147 | | - - name: Run exporter for digitalesysteme |
| 71 | + echo "=== Generating Courses ===" |
| 72 | + courses="${{ steps.changes.outputs.courses_to_generate }}" |
| 73 | + |
| 74 | + for course in $courses; do |
| 75 | + yaml_file="${course}.yml" |
| 76 | + html_file="${course}.html" |
| 77 | + |
| 78 | + if [ -f "$yaml_file" ]; then |
| 79 | + echo "Generating $html_file from $yaml_file..." |
| 80 | + |
| 81 | + # Different parameters based on course type |
| 82 | + case "$course" in |
| 83 | + "index") |
| 84 | + liaex -i "$yaml_file" -o "$course" --format project --project-category-blur |
| 85 | + ;; |
| 86 | + "digitalesysteme"|"prozprog"|"softwareentwicklung"|"robotikprojekt") |
| 87 | + 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 |
| 88 | + ;; |
| 89 | + *) |
| 90 | + liaex -i "$yaml_file" -o "$course" --format project --project-category-blur |
| 91 | + ;; |
| 92 | + esac |
| 93 | + |
| 94 | + if [ -f "$html_file" ]; then |
| 95 | + echo "✅ Successfully generated $html_file" |
| 96 | + else |
| 97 | + echo "❌ Failed to generate $html_file" |
| 98 | + fi |
| 99 | + else |
| 100 | + echo "⚠️ YAML file $yaml_file not found" |
| 101 | + fi |
| 102 | + done |
| 103 | +
|
| 104 | + - name: Display deployment summary |
148 | 105 | run: | |
149 | | - cd ${REPOSITORYFOLDER} |
150 | | - liaex -i digitalesysteme.yml -o digitalesysteme --format project --project-generate-cache --project-generate-pdf --project-generate-scorm2004 --scorm-organization "TU-Bergakademie Freiberg" --scorm-embed --scorm-masteryScore 80 --project-category-blur |
151 | | -
|
152 | | - commit_changes: |
153 | | - needs: |
154 | | - [ |
155 | | - run_index, |
156 | | - run_prozprog, |
157 | | - run_softwareentwicklung, |
158 | | - run_robotikprojekt, |
159 | | - run_digitalesysteme, |
160 | | - ] |
161 | | - runs-on: ubuntu-latest |
162 | | - steps: |
163 | | - - name: Restore repository |
164 | | - uses: actions/cache@v3 |
165 | | - with: |
166 | | - path: repository |
167 | | - key: repository-${{ github.sha }} |
168 | | - |
169 | | - - name: Commit and push changes |
170 | | - run: | |
171 | | - cd ${REPOSITORYFOLDER} |
172 | | - git config --local user.email "action@github.com" |
173 | | - git config --local user.name "GitHub Action" |
174 | | - git add . |
175 | | - git commit -m "Add new export version of courses" || echo "No changes to commit" |
176 | | -
|
177 | | - # Fix authentication by updating remote URL with token |
178 | | - git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git |
179 | | - git push |
180 | | - env: |
181 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + echo "=== Deployment Summary ===" |
| 107 | + echo "HTML files to deploy:" |
| 108 | + ls -la *.html 2>/dev/null || echo "No HTML files" |
| 109 | + echo "" |
| 110 | + echo "Asset directories:" |
| 111 | + find assets/ -type d 2>/dev/null || echo "No asset directories" |
| 112 | + echo "" |
| 113 | + echo "PDF counts per course:" |
| 114 | + for dir in assets/*/pdf 2>/dev/null; do |
| 115 | + if [ -d "$dir" ]; then |
| 116 | + course=$(basename $(dirname "$dir")) |
| 117 | + count=$(ls -1 "$dir"/*.pdf 2>/dev/null | wc -l) |
| 118 | + echo " $course: $count PDFs" |
| 119 | + fi |
| 120 | + done |
| 121 | + |
| 122 | + echo "" |
| 123 | + echo "Generated in this run:" |
| 124 | + courses="${{ steps.changes.outputs.courses_to_generate }}" |
| 125 | + if [ -n "$courses" ]; then |
| 126 | + for course in $courses; do |
| 127 | + echo " - $course" |
| 128 | + done |
| 129 | + else |
| 130 | + echo " - No courses needed regeneration" |
| 131 | + fi |
| 132 | + echo "=== End Summary ===" |
0 commit comments