XD #2154
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: | |
| strip-comments: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - run: | | |
| curl -sSfL https://raw.githubusercontent.com/bleonheart/Useful-Python-Scripts/refs/heads/main/files/remove_lua_comments.py -o remove_lua_comments.py || curl -sSfL https://raw.githubusercontent.com/bleonheart/Useful-Python-Scripts/main/files/remove_lua_comments.py -o remove_lua_comments.py | |
| python3 remove_lua_comments.py . | |
| tar --exclude=.git -cf workspace.tar . | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: workspace | |
| path: workspace.tar | |
| overwrite: true | |
| retention-days: 1 | |
| format-glua: | |
| needs: strip-comments | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: workspace | |
| path: . | |
| - run: | | |
| tar -xf workspace.tar | |
| rm -f workspace.tar | |
| - name: Download glualint binary | |
| env: | |
| GLUALINT_VERSION: "1.29.0" | |
| run: | | |
| set -euo pipefail | |
| sudo apt-get update -y | |
| sudo apt-get install -y unzip file | |
| arch="$(uname -m)" | |
| case "$arch" in | |
| x86_64) asset="glualint-${GLUALINT_VERSION}-x86_64-linux.zip" ;; | |
| aarch64|arm64) asset="glualint-${GLUALINT_VERSION}-aarch64-linux.zip" ;; | |
| *) echo "Unsupported architecture: $arch" >&2; exit 1 ;; | |
| esac | |
| url="https://github.com/FPtje/GLuaFixer/releases/download/${GLUALINT_VERSION}/${asset}" | |
| curl -fLsS "$url" -o glualint.zip | |
| unzip -o glualint.zip | |
| chmod +x glualint | |
| ./glualint --version | |
| - name: Pretty-print all Lua files | |
| run: | | |
| find . -type f -name "*.lua" -print0 | xargs -0 ./glualint --pretty-print-files | |
| tar --exclude=.git -cf workspace.tar . | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: workspace | |
| path: workspace.tar | |
| overwrite: true | |
| retention-days: 1 | |
| linter: | |
| needs: format-glua | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| path: modules | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: workspace | |
| path: . | |
| - run: | | |
| tar -xf workspace.tar | |
| rm -f workspace.tar | |
| - 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 | |
| bump-version: | |
| needs: linter | |
| runs-on: ubuntu-latest | |
| outputs: | |
| sha: ${{ steps.sha.outputs.sha }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: bump-version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| base="${{ github.event.before }}" | |
| changed_dirs=$(git diff --name-only "$base" "$GITHUB_SHA" | awk -F/ '{print $1}' | sort -u) | |
| for dir in $changed_dirs; do | |
| file="$dir/module.lua" | |
| [ -f "$file" ] || continue | |
| v=$(grep -Eo 'MODULE\.version\s*=\s*[0-9]+(\.[0-9]{2})?' "$file" | awk -F= '{print $2}' | tr -d '[:space:]') | |
| [ -z "$v" ] && v="1.00" | |
| if [[ $v == *.* ]]; then | |
| major="${v%%.*}" | |
| minor="${v##*.}" | |
| else | |
| major="$v" | |
| minor="00" | |
| fi | |
| minor=$((10#$minor + 1)) | |
| if [ "$minor" -eq 100 ]; then | |
| minor=0 | |
| major=$((major + 1)) | |
| fi | |
| if [ "$minor" -eq 0 ]; then | |
| new_ver="$major" | |
| else | |
| new_ver=$(printf "%d.%02d" "$major" "$minor") | |
| fi | |
| if grep -q 'MODULE\.version' "$file"; then | |
| sed -i -E "s/(MODULE\.version\s*=\s*)[0-9]+(\.[0-9]{2})?/\1$new_ver/" "$file" | |
| else | |
| printf '\nMODULE.version = %s\n' "$new_ver" >> "$file" | |
| fi | |
| git add "$file" | |
| done | |
| if ! git diff --cached --quiet; then | |
| git config user.email "githubactions@github.com" | |
| git config user.name "GitHub Actions" | |
| git commit -m "Updated Modules Versions" | |
| git push origin HEAD:main | |
| fi | |
| - name: record-sha | |
| id: sha | |
| run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
| scrape-modules: | |
| needs: bump-version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ needs.bump-version.outputs.sha }} | |
| - 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\.uniqueID\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 uniqueID "$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" \ | |
| --arg uniqueID "$dir" \ | |
| --argjson features "$feat" \ | |
| --argjson workshop "$work" \ | |
| '. += [{name:$name,uniqueID:$uniqueID,author:$author,discord:$discord,description:$desc,version:$version,download:$download,source:$source,uniqueID:$uniqueID,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 | |
| ref: ${{ needs.bump-version.outputs.sha }} | |
| - 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(.uniqueID==$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/" \; | |
| 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 |