Use the badge from the project itself. Rely on the API to build the document
This commit is contained in:
+4
-4
@@ -28,7 +28,7 @@ build:
|
|||||||
extends: .parallel
|
extends: .parallel
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_TAG
|
- 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"
|
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_PIPELINE == "weekly-build"
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
@@ -52,7 +52,7 @@ test:
|
|||||||
- TARGET: unstable
|
- TARGET: unstable
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_TAG
|
- 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"
|
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULED_PIPELINE == "weekly-build"
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
@@ -85,7 +85,7 @@ publish-images:
|
|||||||
make-documents:
|
make-documents:
|
||||||
stage: release
|
stage: release
|
||||||
before_script:
|
before_script:
|
||||||
- apk add bash git curl jq make py3-jinja2
|
- apk add bash git curl jq make py3-jinja2 py3-gitlab
|
||||||
script:
|
script:
|
||||||
- make documents
|
- make documents
|
||||||
needs:
|
needs:
|
||||||
@@ -144,4 +144,4 @@ weekly-build-scheduler:
|
|||||||
|
|
||||||
code_quality:
|
code_quality:
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_APPROVED != "true"
|
- if: $CI_MERGE_REQUEST_APPROVED
|
||||||
|
|||||||
@@ -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
|
## [3.2.0] - 2024/06/06
|
||||||
### Changed
|
### Changed
|
||||||
- Changed the group _users_ GID from 100 to 90. This allow to use the GID 100. (#64)
|
- Changed the group _users_ GID from 100 to 90. This allow to use the GID 100. (#64)
|
||||||
|
|||||||
@@ -1,18 +1,3 @@
|
|||||||
[![][badge-pipeline]][url-pipelines]
|
{% for name, links in badges.items() -%}
|
||||||
[![][badge-image-size]][url-docker]
|
[]({{links.link}})
|
||||||
[![][badge-pulls]][url-docker]
|
{% endfor %}
|
||||||
[![][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
|
|
||||||
|
|||||||
+77
-39
@@ -2,54 +2,92 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
from gitlab import Gitlab
|
||||||
|
|
||||||
|
|
||||||
REPOSITORY_PATH = Path(__file__).parent.parent
|
REPOSITORY_PATH = Path(__file__).parent.parent
|
||||||
|
|
||||||
# Argument parsing.
|
class DocumentMaker:
|
||||||
parser = argparse.ArgumentParser(prog="Seafile Docker client documentation renderer")
|
|
||||||
parser.add_argument("template", type=str)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
# Setup Jinja2 templater
|
def __init__(self, filename: str) -> None:
|
||||||
documentations_path = REPOSITORY_PATH.joinpath("documentations")
|
# Intanciate the Jinja2 renderer.
|
||||||
loader = FileSystemLoader(documentations_path)
|
self.directory = REPOSITORY_PATH.joinpath("documentations")
|
||||||
environment = Environment(loader=loader)
|
loader = FileSystemLoader(self.directory)
|
||||||
template = environment.get_template(args.template)
|
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=[]
|
def get_badges(self):
|
||||||
for path in Path("versions").iterdir():
|
badges = self.project.badges.list()
|
||||||
with open(path, "rt") as fo:
|
|
||||||
buffer.append(fo.read().strip())
|
|
||||||
buffer.sort(reverse=True)
|
|
||||||
|
|
||||||
# Prepare the render context.
|
for badge in badges:
|
||||||
latest = True
|
name = badge.name
|
||||||
versions = []
|
link = badge.rendered_link_url
|
||||||
for line in buffer:
|
image = badge.rendered_image_url
|
||||||
version = line.strip()
|
links = {"link": link, "image": image}
|
||||||
parts = version.split(".")
|
self.badges[name] = links
|
||||||
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)
|
|
||||||
|
|
||||||
# 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
|
def render(self):
|
||||||
with open(document, mode="w") as fo:
|
# Render
|
||||||
fo.write(content)
|
# 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()
|
||||||
Reference in New Issue
Block a user