Merge branch '62-use-the-badge-from-the-project-itself-rely-on-the-api-to-build-the-document' into 'master'

Use the badge from the project itself. Rely on the API to build the document

Closes #62

See merge request florian.anceau-oss/docker-seafile-client!17
This commit is contained in:
Florian Anceau
2024-06-09 10:38:03 +00:00
4 changed files with 93 additions and 61 deletions

View File

@@ -28,7 +28,7 @@ build:
extends: .parallel
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_APPROVED != "true"
- if: $CI_MERGE_REQUEST_APPROVED
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_PIPELINE == "weekly-build"
artifacts:
paths:
@@ -52,7 +52,7 @@ test:
- TARGET: unstable
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_APPROVED != "true"
- if: $CI_MERGE_REQUEST_APPROVED
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_PIPELINE == "weekly-build"
artifacts:
paths:
@@ -85,7 +85,7 @@ publish-images:
make-documents:
stage: release
before_script:
- apk add bash git curl jq make py3-jinja2
- apk add bash git curl jq make py3-jinja2 py3-gitlab
script:
- make documents
needs:
@@ -144,4 +144,4 @@ weekly-build-scheduler:
code_quality:
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_APPROVED != "true"
- if: $CI_MERGE_REQUEST_APPROVED

View File

@@ -19,6 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- --/>
-->
## [3.2.1] - 2024/06/09
### Added
- Merge requests pipeline only runs when merge request has been approved.
### Changed
- Badges are rendered from the Gitlab project itself, not from code. (#62)
[3.2.1]: [url_to_tag](https://gitlab.com/florian.anceau/docker-seafile-client/-/tags/3.2.0)
<!-- /3.2.1 -->
## [3.2.0] - 2024/06/06
### Changed
- Changed the group _users_ GID from 100 to 90. This allow to use the GID 100. (#64)

View File

@@ -1,18 +1,3 @@
[![][badge-pipeline]][url-pipelines]
[![][badge-image-size]][url-docker]
[![][badge-pulls]][url-docker]
[![][badge-release]][url-sources]
[![][badge-license]][url-sources]
[![][badge-sponsoring]][url-sponsoring]
[url-pipelines]: https://gitlab.com/florian.anceau/docker-seafile-client/badges/master/pipeline.svg
[url-docker]: https://hub.docker.com/r/flowgunso/seafile-client
[url-sources]: https://gitlab.com/florian.anceau/docker-seafile-client/
[url-sponsoring]: https://liberapay.com/docker-seafile-client/donate
[badge-pipeline]: https://img.shields.io/gitlab/pipeline-status/florian.anceau%2Fdocker-seafile-client
[badge-image-size]: https://img.shields.io/docker/image-size/flowgunso/seafile-client/latest?logo=docker&label=Image%20size&color=%230778b8
[badge-pulls]: https://img.shields.io/docker/pulls/flowgunso/seafile-client?logo=docker&label=Pulls&color=%230778b8
[badge-license]: https://img.shields.io/gitlab/license/11322291?label=License&color=fca326
[badge-release]: https://img.shields.io/gitlab/v/release/11322291?logo=gitlab&label=Source%20code&color=fca326
[badge-sponsoring]: https://img.shields.io/liberapay/receives/docker-seafile-client.svg?logo=liberapay
{% for name, links in badges.items() -%}
[![{{name}}]({{links.image}})]({{links.link}})
{% endfor %}

View File

@@ -2,54 +2,92 @@
from pathlib import Path
import argparse
import os
from jinja2 import Environment, FileSystemLoader
from gitlab import Gitlab
REPOSITORY_PATH = Path(__file__).parent.parent
# Argument parsing.
parser = argparse.ArgumentParser(prog="Seafile Docker client documentation renderer")
parser.add_argument("template", type=str)
args = parser.parse_args()
class DocumentMaker:
# Setup Jinja2 templater
documentations_path = REPOSITORY_PATH.joinpath("documentations")
loader = FileSystemLoader(documentations_path)
environment = Environment(loader=loader)
template = environment.get_template(args.template)
def __init__(self, filename: str) -> None:
# Intanciate the Jinja2 renderer.
self.directory = REPOSITORY_PATH.joinpath("documentations")
loader = FileSystemLoader(self.directory)
environment = Environment(loader=loader)
self.filename = filename
self.template = environment.get_template(filename)
# Instanciate the Gitlab session.
gitlab_project_id=os.environ["CI_PROJECT_ID"]
gitlab_private_token=os.environ["WEEKLY_BUILD_PRIVATE_TOKEN"]
self.gitlab = Gitlab(private_token=gitlab_private_token)
self.project = self.gitlab.projects.get(gitlab_project_id)
self.versions = []
self.badges = {}
def get_versions(self):
versions = []
for path in Path("versions").iterdir():
with open(path, "rt") as fo:
versions.append(fo.read().strip())
versions.sort(reverse=True)
# Prepare the render context.
latest = True
self.versions = []
for version in versions:
version = version.strip()
parts = version.split(".")
increments = []
blocks = []
for part in parts:
increments.append(part)
section = ".".join(increments)
blocks.append(f"`{section}`")
if latest:
blocks.append("`latest`")
latest = False
self.versions.append(blocks)
buffer=[]
for path in Path("versions").iterdir():
with open(path, "rt") as fo:
buffer.append(fo.read().strip())
buffer.sort(reverse=True)
def get_badges(self):
badges = self.project.badges.list()
# Prepare the render context.
latest = True
versions = []
for line in buffer:
version = line.strip()
parts = version.split(".")
increments = []
blocks = []
for part in parts:
increments.append(part)
section = ".".join(increments)
blocks.append(f"`{section}`")
if latest:
blocks.append("`latest`")
latest = False
versions.append(blocks)
for badge in badges:
name = badge.name
link = badge.rendered_link_url
image = badge.rendered_image_url
links = {"link": link, "image": image}
self.badges[name] = links
# Render
# TODO: read and adapt the CHANGELOG and insert into the render.
content = template.render(versions=versions)
#content = template.render() # When version/ is unavailable.
filename = Path(args.template).with_suffix("")
document = documentations_path.joinpath(filename)
# Write to file
with open(document, mode="w") as fo:
fo.write(content)
def render(self):
# Render
# TODO: read and adapt the CHANGELOG and insert into the render.
content = self.template.render(versions=self.versions, badges=self.badges)
#content = template.render() # When version/ is unavailable.
filename = Path(self.filename).with_suffix("")
path = self.directory.joinpath(filename)
# Write to file
with open(path, mode="w") as fo:
fo.write(content)
if __name__ == "__main__":
# Argument parsing.
parser = argparse.ArgumentParser(prog="Seafile Docker client documentation renderer")
parser.add_argument("template", type=str)
args = parser.parse_args()
maker = DocumentMaker(args.template)
maker.get_versions()
maker.get_badges()
maker.render()