diff --git a/.env.example b/.env.example new file mode 100644 index 00000000000..231f80a52f4 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +WIKI_BASE_URL=https://liquipedia.net +WIKI_UA_EMAIL=john.doe@liquipedia.is.awesome +WIKI_USER=YourBotAccount@BotName +WIKI_PASSWORD=YourBotPassword +DRY_RUN=0 diff --git a/.github/workflows/delete dev env.yml b/.github/workflows/delete dev env.yml index f850adca2e1..89e24d530a7 100644 --- a/.github/workflows/delete dev env.yml +++ b/.github/workflows/delete dev env.yml @@ -28,9 +28,10 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency - run: pip install requests + run: pip install -r requirements.txt - name: Remove Lua Dev Env Modules env: diff --git a/.github/workflows/deploy test.yml b/.github/workflows/deploy test.yml index fe509c4d9ae..9288b549896 100644 --- a/.github/workflows/deploy test.yml +++ b/.github/workflows/deploy test.yml @@ -32,10 +32,11 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency if: steps.changed-files.outputs.any_changed == 'true' - run: pip install requests + run: pip install -r requirements.txt - name: Personal Lua Deploy if: steps.changed-files.outputs.any_changed == 'true' diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ae543ea957e..e4cbbcccad2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,10 +34,11 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency if: steps.res-changed-files.outputs.any_changed == 'true' || steps.lua-changed-files.outputs.any_changed == 'true' - run: pip install requests + run: pip install -r requirements.txt - name: Resource Deploy if: steps.res-changed-files.outputs.any_changed == 'true' diff --git a/.github/workflows/protect new wiki.yml b/.github/workflows/protect new wiki.yml index 790e482f590..77614d8ae8c 100644 --- a/.github/workflows/protect new wiki.yml +++ b/.github/workflows/protect new wiki.yml @@ -20,10 +20,11 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency id: dependencies - run: pip install requests + run: pip install -r requirements.txt - name: Template Protect env: diff --git a/.github/workflows/protect page across wikis.yml b/.github/workflows/protect page across wikis.yml index 6f9674247e8..2b0f45451b2 100644 --- a/.github/workflows/protect page across wikis.yml +++ b/.github/workflows/protect page across wikis.yml @@ -20,9 +20,10 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency - run: pip install requests + run: pip install -r requirements.txt - name: Page Protect env: diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 0d2d29c3d8b..38225b42d7c 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -19,9 +19,10 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.14' + cache: 'pip' - name: Install Python Dependency - run: pip install requests + run: pip install -r requirements.txt - name: Resource Deploy env: diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000000..d788432c8cc --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,49 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Deploy current file", + "type": "shell", + "command": "${command:python.interpreterPath}", + "args": [ + "scripts${/}deploy.py", + "${relativeFile}" + ], + "options": { + "env": { + "LUA_DEV_ENV_NAME": "/dev/${input:devEnvironment}", + "LUA_DEV_BASE_REF": "${input:devBaseRef}" + } + }, + "problemMatcher": [] + }, + { + "label": "Deploy all changed file", + "type": "shell", + "command": "${command:python.interpreterPath}", + "args": [ + "scripts${/}deploy.py", + ], + "options": { + "env": { + "LUA_DEV_ENV_NAME": "/dev/${input:devEnvironment}", + "LUA_DEV_BASE_REF": "${input:devBaseRef}" + } + }, + "problemMatcher": [] + } + ], + "inputs": [ + { + "id": "devEnvironment", + "type": "promptString", + "description": "Lua Dev Enviroment name" + }, + { + "id": "devBaseRef", + "type": "promptString", + "description": "Base ref to compare against for dev deployment", + "default": "main" + } + ] +} diff --git a/README.md b/README.md index 74287267068..5e49ead1aab 100644 --- a/README.md +++ b/README.md @@ -144,12 +144,58 @@ Trusted contributers may be given the privilege of directly branching within the ### Testing your branch +Deploying your branch to a dev environment publishes your modules to sandbox pages (suffixed with `/dev/`) on the wiki, so you can render and test them without touching the live pages. + +#### Via a GitHub Action + To test your changes in action, you can run the GitHub Action called "Personal Deploy" defined in `.github/workflows/deploy test.yml`. You can do it either through the GitHub interface or with the GitHub CLI tools: `gh workflow run 'deploy test.yml' -r -f luadevenv=` To check the workflow progress from the CLI, you can run: `gh run list --workflow="deploy test.yml"` +#### From your machine + +You can also run the deploy script locally. This works from any editor — the repo ships a Visual Studio Code integration, and every other editor can call the same script directly. + +**One-time setup:** + +1. Install the Python dependencies: `pip install -r requirements.txt` +2. Copy `.env.example` to `.env` and fill in your bot account credentials. `.env` is git-ignored — never commit it. + +``` +WIKI_BASE_URL=https://liquipedia.net +WIKI_UA_EMAIL=you@example.com +WIKI_USER=YourBotAccount@BotName +WIKI_PASSWORD=YourBotPassword +DRY_RUN=0 +``` + +**Running it:** + +```bash +# Deploy specific files +python scripts/deploy.py lua/wikis/commons/SomeModule.lua [more files...] + +# Deploy every file changed on your branch under lua/wikis/ +python scripts/deploy.py +``` + +The behaviour is driven by environment variables (set them in `.env` or per-invocation): + +| Variable | Purpose | +| --- | --- | +| `LUA_DEV_ENV_NAME` | Sandbox suffix, e.g. `/dev/myenv`. Appended to every deployed page name. **Set this for all dev testing** — without it, deploys go to the live module pages. Also required to enable the no-argument "all changed files" mode. | +| `LUA_DEV_BASE_REF` | Ref that the no-argument mode diffs against to find changed files. Defaults to `main`. | +| `DRY_RUN` | Set to `1` to run the full flow without writing to the wiki. | +| `WIKI_USER` / `WIKI_PASSWORD` / `WIKI_BASE_URL` / `WIKI_UA_EMAIL` | Bot credentials and target wiki (see setup above). | + +> **Note:** running `python scripts/deploy.py` with no arguments **and** no `LUA_DEV_ENV_NAME` triggers a full re-sync of every module to the live wiki — this is the automated weekly-resync path and is not what you want for testing a branch. + +**Visual Studio Code:** the repo includes tasks in `.vscode/tasks.json` — run *Tasks: Run Task* and pick **Deploy current file** or **Deploy all changed file**. Both prompt for the dev environment name and the base ref. + +**Other editors:** bind a command to `python scripts/deploy.py` with the environment above. For example, a Neovim mapping can shell out to `python scripts/deploy.py ` with `LUA_DEV_ENV_NAME=/dev/` set on the job's environment. + ## Support If you encounter any issues or have questions, feel free to open an issue on GitHub or reach out to the Liquipedia community for support. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000..81c9577e43b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.34.2 +python-dotenv==1.2.2 diff --git a/scripts/deploy.py b/scripts/deploy.py index dffd1854605..210a650ceba 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -2,10 +2,13 @@ import os import pathlib import re +import subprocess import sys from typing import Iterable +from dotenv import load_dotenv + from deploy_util import ( get_git_deploy_reason, read_file_from_path, @@ -13,6 +16,8 @@ ) from mediawiki_session import MediaWikiSession +load_dotenv() + HEADER_PATTERN = re.compile( r"\A---\n" r"-- @Liquipedia\n" r"-- page=(?P[^\n]*)\n" ) @@ -46,11 +51,33 @@ def main(): all_modules_deployed = True lua_files: Iterable[pathlib.Path] git_deploy_reason: str - if len(sys.argv[1:]) == 0: + assert os.getenv("LUA_DEV_ENV_NAME") is None or ( + os.getenv("LUA_DEV_ENV_NAME") != "/dev/" + and os.getenv("LUA_DEV_ENV_NAME").startswith("/dev/") + ), f"Invalid dev environment: {os.getenv('LUA_DEV_ENV_NAME')}" + if len(sys.argv[1:]) == 0 and os.getenv("LUA_DEV_ENV_NAME") is None: lua_files = pathlib.Path("./lua/wikis/").rglob("*.lua") git_deploy_reason = "Automated Weekly Re-Sync" else: - lua_files = [pathlib.Path(arg) for arg in sys.argv[1:]] + if len(sys.argv[1:]) == 0: + lua_files = [ + pathlib.Path(changed_file) + for changed_file in subprocess.check_output( + [ + "git", + "diff", + "--name-only", + "--diff-filter=d", + os.getenv("LUA_DEV_BASE_REF") or "main", + "lua/wikis/*", + ] + ) + .decode() + .strip() + .splitlines() + ] + else: + lua_files = [pathlib.Path(arg) for arg in sys.argv[1:]] git_deploy_reason = get_git_deploy_reason() for wiki, files in itertools.groupby(sorted(lua_files), lambda path: path.parts[2]):