knoc-plugin-template/README.md

91 lines
1.6 KiB
Markdown
Raw Normal View History

2025-05-28 17:36:06 +02:00
# Template for Knoc plugins
## Entry points
It has 4 standard entry points, defined in `pyproject.toml`:
* CLI
* workflow
* api
* settings
## CI
2025-05-28 19:45:06 +02:00
It has a *Forgejo* CI build action, defined in `.forgejo/actions/build.yaml`.
2025-05-28 17:36:06 +02:00
2025-05-28 16:37:10 +00:00
## Usage
2025-05-28 17:11:44 +00:00
Just replace `foo` by the name of the plugin below.
With `fish`:
2025-05-28 17:01:04 +00:00
2025-05-28 16:37:10 +00:00
```fish
2025-05-28 17:01:04 +00:00
set NAME foo
set PNAME knoc_$NAME
2025-05-28 16:37:10 +00:00
set DNAME (echo $NAME | tr "_" "-")
```
or with bash:
2025-05-28 19:45:06 +02:00
2025-05-28 16:37:10 +00:00
```bash
2025-05-28 17:01:23 +00:00
NAME=foo
2025-05-28 17:01:04 +00:00
PNAME=knoc_$NAME
2025-05-28 16:37:10 +00:00
DNAME=$(echo $NAME | tr "_" "-")
```
Then:
2025-05-28 19:45:06 +02:00
2025-05-28 16:37:10 +00:00
```fish
2025-05-28 16:45:19 +00:00
git clone https://code.philo.ydns.eu/K-Net/knoc-plugin-template.git $DNAME
cd $DNAME
2025-05-28 16:37:10 +00:00
rm -rf .git
mv src/knoc_plugin_template src/$NAME
2025-05-28 17:01:04 +00:00
sed "s/plugin_template/$NAME/" -i pyproject.toml
2025-05-28 16:37:10 +00:00
sed "s/knoc-plugin-template/$DNAME/" -i pyproject.toml
2025-05-28 17:03:52 +00:00
sed "s/plugin_template/$NAME/" -i src/$PNAME/api.py
sed "s/plugin_template/$NAME/" -i src/$PNAME/cli.py
sed "s/plugin_template/$NAME/" -i src/$PNAME/settings.py
sed "s/plugin_template/$NAME/" -i src/$PNAME/workflows.py
uv venv
2025-05-28 19:45:06 +02:00
git init # Forgejo inits repo with a branch `main`, so it might be a good idea to stick wit this convention
git branch -m master main
2025-05-28 17:11:44 +00:00
```
Then, with `fish`:
2025-05-28 19:45:06 +02:00
2025-05-28 17:11:44 +00:00
```fish
. .venv/bin/activate.fish
uv sync
```
Or `bash`:
2025-05-28 19:45:06 +02:00
2025-05-28 17:11:44 +00:00
```bash
. .venv/bin/activate
uv sync
2025-05-28 19:45:06 +02:00
git add --all
git commit -m "Initial commit"
2025-05-28 16:37:10 +00:00
```
2025-05-28 17:11:44 +00:00
2025-05-28 17:13:26 +00:00
=> The package is ready.
2025-05-28 17:11:44 +00:00
In a *knoc* development environment:
2025-05-28 19:45:06 +02:00
2025-05-28 17:11:44 +00:00
```fish
uv pip install -e ../$DNAME
knoc # Should display the new plugin's CLI tool
2025-05-28 17:13:26 +00:00
```
2025-05-28 19:45:06 +02:00
## Develop
2025-05-28 17:22:08 +00:00
2025-05-28 19:45:06 +02:00
* Edit
*`git commit`
*`git tag` (for versioning: `git tag -a v0.1.2 -m "..."`)
* `git push`
2025-05-28 17:22:08 +00:00
2025-05-28 19:45:06 +02:00
## Deploy
2025-05-28 17:22:08 +00:00
2025-05-28 19:45:06 +02:00
To add the plugin in a production image, add the name to the `PLUGIN` variable
of the CI build tool, and deploy.
2025-05-28 17:14:51 +00:00