polyfill test #56
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: WikiWire | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'modules/**' | |
| - 'modules/*' | |
| - 'templates/**' | |
| - 'templates/*' | |
| jobs: | |
| wikiwire: | |
| runs-on: ubuntu-latest | |
| name: Sync files to production MediaWiki | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Darklua | |
| run: | | |
| wget -q https://github.com/seaofvoices/darklua/releases/download/v0.18.0/darklua-linux-x86_64.zip | |
| unzip -q darklua-linux-x86_64.zip | |
| chmod +x darklua | |
| - name: Regenerate Lua outputs for changed Luau modules | |
| shell: bash | |
| env: | |
| BEFORE: ${{ github.event.before }} | |
| AFTER: ${{ github.sha }} | |
| run: | | |
| set -euo pipefail | |
| POLYFILL="table.find=table.find or function(t,v,i) for j=i or 1,#t do if t[j]==v then return j end end end; table.clear=table.clear or function(t) for k in pairs(t) do t[k]=nil end end; table.create=table.create or function(n,v) local t={} for i=1,n do t[i]=v end return t end;" | |
| if [[ -z "${BEFORE:-}" || "${BEFORE}" =~ ^0+$ ]]; then | |
| changed_files="$(git show --name-only --pretty=format: "${AFTER}")" | |
| else | |
| changed_files="$(git diff --name-only "${BEFORE}" "${AFTER}")" | |
| fi | |
| while IFS= read -r path; do | |
| [[ -n "$path" ]] || continue | |
| [[ "$path" == modules/* ]] || continue | |
| [[ "$path" =~ \.module\.luau$ ]] || continue | |
| out_path="${path%.module.luau}.module.lua" | |
| mkdir -p "$(dirname "$out_path")" | |
| ./darklua process --config .darklua.json5 "$path" "$out_path" | |
| echo -e "$POLYFILL\n$(cat "$out_path")" > "$out_path" | |
| done <<< "$changed_files" | |
| - name: Fail if outputs were not committed | |
| run: git diff --exit-code | |
| - uses: obbywiki/wikiwire@4989b61661fdd188479c7f2283b9ddde25337efa | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.WIKIWIRE_GITHUB_TOKEN }} | |
| with: | |
| username: WikiWireBot@WikiWire | |
| password: ${{ secrets.WIKIWIRE_PASSWORD }} | |
| dark_lua_compat: "false" |