Update ci.yml #2181
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: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| actions: write | |
| checks: write | |
| contents: write | |
| deployments: write | |
| id-token: write | |
| issues: write | |
| discussions: write | |
| packages: write | |
| pages: write | |
| pull-requests: write | |
| repository-projects: write | |
| security-events: write | |
| statuses: write | |
| jobs: | |
| linter: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| path: modules | |
| - uses: leafo/gh-actions-lua@v8.0.0 | |
| with: | |
| luaVersion: 5.2 | |
| - uses: leafo/gh-actions-luarocks@v4.0.0 | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: LiliaFramework/GluaCheck | |
| path: luacheck | |
| - run: luarocks make | |
| working-directory: luacheck | |
| - run: | | |
| luacheck . \ | |
| --no-redefined \ | |
| --no-global --no-self \ | |
| --no-max-line-length --no-max-code-line-length \ | |
| --no-max-string-line-length --no-max-comment-line-length | |
| working-directory: modules | |
| scrape-modules: | |
| needs: linter | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - run: sudo apt-get update && sudo apt-get install -y jq zip | |
| - name: extract-module-metadata | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| parse_list() { | |
| local s="$1" | |
| [ -z "$s" ] && { printf '[]'; return; } | |
| if [[ $s == \{* ]]; then | |
| s=$(echo "$s" | tr -d '\n' | sed -E 's/^\{//;s/\}$//') | |
| IFS=',' read -ra arr <<< "$s" | |
| printf '[' | |
| for idx in "${!arr[@]}"; do | |
| entry=$(echo "${arr[$idx]}" | sed -E 's/^\s*"|"\s*$//g') | |
| printf '"%s"' "$entry" | |
| [ "$idx" -lt $(( ${#arr[@]} - 1 )) ] && printf ',' | |
| done | |
| printf ']' | |
| else | |
| s=$(echo "$s" | sed -E 's/^\s*"|"\s*$//g') | |
| [ -z "$s" ] && { printf '[]'; return; } | |
| printf '["%s"]' "$s" | |
| fi | |
| } | |
| echo '[]' > modules_data.json | |
| for m in */module.lua; do | |
| [ -f "$m" ] || continue | |
| dir=${m%%/*} | |
| name_key=$(grep -Po 'MODULE\.name\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| uniqueid=$(grep -Po 'MODULE\.versionID\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| author=$(grep -Po 'MODULE\.author\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| discord=$(grep -Po 'MODULE\.discord\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| desc_key=$(grep -Po 'MODULE\.desc\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| lang_file="$dir/languages/english.lua" | |
| if [ -f "$lang_file" ]; then | |
| name=$(grep -Po "\\b${name_key}\\s*=\\s*\"\\K[^\"]*" "$lang_file" | head -n1 || true) | |
| desc=$(grep -Po "\\b${desc_key}\\s*=\\s*\"\\K[^\"]*" "$lang_file" | head -n1 || true) | |
| fi | |
| [ -z "$name" ] && name="$name_key" | |
| [ -z "$desc" ] && desc="$desc_key" | |
| version=$(grep -Po 'MODULE\.version\s*=\s*[0-9]+(\.[0-9]{2})?' "$m" | sed -E 's/.*=\s*//' || true) | |
| [ -z "$version" ] && version="0.00" | |
| rawf=$(grep -Po 'MODULE\.Features\s*=\s*(\{[^}]*\}|"[^"]*")' "$m" | head -n1 | sed -E 's/^[^=]+=\s*//' || true) | |
| raww=$(grep -Po 'MODULE\.WorkshopContent\s*=\s*(\{[^}]*\}|"[^"]*")' "$m" | head -n1 | sed -E 's/^[^=]+=\s*//' || true) | |
| feat=$(parse_list "$rawf") | |
| work=$(parse_list "$raww") | |
| jq --arg name "$name" \ | |
| --arg versionID "$uniqueid" \ | |
| --arg author "$author" \ | |
| --arg discord "$discord" \ | |
| --arg desc "$desc" \ | |
| --arg version "$version" \ | |
| --arg download "https://github.com/LiliaFramework/Modules/raw/refs/heads/gh-pages/${dir}.zip" \ | |
| --arg source "https://liliaframework.github.io/Modules/${dir}.html" \ | |
| --argjson features "$feat" \ | |
| --argjson workshop "$work" \ | |
| '. += [{name:$name,versionID:$versionID,author:$author,discord:$discord,description:$desc,version:$version,download:$download,source:$source,features:$features,workshop:$workshop}]' modules_data.json > tmp.json | |
| mv tmp.json modules_data.json | |
| done | |
| - name: zip-modules | |
| shell: bash | |
| run: | | |
| for d in */; do | |
| [ -d "$d" ] && zip -r "${d%/}.zip" "$d" | |
| done | |
| - name: run-scrap-script | |
| run: node scrap_modules.js | |
| - name: move-json | |
| run: mv modules_data.json modules.json | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: module-zips | |
| path: ./*.zip | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: modules-json | |
| path: modules.json | |
| gh-pages: | |
| needs: scrape-modules | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: create-docs-dir | |
| run: mkdir -p documentation | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: module-zips | |
| path: documentation | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: modules-json | |
| path: documentation | |
| - name: unzip-modules | |
| shell: bash | |
| run: | | |
| for z in documentation/*.zip; do | |
| f=$(basename "$z" .zip) | |
| unzip "$z" -d "extracted_${f}" | |
| done | |
| - name: gather-module-docs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| shopt -s nullglob | |
| for d in extracted_*; do | |
| [ -d "$d" ] || continue | |
| mod=${d#extracted_} | |
| echo "Processing module: $mod (directory: $d)" | |
| echo "Contents of $d:" | |
| ls -la "$d/" | head -10 | |
| name=$(jq -r --arg id "$mod" '.[] | select(.versionID==$id) | .name' documentation/modules.json || echo '') | |
| if [ -n "$name" ]; then | |
| folder=$(echo "$name" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/_/g' | sed -E 's/^_+|_+$//g') | |
| else | |
| folder="$mod" | |
| fi | |
| dest="documentation/docs/modules/${folder}" | |
| mkdir -p "$dest" | |
| # Copy module's README.md as about.md | |
| # Try multiple possible locations and case variations | |
| readme_file="" | |
| if [ -f "$d/README.md" ]; then | |
| readme_file="$d/README.md" | |
| elif [ -f "$d/readme.md" ]; then | |
| readme_file="$d/readme.md" | |
| else | |
| # Look for README in subdirectories (max depth 1) | |
| readme_file=$(find "$d" -maxdepth 2 -type f \( -iname "readme.md" -o -iname "readme.txt" \) | head -n 1 || true) | |
| fi | |
| if [ -n "$readme_file" ] && [ -f "$readme_file" ]; then | |
| cp "$readme_file" "$dest/about.md" | |
| echo "Copied $readme_file to $dest/about.md for module $mod" | |
| else | |
| echo "No README found for module $mod in $d" | |
| fi | |
| # Copy existing docs if they exist | |
| doc_dir=$(find "$d" -type d -iname docs -maxdepth 2 -print -quit || true) | |
| if [ -n "$doc_dir" ]; then | |
| find "$doc_dir" -maxdepth 1 -type f -name '*.md' -exec cp {} "$dest/" \; | |
| # Look for changelog files in docs folder | |
| changelog_file="" | |
| for possible_changelog in "$doc_dir/CHANGELOG.md" "$doc_dir/changelog.md" "$doc_dir/CHANGELOG.txt" "$doc_dir/changelog.txt" "$doc_dir/HISTORY.md" "$doc_dir/history.md"; do | |
| if [ -f "$possible_changelog" ]; then | |
| changelog_file="$possible_changelog" | |
| break | |
| fi | |
| done | |
| # Also check for changelog files in module root if not found in docs | |
| if [ -z "$changelog_file" ]; then | |
| for possible_changelog in "$d/CHANGELOG.md" "$d/changelog.md" "$d/CHANGELOG.txt" "$d/changelog.txt" "$d/HISTORY.md" "$d/history.md"; do | |
| if [ -f "$possible_changelog" ]; then | |
| changelog_file="$possible_changelog" | |
| break | |
| fi | |
| done | |
| fi | |
| # Copy changelog with standard name if found | |
| if [ -n "$changelog_file" ]; then | |
| cp "$changelog_file" "$dest/changelog.md" | |
| echo "Copied changelog from $changelog_file to $dest/changelog.md for module $mod" | |
| fi | |
| fi | |
| done | |
| shopt -u nullglob | |
| - name: clean-obsolete-docs | |
| run: | | |
| rm -rf documentation/docs/hooks/modules | |
| rm -rf documentation/docs/libraries/modules | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: built-docs | |
| path: documentation | |
| - name: remove-docs-before-publish | |
| run: rm -rf documentation/docs | |
| - name: remove-modules-json-before-publish | |
| run: rm -f documentation/modules.json | |
| - uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.LiliaGitSecret }} | |
| publish_branch: gh-pages | |
| publish_dir: documentation | |
| force_orphan: true | |
| upload-docs: | |
| needs: gh-pages | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: built-docs | |
| path: built-docs | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: LiliaFramework/Lilia | |
| token: ${{ secrets.LiliaGitSecret }} | |
| path: lilia | |
| fetch-depth: 0 | |
| - name: delete-old-modules | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| rm -rf lilia/documentation/docs/modules | |
| - name: copy-built-docs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p lilia/documentation | |
| if [ -d built-docs/documentation ]; then | |
| rsync -a built-docs/documentation/ lilia/documentation/ | |
| else | |
| rsync -a built-docs/ lilia/documentation/ | |
| fi | |
| mkdir -p lilia/documentation/docs/versioning | |
| if [ -f lilia/documentation/modules.json ]; then | |
| mv lilia/documentation/modules.json lilia/documentation/docs/versioning/modules.json | |
| fi | |
| - name: commit-push-docs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| cd lilia | |
| git config user.email "githubactions@github.com" | |
| git config user.name "GitHub Actions" | |
| git add -A . | |
| if git diff --cached --quiet; then | |
| echo "No documentation changes to commit" | |
| else | |
| git commit -m "Updated Some Public Modules" | |
| git push https://x-access-token:${{ secrets.LiliaGitSecret }}@github.com/LiliaFramework/Lilia.git HEAD:main | |
| fi |