Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .github/workflows/delete dev env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/protect new wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/protect page across wikis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 49 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
46 changes: 46 additions & 0 deletions README.md
Comment thread
ElectricalBoy marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`) 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 <BRANCH NAME> -f luadevenv=<DEV-ENV-NAME>`

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 <file>` with `LUA_DEV_ENV_NAME=/dev/<name>` 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.
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests==2.34.2
python-dotenv==1.2.2
31 changes: 29 additions & 2 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
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,
write_to_github_summary_file,
)
from mediawiki_session import MediaWikiSession

load_dotenv()

HEADER_PATTERN = re.compile(
r"\A---\n" r"-- @Liquipedia\n" r"-- page=(?P<pageName>[^\n]*)\n"
)
Expand Down Expand Up @@ -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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to further guard this path?
The modules should be protected, but there isn't really a reason why anyone would need this except for the scheduled deploy action.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe having a prefix check won't hurt much now that I think about it...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was rather thinking about someone forgetting to set the environment variable.
So the suggestion would probably be to add a dedicated flag for the deploy-all instead

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was rather thinking about someone forgetting to set the environment variable.

vscode will always prompt for a dev env name so I don't think extra check is needed and anyone using non-admin bot will face MW yelling anyway
that only leaves admin bots and I generally think that admins are careful enough not to screw live modules up

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]):
Expand Down
Loading