Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: pre-release

on:
push:
tags: [ "[0-9]+.[0-9]+.[0-9]+*" ]

jobs:
create-pre-release:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout commit
uses: actions/checkout@v6
with:
sparse-checkout: |
cliff.toml
sparse-checkout-cone-mode: false
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
with:
version: 1.0.0-pre1
- name: Use cargo cache
id: cache-cargo
uses: actions/cache@v4
with:
path: |
~/.cargo
key: gh-release-${{ runner.os }}-cargo-${{ hashFiles('~/.cargo/.crates.toml') }}
restore-keys: gh-release-${{ runner.os }}-cargo-
- name: Install git-cliff
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: |
cargo install git-cliff
- name: Get the Git tag name
id: get-tag-name
run: echo "tag-name=${GITHUB_REF/refs\/tags\//}" | tee -a "$GITHUB_OUTPUT"
- id: release
name: Create changelog and release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gl-gh-release create \
--repo "python-gardenlinux-lib" \
--tag "${{ steps.get-tag-name.outputs.tag-name }}" \
--commit "${{ github.sha }}" \
--name 'python-gardenlinux-lib v${{ steps.get-tag-name.outputs.tag-name }}' \
--latest \
--body "
$(git-cliff -o - --current)
"
84 changes: 84 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[changelog]
# A Tera template to be rendered as the changelog's header.
# See https://keats.github.io/tera/docs/#introduction
header = """
{% if version -%}
# Changelog for {{ version }} }}
{% else -%}
# Changelog
{% endif -%}

All notable changes since last release will be documented below.
"""
# A Tera template to be rendered for each release in the changelog.
# See https://keats.github.io/tera/docs/#introduction
body = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}

{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{%- for commit in commits %}
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
{% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
{% if commit.remote.pr_number %} in \
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
{%- endif -%}
{% endfor %}
{% endfor %}
"""
# A Tera template to be rendered as the changelog's footer.
# See https://keats.github.io/tera/docs/#introduction
footer = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}

{% for release in releases -%}
{% if release.version -%}
{% if release.previous.version -%}
[{{ release.version | trim_start_matches(pat="v") }}]: \
{{ self::remote_url() }}/compare/{{ release.previous.version }}...{{ release.version }}
{% endif -%}
{% else -%}
[unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}...HEAD
{% endif -%}
{% endfor %}
<!-- generated by git-cliff -->
"""
# Remove leading and trailing whitespaces from the changelog's body.
trim = true

[git]
# Parse commits according to the conventional commits specification.
# See https://www.conventionalcommits.org
conventional_commits = true
# Exclude commits that do not match the conventional commits specification.
filter_unconventional = false
# An array of regex based parsers for extracting data from the commit message.
# Assigns commits to groups.
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
commit_parsers = [
{ message = "^[a|A]dd", group = "Added" },
{ message = "^[s|S]upport", group = "Added" },
{ message = "^[r|R]emove", group = "Removed" },
{ message = "^.*: add", group = "Added" },
{ message = "^.*: support", group = "Added" },
{ message = "^.*: remove", group = "Removed" },
{ message = "^.*: delete", group = "Removed" },
{ message = "^test", group = "Fixed" },
{ message = "^fix", group = "Fixed" },
{ message = "^.*: fix", group = "Fixed" },
{ message = "^.*", group = "Changed" },
]
# Prevent commits that are breaking from being excluded by commit parsers.
filter_commits = false
# Order releases topologically instead of chronologically.
topo_order = true
# Order of commits in each group/release within the changelog.
# Allowed values: newest, oldest
sort_commits = "oldest"
98 changes: 97 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ networkx = "^3.6"
oras = "^0.2.38"
pygit2 = "^1.19.0"
pygments = "^2.19.2"
PyGithub = "^2.8.1"
PyYAML = "^6.0.2"
gitpython = "^3.1.45"

Expand Down
9 changes: 9 additions & 0 deletions src/gardenlinux/github/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

"""
GitHub module
"""

from .client import Client

__all__ = ["Client"]
73 changes: 73 additions & 0 deletions src/gardenlinux/github/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-

"""
GitHub client
"""

from logging import Logger
from os import environ
from typing import Any, Optional

from github import Auth, Github

from ..logger import LoggerSetup


class Client(object):
"""
GitHub client instance to provide methods for interaction with GitHub API.

:author: Garden Linux Maintainers
:copyright: Copyright 2024 SAP SE
:package: gardenlinux
:subpackage: github
:since: 1.0.0
:license: https://www.apache.org/licenses/LICENSE-2.0
Apache License, Version 2.0
"""

def __init__(self, token: Optional[str] = None, logger: Optional[Logger] = None):
"""
Constructor __init__(Client)

:param token: GitHub access token
:param logger: Logger instance

:since: 1.0.0
"""

self._client = None
self._token = token

if self._token is None or self._token.strip() == "":
self._token = environ.get("GITHUB_TOKEN")

if self._token is None:
raise ValueError("GITHUB_TOKEN environment variable not set")

if logger is None or not logger.hasHandlers():
logger = LoggerSetup.get_logger("gardenlinux.github")

self._logger = logger

@property
def instance(self) -> Github:
if self._client is None:
self._client = Github(auth=Auth.Token(self._token))

return self._client

def __getattr__(self, name: str) -> Any:
"""
python.org: Called when an attribute lookup has not found the attribute in
the usual places (i.e. it is not an instance attribute nor is it found in the
class tree for self).

:param name: Attribute name

:return: (mixed) Attribute
:since: 0.8.0
"""

self._logger.debug(f"gardenlinux.github.Client.{name} accessed")
return getattr(self.instance, name)
Loading
Loading