Skip to content

Commit fd8349c

Browse files
committed
build out a readme template system for easy overrides
1 parent a64d459 commit fd8349c

File tree

8 files changed

+82
-64
lines changed

8 files changed

+82
-64
lines changed

action.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ inputs:
1010
description: 'The python package whose version is being tracked.'
1111
required: true
1212

13-
project_description:
14-
description: "A description of the project- this can be a full markdown text."
15-
required: true
16-
default: ""
17-
1813
readme_path:
1914
description: 'The path to the README file to update.'
2015
required: true
@@ -83,7 +78,6 @@ runs:
8378
TEMPLATE_DIRECTORY: ${{ inputs.template_directory }}
8479
PACKAGE: ${{ inputs.package }}
8580
PROJECT_NAME: ${{ inputs.package }}
86-
PROJECT_DESCRIPTION: ${{ inputs.project_description }}
8781
PYTHON_VERSIONS: "3.6 3.7 3.8 3.9 3.10"
8882
MAX_VERSIONS: ${{ inputs.max_versions }}
8983
ORGANIZATION: ${{ inputs.organization }}

readme_builder.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
1-
from jinja2 import Environment, FileSystemLoader, select_autoescape
1+
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, select_autoescape
22
import os
3+
from pathlib import Path
34

4-
SCRIPT_DIR=os.path.dirname(os.path.realpath(__file__))
5+
subtemplates = [
6+
"description",
7+
"documentation",
8+
"quick_start",
9+
"tags"
10+
]
11+
12+
template_paths = []
513

14+
# Use explicit user setting *or* default repo directory for templates.
15+
# These get called first, allowing repos to override action templates.
616
TEMPLATE_DIR = os.environ.get("TEMPLATE_DIRECTORY", False)
7-
if not TEMPLATE_DIR or len(TEMPLATE_DIR) < 1:
8-
TEMPLATE_DIR = f"{SCRIPT_DIR}/templates/"
17+
if TEMPLATE_DIR and len(TEMPLATE_DIR) > 0:
18+
template_paths.append(FileSystemLoader(TEMPLATE_DIR))
19+
else:
20+
WORKSPACE_DIR = os.environ.get("GITHUB_WORKSPACE", False)
21+
if WORKSPACE_DIR:
22+
workspace_template_path = Path(WORKSPACE_DIR, 'templates')
23+
if workspace_template_path.exists():
24+
template_paths.append(str(FileSystemLoader(workspace_template_path)))
25+
26+
# Add the action templates as the final templates to check.
27+
SCRIPT_DIR=os.path.dirname(os.path.realpath(__file__))
28+
template_paths.append(FileSystemLoader(f"{SCRIPT_DIR}/templates/"))
929

1030
env = Environment(
11-
loader=FileSystemLoader(TEMPLATE_DIR),
31+
loader=ChoiceLoader(template_paths),
1232
autoescape=select_autoescape()
1333
)
1434

15-
template = env.get_template("README.md")
16-
1735
variables = {
1836
"package": os.environ["PACKAGE"],
1937
"project_name": os.environ["PROJECT_NAME"],
20-
"description": os.environ["PROJECT_DESCRIPTION"],
2138
"package_versions": os.environ["PACKAGE_VERSIONS"].split(),
2239
"python_versions": os.environ["PYTHON_VERSIONS"].split(),
2340
"organization": os.environ["ORGANIZATION"],
2441
"repository": os.environ["REPOSITORY"]
2542
}
2643

27-
print(template.render(**variables))
44+
for template_var in subtemplates:
45+
subtemplate = env.get_template(f"{template_var}.md")
46+
variables[template_var] = subtemplate.render(**variables)
47+
48+
readme_template = env.get_template("README.md")
49+
print(readme_template.render(**variables))

templates/README.md

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,7 @@
33

44
{{ description }}
55

