You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+98-24
Original file line number
Diff line number
Diff line change
@@ -5,19 +5,20 @@
5
5
## **Code Embedder**
6
6
Seamlessly update code snippets in your **README** files! πππ
7
7
8
-
[Description](#-description) β’ [How it works](#-how-it-works) β’ [Examples](#-examples) β’ [Setup](#-setup) β’ [Under the hood](#-under-the-hood)
8
+
[Description](#-description) β’ [How it works](#-how-it-works) β’ [Setup](#-setup) β’ [Examples](#-examples) β’ [Under the hood](#-under-the-hood)
9
9
</div>
10
10
11
11
12
12
## π Description
13
13
14
14
**Code Embedder** is a GitHub Action that automatically updates code snippets in your markdown (`README`) files. It finds code blocks in your `README` that reference specific scripts, then replaces these blocks with the current content of those scripts. This keeps your documentation in sync with your code.
15
15
16
-
β¨ **Key features**
16
+
### β¨ Key features
17
17
- π **Automatic synchronization**: Keep your `README` code examples up-to-date without manual intervention.
18
-
- π **Section support**: Update specific sections of the script in the `README`.
19
18
- π οΈ **Easy setup**: Simply add the action to your GitHub workflow and format your `README` code blocks.
20
-
- π **Language agnostic**: Works with any programming language or file type.
19
+
- π **Section support**: Update only specific sections of the script in the `README`.
By using **Code Embedder**, you can focus on writing and updating your actual code π», while letting the action take care of keeping your documentation current ππ. This reduces the risk of outdated or incorrect code examples in your project documentation.
23
24
@@ -43,9 +44,46 @@ You must also add the following comment tags in the script file `path/to/script`
43
44
...
44
45
[Comment sign] code_embedder:section_name end
45
46
```
46
-
The comment sign is the one that is used in the script file, e.g. `#` for Python, or `//` for JavaScript. The `section_name` must be unique in the file, otherwise the action will not be able to identify the section.
47
+
The comment sign is the one that is used in the script file, e.g. `#` for Python, or `//` for JavaScript. The `section_name` must be unique in the file, otherwise the action will use the first section found.
In the `README` (or other markdown) file, the object of the script is marked with the following tag:
51
+
````md
52
+
```language:path/to/script:object_name
53
+
```
54
+
````
47
55
56
+
> [!Note]
57
+
> The object name must match exactly the name of the object (function, class) in the script file. Currently, only π Python objects are supported.
48
58
59
+
> [!Note]
60
+
> If there is a section with the same name as any object, the object definition will be used in the `README` instead of the section. To avoid this, **use unique names for sections and objects!**
61
+
62
+
## π§ Setup
63
+
To use this action, you need to configure a yaml workflow file in `.github/workflows` folder (e.g. `.github/workflows/code-embedder.yaml`) with the following content:
With any changes to the section `A` in `main.py`, the code block section is updated in the `README` file with the next workflow run.
114
152
115
-
##π§ Setup
116
-
To use this action, you need to configure a yaml workflow file in `.github/workflows` folder (e.g. `.github/workflows/code-embedder.yaml`) with the following content:
The tag used for object update follows the same convention as the tag for section update, but you provide `object_name` instead of `section_name`. The object name can be a function name or a class name.
117
155
118
-
```yaml
119
-
name: Code Embedder
156
+
> [!Note]
157
+
> The `object_name` must match exactly the name of the object (function, class) in the script file, including the case. If you define class `Person` in the script, you must use `Person` as the object name in the `README`, not lowercase `person`.
120
158
121
-
on: pull_request
159
+
For example, let's say we have the following `README` file:
Once the workflow runs, the code block section will be updated in the `README` file with the content of the function `print_hello` and class `Person` from the script located at `main.py` and pushed to the repository π.
190
+
191
+
````md
192
+
# README
193
+
194
+
This is a readme.
195
+
196
+
Function `print_hello` is defined as follows:
197
+
```python:main.py:print_hello
198
+
def print_hello():
199
+
print("Hello, world!")
139
200
```
140
201
202
+
Class `Person` is defined as follows:
203
+
```python:main.py:Person
204
+
class Person:
205
+
def __init__(self, name):
206
+
self.name = name
207
+
def say_hello(self):
208
+
print(f"Hello, {self.name}!")
209
+
```
210
+
````
211
+
212
+
With any changes to the function `print_hello` or class `Person` in `main.py`, the code block sections are updated in the `README` file with the next workflow run.
213
+
214
+
141
215
## π¬ Under the hood
142
216
This action performs the following steps:
143
-
1. π Scans through the markdown (`README`) files to identify referenced script files (full scriptor section).
217
+
1. π Scans through the markdown (`README`) files to identify referenced script files (full script, section or π Python object).
144
218
1. π Extracts the contents from those script files and updates the corresponding code blocks in the markdown (`README`) files.
145
219
1. π Commits and pushes the updated documentation back to the repository.
0 commit comments