Skip to content

Commit c2e9ca8

Browse files
committed
smarter readme building
1 parent b86fa9f commit c2e9ca8

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ runs:
7575

7676
- name: "Install Jinja2"
7777
shell: bash
78-
run: "python -m pip install jinja2"
78+
run: "python -m pip install jinja2 pyyaml"
7979

8080
- name: "Update README.md"
8181
shell: bash
@@ -89,6 +89,7 @@ runs:
8989
ORGANIZATION: ${{ inputs.organization }}
9090
REPOSITORY: ${{ inputs.repository }}
9191
INCLUDE_PRERELEASE: ${{ inputs:include_prereleases}}
92+
BUILDER_WORKFLOW_PATH: ${{ inputs.action_path }}
9293

9394
- name: "Push"
9495
shell: bash

readme_builder.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, select_autoescape
2+
import yaml
23
import os
34
from pathlib import Path
45

@@ -32,13 +33,41 @@
3233
autoescape=select_autoescape()
3334
)
3435

36+
37+
def get_key_value(obj, key):
38+
if hasattr(obj,'iteritems'):
39+
for k, v in obj.iteritems():
40+
if k == key:
41+
return v
42+
if isinstance(v, dict):
43+
return get_key_value(v, key)
44+
elif isinstance(v, list):
45+
for d in v:
46+
return get_key_value(d, key)
47+
48+
platform = "linux/amd64,linux/arm64,linux/arm/v7"
49+
variants = ["full", "slim", "alpine"]
50+
if os.environ.get('BUILDER_WORKFLOW_PATH', False):
51+
with open(os.environ['BUILDER_WORKFLOW_PATH'], "r") as stream:
52+
try:
53+
build_spec = yaml.safe_load(stream)
54+
platform = get_key_value(build_spec, "platform")
55+
strategy = get_key_value(build_spec, "strategy")
56+
if strategy and 'matrix' in strategy:
57+
if 'target_base' in strategy['matrix']:
58+
variants = strategy['matrix']['target_base']
59+
except yaml.YAMLError as exc:
60+
print(exc)
61+
3562
variables = {
3663
"package": os.environ["PACKAGE"],
3764
"project_name": os.environ["PROJECT_NAME"],
3865
"package_versions": os.environ["PACKAGE_VERSIONS"].split(),
3966
"python_versions": os.environ["PYTHON_VERSIONS"].split(),
4067
"organization": os.environ["ORGANIZATION"],
41-
"repository": os.environ["REPOSITORY"]
68+
"repository": os.environ["REPOSITORY"],
69+
"platforms": platform.split(','),
70+
"variants": variants
4271
}
4372

4473
for template_var in subtemplates:

templates/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ This project actively supports these Python versions:
1717

1818
Like the upstream Python containers themselves a variety of image variants are supported.
1919

20+
{% if "full" in variants %}
2021
### Full
2122

2223
The default container type, and if you're not sure what container to use start here. It has a variety of libraries and build tools installed, making it easy to extend.
24+
{% endif %}
2325

26+
{% if "slim" in variants %}
2427
### Slim
2528

2629
This container is similar to Full but with far less libraries and tools installed by default. If yo're looking for the tiniest possible image with the most stability this is your best bet.
30+
{% endif %}
2731

32+
{% if "alpine" in variants %}
2833
### Alpine
2934

3035
This container is provided for those who wish to use Alpine. Alpine works a bit differently than the other image types, as it uses `musl` instead of `glibc` and many libaries are not well tested under `musl` at this time.
36+
{% endif %}
37+
3138

3239
## Architectures
3340

3441
Every tag in this repository supports these architectures:
3542

36-
* linux/amd64
37-
* linux/arm64
38-
* linux/arm/v7
43+
{% for platform in platforms -%}
44+
* {{ platform }}
45+
{% endfor %}
46+
3947

4048
{{ tags }}
4149

templates/tags.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
Tags are based on the package version, python version, and the upstream container the container is based on.
88

9-
| {{ package }} Version | Python Version | Full Container | Slim Container | Alpine Container |
10-
|-----------------------|----------------|----------------|----------------|------------------|
9+
| {{ package }} Version | Python Version | Full Container | Slim Container |{{ ' Alpine Container |' if "alpine" in variants }}
10+
|-----------------------|----------------|----------------|----------------|{{ '------------------|' if "alpine" in variants }}
1111
{%- for package_version in ["latest"] + package_versions|reverse|list -%}
1212
{%- for python_version in python_versions|reverse %}
13-
| {{ package_version }} | {{ python_version }} | py{{ python_version }}-{{ package_version }} | py{{ python_version }}-slim-{{ package_version }} | py{{ python_version }}-alpine-{{ package_version }} |
13+
| {{ package_version }} | {{ python_version }} | py{{ python_version }}-{{ package_version }} | py{{ python_version }}-slim-{{ package_version }} |{{ " py"+ python_version +"-alpine-"+ package_version +" |" if "alpine" in variants }}
1414
{%- endfor %}
1515
{%- endfor %}
1616

0 commit comments

Comments
 (0)