6-
## Quick Start
7-
8-
### Full
9-
10-
To pull the latest slim version:
11-
12-
```bash
13-
docker pull ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-LATEST
14-
```
15-
16-
To include it in the dockerfile instead:
17-
18-
```dockerfile
19-
FROM ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-LATEST
20-
```
21-
22-
### Slim
23-
24-
To pull the latest slim version:
25-
26-
```bash
27-
docker pull ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-LATEST
28-
```
29-
30-
To include it in the dockerfile instead:
31-
32-
```dockerfile
33-
FROM ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-LATEST
34-
```
6+
{{ quick_start }}
357

368
## Python Versions
379

@@ -65,23 +37,6 @@ Every tag in this repository supports these architectures:
6537
* linux/arm64
6638
* linux/arm/v7
6739

40+
{{ tags }}
6841

69-
## Tags
70-
71-
* Recommended Image: `ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-{{ package_versions|last }}`
72-
* Slim Image: `ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-{{ package_versions|last }}`
73-
74-
Tags are based on the package version, python version, and the upstream container the container is based on.
75-
76-
| {{package}} Version | Python Version | Full Container | Slim Container | Alpine Container |
77-
|---------------------|----------------|----------------|----------------|------------------|
78-
{%- for package_version in ["latest"] + package_versions|reverse|list -%}
79-
{%- for python_version in python_versions|reverse %}
80-
| {{ package_version }} | {{ python_version }} | py{{ python_version }}-{{ package_version }} | py{{ python_version }}-slim-{{ package_version }} | py{{ python_version }}-alpine-{{ package_version }} |
81-
{%- endfor %}
82-
{%- endfor %}
83-
84-
85-
### Older Tags
86-
87-
Older tags are left for historic purposes but do not receive updates. A full list of tags can be found on the package's [registry page](https://github.com/{{ repository }}/pkgs/container/{{ short_repository }}).
42+
{{ documentation }}

templates/description.md

Whitespace-only changes.

templates/documentation.md

Whitespace-only changes.

templates/quick_start.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Quick Start
2+
3+
### Full
4+
5+
To pull the latest slim version:
6+
7+
```bash
8+
docker pull ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-LATEST
9+
```
10+
11+
To include it in the dockerfile instead:
12+
13+
```dockerfile
14+
FROM ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-LATEST
15+
```
16+
17+
### Slim
18+
19+
To pull the latest slim version:
20+
21+
```bash
22+
docker pull ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-LATEST
23+
```
24+
25+
To include it in the dockerfile instead:
26+
27+
```dockerfile
28+
FROM ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-LATEST
29+
```

templates/tags.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Tags
2+
3+
* Recommended Image: `ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-{{ package_versions|last }}`
4+
* Slim Image: `ghcr.io/{{ organization }}/{{ short_repository }}:py{{ python_versions|last }}-slim-{{ package_versions|last }}`
5+
6+
Tags are based on the package version, python version, and the upstream container the container is based on.
7+
8+
| {{ package }} Version | Python Version | Full Container | Slim Container | Alpine Container |
9+
|-----------------------|----------------|----------------|----------------|------------------|
10+
{%- for package_version in ["latest"] + package_versions|reverse|list -%}
11+
{%- for python_version in python_versions|reverse %}
12+
| {{ package_version }} | {{ python_version }} | py{{ python_version }}-{{ package_version }} | py{{ python_version }}-slim-{{ package_version }} | py{{ python_version }}-alpine-{{ package_version }} |
13+
{%- endfor %}
14+
{%- endfor %}
15+
16+
17+
### Older Tags
18+
19+
Older tags are left for historic purposes but do not receive updates. A full list of tags can be found on the package's [registry page](https://github.com/{{ repository }}/pkgs/container/{{ short_repository }}).

test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ export PACKAGE_VERSIONS="0.13.3 0.13.4 0.14.0 0.15.0"
77
export PYTHON_VERSIONS="3.6 3.7 3.8 3.9 3.10"
88
export ORGANIZATION="TestOrganization"
99
export REPOSITORY="TestOrganization/TestRepository"
10-
export PROJECT_DESCRIPTION="This project is a project."
1110

1211
./scripts/update_readme.sh -

0 commit comments

Comments
 (0)