Update the build badge date on builds

This commit is contained in:
Florian Anceau
2024-06-27 06:37:32 +00:00
parent 214bb03a2b
commit b2e855ec52
4 changed files with 43 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ make-documents:
publish-documents:
stage: release
before_script:
- apk add bash git curl jq make
- apk add bash git curl jq make py3-gitlab
script:
- make publish-documents
needs:

View File

@@ -19,6 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- --/>
-->
## [3.2.3] - 2024/06/27
### Changed
- Update the build badge date on builds. (#61)
[3.2.3]: https://gitlab.com/florian.anceau/docker-seafile-client/-/tags/3.2.3
<!-- /3.2.3 -->
## [3.2.2] - 2024/06/09
### Fixed
- Allow the latest tag to be applied to the v9 versions. (#54)

View File

@@ -40,6 +40,7 @@ publish-images:
publish-documents:
bash scripts/publish-documents.sh
python scripts/update-build-badge.py
save:
mkdir -p tarballs/

View File

@@ -0,0 +1,34 @@
# !/usr/bin/env python
import os
from datetime import datetime
from gitlab import Gitlab
class BuildBadgeUpdater:
def __init__(self, gitlab_private_token, gitlab_project_id, gitlab_build_badge_id):
# Instanciate the Gitlab session and grab the Weekly build scheduled pipeline.
self.gitlab = Gitlab(private_token=gitlab_private_token)
project = self.gitlab.projects.get(gitlab_project_id)
self.badge = project.badges.get(gitlab_build_badge_id)
def update(self):
now = datetime.now()
date = now.strftime(r"%Y--%m--%d")
image_url = f"https://img.shields.io/badge/_-{date}-_?label=last%20build&color=light-green"
self.badge.image_url = image_url
self.badge.save()
if __name__ == "__main__":
build_badge_updater = BuildBadgeUpdater(
gitlab_project_id=os.environ["CI_PROJECT_ID"],
gitlab_private_token=os.environ["WEEKLY_BUILD_PRIVATE_TOKEN"],
gitlab_build_badge_id=os.environ["BUILD_BADGE_ID"]
)
build_badge_updater.update()