Merge pull request #111 from LiliaFramework/codex/add-line-breaks-in-… #2075
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 | |
| 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=$(grep -Po 'MODULE\.name\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=$(grep -Po 'MODULE\.desc\s*=\s*"[^"]*"' "$m" | sed -E 's/.*=\s*"([^"]+)".*/\1/' || true) | |
| 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 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 public_uniqueID "$dir" \ | |
| --argjson features "$feat" \ | |
| --argjson workshop "$work" \ | |
| '. += [{name:$name,author:$author,discord:$discord,description:$desc,version:$version,download:$download,source:$source,public_uniqueID:$public_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 | |
| - name: update-website-json | |
| shell: bash | |
| run: | | |
| git clone https://x-access-token:${{ secrets.LiliaGitSecret }}@github.com/LiliaFramework/LiliaFramework.github.io.git website | |
| cp modules.json website/modules.json | |
| cd website | |
| git config user.email "githubactions@github.com" | |
| git config user.name "GitHub Actions" | |
| git add modules.json | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Update modules.json with source URLs" | |
| git push https://x-access-token:${{ secrets.LiliaGitSecret }}@github.com/LiliaFramework/LiliaFramework.github.io.git HEAD:main | |
| fi | |
| - 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_} | |
| doc_dir=$(find "$d" -type d -iname docs -maxdepth 2 -print -quit || true) | |
| [ -z "$doc_dir" ] && continue | |
| dest="documentation/docs/modules/${mod}" | |
| mkdir -p "$dest" | |
| find "$doc_dir" -maxdepth 1 -type f -name '*.md' -exec cp {} "$dest/" \; | |
| done | |
| shopt -u nullglob | |
| - name: create-about-md | |
| run: node generate_about_md.js | |
| - name: clean-obsolete-docs | |
| run: | | |
| rm -rf documentation/docs/hooks/modules | |
| rm -rf documentation/docs/libraries/modules | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 16 | |
| - uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.LiliaGitSecret }} | |
| publish_branch: gh-pages | |
| publish_dir: documentation | |
| force_orphan: true | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: built-docs | |
| path: documentation | |
| 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 | |
| rm -f lilia/documentation/modules.json | |
| - 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 "Update generated module documentation" | |
| git push https://x-access-token:${{ secrets.LiliaGitSecret }}@github.com/LiliaFramework/Lilia.git HEAD:main | |
| fi |