Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# A plugin's content hash covers its exact bytes, on every checkout.
plugins/** -text
6 changes: 6 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Every pull request needs a review from an owner. The last matching line wins.
* @MHohlios

# An owner for a game joins here as contributors show up, with Michael kept
# on for now:
# /plugins/<id>/ @MHohlios @their-handle
43 changes: 43 additions & 0 deletions .github/workflows/budget-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Budget comment

# A pull request from a fork can't write to this repo, so this runs afterwards
# from main, where it can. It never checks out the pull request's code, and it
# treats the report as forgeable: see `render_budget_table` in ci/registry.py.
on:
workflow_run:
workflows: [Registry]
types: [completed]

permissions: {}

jobs:
comment:
name: Show the budget on the pull request
if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Fetch the report
id: report
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: gh run download "$RUN_ID" --name budget --dir "$RUNNER_TEMP/report"
- name: Post it
if: steps.report.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
python3 ci/registry.py comment "$RUNNER_TEMP/report/budget.json" > "$RUNNER_TEMP/comment.md"
ci/post-budget-comment.sh "$RUNNER_TEMP/comment.md"
85 changes: 85 additions & 0 deletions .github/workflows/registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Registry

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

env:
CARGO_TERM_COLOR: always

jobs:
# Runs a stranger's plugin, so it holds no secret and can write nothing.
check:
name: Check plugins
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Read the pinned versions
run: ci/load-pins.sh
- name: Check out MUDling at the pinned commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: Vyttle-LLC/mudling
ref: ${{ env.MUDLING_COMMIT }}
path: .mudling
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
toolchain: stable
- uses: Swatinem/rust-cache@2201cc584a476d1b508be977bbe4b7d1c7a52e9c # v2.9.3
with:
workspaces: .mudling
- name: Build mudling
run: cargo build --release --locked -p mudling-cli --manifest-path .mudling/Cargo.toml
- name: Install luau-analyze
run: ci/install-luau.sh "$RUNNER_TEMP/luau"
- name: Test the checks themselves
env:
MUDLING: .mudling/target/release/mudling
LUAU_ANALYZE: ${{ runner.temp }}/luau/luau-analyze
SESSION_LOG: .mudling/crates/mudling-bench/fixtures/session.txt
run: python3 -m unittest discover ci
- name: Check every plugin
run: >
python3 ci/registry.py check
--mudling .mudling/target/release/mudling
--luau-analyze "$RUNNER_TEMP/luau/luau-analyze"
--session-log .mudling/crates/mudling-bench/fixtures/session.txt
--report budget.json
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: budget
path: budget.json
if-no-files-found: ignore

# Holds the signing key, so it runs no plugin's code and only runs on main.
publish:
name: Publish the signed index
needs: check
if: github.event_name == 'push'
runs-on: ubuntu-24.04
permissions:
contents: write
# One at a time, and a newer main replaces any run still waiting.
concurrency:
group: publish-index
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Build and sign the index
env:
INDEX_SIGNING_KEY: ${{ secrets.INDEX_SIGNING_KEY }}
TZ: UTC
run: >
python3 ci/registry.py index
--commit "$GITHUB_SHA"
--published-at "$(git show --no-patch --format=%cd --date=format-local:%Y-%m-%dT%H:%M:%SZ)"
--output "$RUNNER_TEMP/index.json"
- name: Publish it to the index branch
run: ci/publish-index.sh "$RUNNER_TEMP/index.json"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Session logs hold other players' chat, so they never go in this repo.
*.log

__pycache__/
.mudling/
budget.json
125 changes: 125 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Adding a plugin

This takes you from nothing to an open pull request. You need
[Rust](https://rustup.rs), [git](https://git-scm.com), a GitHub account, and a
game you know. You don't need to read MUDling's core.

## 1. Build the `mudling` command

```sh
git clone https://github.com/Vyttle-LLC/mudling
cd mudling
cargo build --release -p mudling-cli
```

The command is now at `target/release/mudling`. These steps call it `mudling`, so
either put that folder on your `PATH` or use the full path.

## 2. Fork this repo and make your plugin

Fork [mudling-plugins](https://github.com/Vyttle-LLC/mudling-plugins) on GitHub,
then:

```sh
git clone https://github.com/<you>/mudling-plugins
cd mudling-plugins
git switch -c add-mygame
mudling plugin new mygame --dir plugins
mudling plugin test plugins/mygame
```

The `id`, here `mygame`, is the folder's name too, and they must stay the same.
Use lowercase letters, digits, `.`, `_` and `-`. Other file and folder names may
also use capitals, but no spaces and nothing outside ASCII. Don't add a
`.gitattributes` file: it would change the bytes that the app checks. You now have
a plugin that loads and passes its own test.

## 3. Teach it your game

Edit the files in `plugins/mygame/`:

- `plugin.toml` is the manifest. Set `name`, set `hosts` under `[servers]` to the
game's address, and add `mssp_names` if the game sends its MSSP name. The
directory shows and matches plugins by these.
- `text.toml` reads the game's text. Other extension points get files of their
own.
- `hooks.luau` holds Luau hooks, for what a pattern can't read. If you need none,
delete the file along with `[hooks]` and `permissions` in `plugin.toml` and
every `hook = "…"` line in `text.toml`. Then run the `--update` command from
step 4 once, because the sample's `.expected` still lists what the hook did.

The [plugin API reference](https://github.com/Vyttle-LLC/mudling/blob/main/docs/plugins/reference.md)
lists everything, and the
[cookbook](https://github.com/Vyttle-LLC/mudling/blob/main/docs/plugins/cookbook.md)
works through a real plugin.

To try a log from your own play without keeping it:

```sh
mudling plugin test plugins/mygame --log ~/somewhere/outside/this/repo/session.log
```

## 4. Write its tests

A test is a pair of files in `tests/`: `<name>.txt`, some game text, and
`<name>.expected`, what it should produce.

**Write the text by hand, and make up every name.** A real session log holds other
players' chat, so never commit one, not even part of one. CI fails any `*.log`
file.

Once the text covers what your plugin reads:

```sh
mudling plugin test plugins/mygame --update
```

This writes the `.expected` files. Read them, because whatever they hold is what
your plugin will be held to. Then run the test on its own to see it pass:

```sh
mudling plugin test plugins/mygame
```

Each `caught` line shows how many lines a pattern matched. Each `fail` line says
what's wrong. The last line is `passed` or `failed`.

## 5. Choose a license

Set `license` in `plugin.toml` to exactly `MIT` or `Apache-2.0`. `mudling plugin
new` starts you on `MIT`. The registry takes nothing else, so that plugins can be
bundled and forked freely. By opening a pull request, you confirm you have the
right to license your plugin that way.

## 6. Open a pull request

Add only your plugin's folder, so that review stays quick:

```sh
git add plugins/mygame
git commit -m "Add the mygame plugin"
git push -u origin add-mygame
```

Then open a pull request on GitHub, against `main` of
`Vyttle-LLC/mudling-plugins`.

If this is your first contribution here, a maintainer may need to approve the
checks before they run. GitHub asks for that on first pull requests.

## 7. What happens next

CI runs [these checks](docs/ci.md) and shows your plugin's cost per line in a
comment on the pull request. If a check fails, its log has a `fail <id> <kind>:`
line that says why, and [the same page](docs/ci.md#what-a-failure-means) says what
to do. Push a fix to the same branch and CI runs again.

Once it passes, an owner reviews your plugin. Merged plugins reach players with the
next index, a few minutes later.

## Updating a plugin

Open a pull request the same way, and raise `version` in `plugin.toml`, which is
how players learn there's an update. If you'd like to own your game's plugins and
review others' changes to them, say so in the pull request: owners join
`.github/CODEOWNERS` as contributors show up.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# mudling-plugins
Community plugins for MUDling

The community plugin registry for [MUDling](https://github.com/Vyttle-LLC/mudling),
a MUD client. Each plugin teaches MUDling about a game: its prompts, its tables,
its map, its gear. MUDling's plugin directory (Settings › Plugins › Browse) lists
what's here.

To add a plugin, read [CONTRIBUTING.md](CONTRIBUTING.md). It goes from
`mudling plugin new` to an open pull request.

## What's in this repo

| Path | What it is |
| --- | --- |
| `plugins/<id>/` | One folder per plugin. |
| `.github/CODEOWNERS` | Who reviews what. |
| `ci/` | The checks every pull request goes through, and their tests. |
| `docs/ci.md` | What each check does, and why a failure happened. |
| `docs/index-format.md` | The signed index that the app reads. |
| `docs/signing.md` | The signing key, and how to set or replace it. |

## The rules

- **One folder per plugin:** `plugins/<id>/`, named for the plugin's `id`.
- **MIT or Apache-2.0 only,** so a plugin can be bundled and forked freely.
- **Every plugin ships tests:** a few lines of made-up game text, and what they
should produce.
- **No session logs.** They hold other players' chat. Write test text by hand.
- **CI runs first.** It checks the manifest, the patterns, the plugin's tests, its
cost per line and its Luau, before anyone reviews the pull request.
- **Then a person reviews it:** an owner from `CODEOWNERS`, Michael to begin with.
Owners for each game join as contributors show up.

## How a plugin reaches players

When a pull request merges to `main`, CI checks everything again and builds an
index with one entry per plugin. It signs the index and publishes it to the
`index` branch, and MUDling reads it from there. Nothing in the app trusts an
index that doesn't verify.

## License

The repo itself is [MIT](LICENSE). Each plugin carries the license its
`plugin.toml` names: MIT or Apache-2.0.
3 changes: 3 additions & 0 deletions ci/fixtures/fixture/greet.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function on_welcome(event)
Shared.remember(event.captures.name)
end
20 changes: 20 additions & 0 deletions ci/fixtures/fixture/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CI's own test plugin: it passes every check. ci/test_registry.py copies it and
# breaks one thing at a time.
id = "fixture"
name = "Fixture"
version = "1.0.0"
api = 1
license = "MIT"
layer = "game"
permissions = ["write_store:character"]

[servers]
hosts = ["fixture.example"]
mssp_names = ["Fixture"]

[points]
text = "text.toml"

[hooks]
# shared.luau first: greet.luau uses the Shared table it defines.
files = ["shared.luau", "greet.luau"]
5 changes: 5 additions & 0 deletions ci/fixtures/fixture/shared.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Shared = {}

function Shared.remember(name)
mud.store("character", "name", name)
end
2 changes: 2 additions & 0 deletions ci/fixtures/fixture/tests/sample.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
event text character.welcome name="Ana"
store character name "Ana"
3 changes: 3 additions & 0 deletions ci/fixtures/fixture/tests/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[connected]
Welcome back, Ana.
Bo says 'nice weather'
5 changes: 5 additions & 0 deletions ci/fixtures/fixture/text.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# "Welcome back, Ana."
[[pattern]]
name = "character.welcome"
pattern = '''^Welcome back, (?<name>\w+)\.$'''
hook = "on_welcome"
12 changes: 12 additions & 0 deletions ci/install-luau.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Downloads the pinned luau-analyze into $1 and checks it against its hash.
# Reads LUAU_VERSION and LUAU_UBUNTU_SHA256 from the environment.
set -eu

folder=$1
mkdir -p "$folder"
curl --fail --silent --show-error --location --output "$folder/luau.zip" \
"https://github.com/luau-lang/luau/releases/download/$LUAU_VERSION/luau-ubuntu.zip"
echo "$LUAU_UBUNTU_SHA256 $folder/luau.zip" | sha256sum --check --quiet
unzip -q -o "$folder/luau.zip" luau-analyze -d "$folder"
chmod +x "$folder/luau-analyze"
11 changes: 11 additions & 0 deletions ci/load-pins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# Hands ci/pins.env to the rest of the job, and stops it plainly if the MUDling
# commit hasn't been set to a real one.
set -eu

grep -v '^#' ci/pins.env >>"$GITHUB_ENV"
commit=$(sed -n 's/^MUDLING_COMMIT=//p' ci/pins.env)
if ! printf '%s' "$commit" | grep -Eq '^[0-9a-f]{40}$'; then
echo "::error file=ci/pins.env::MUDLING_COMMIT is '$commit'. Set it to a full commit on Vyttle-LLC/mudling that has mudling plugin test."
exit 1
fi
7 changes: 7 additions & 0 deletions ci/luaurc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"languageMode": "nonstrict",
"lint": { "FunctionUnused": false },
"lintErrors": true,
"typeErrors": true,
"globals": ["mud"]
}
Loading