Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ jobs:
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
check.trivy.dev:443
download.docker.com:443
fulcio.sigstore.dev:443
ghcr.io:443
github.com:443
githubapp.com:443
index.docker.io:443
mirror.gcr.io:443
objects.githubusercontent.com:443
Expand All @@ -95,6 +95,7 @@ jobs:
registry-1.docker.io:443
rekor.sigstore.dev:443
release-assets.githubusercontent.com:443
trivy.dev:443
${{ inputs.egress-policy-allowlist }}
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/local-auto-tagger-docker-bp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
with:
egress-policy-allowlist: >
dl-cdn.alpinelinux.org:443
pypi.org:443
files.pythonhosted.org:443
pypi.org:443
image: notdodo/auto-tagger
push: true
registry: ghcr.io
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ jobs:
static.rust-lang.org:443
sts.eu-west-1.amazonaws.com:443
zig.linus.dev:443
zig.nekos.space:443
ziglang.org:443
zigmirror.hryx.net:443
zigmirror.nesovic.dev:443
zig.nekos.space:443
${{ inputs.egress-policy-allowlist }}
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
Expand Down
File renamed without changes.
39 changes: 24 additions & 15 deletions auto-tagger/configuration.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
"""
Module with the configuration of the action
"""
"""Configuration helpers for the GitHub Action."""

from __future__ import annotations

import os
from dataclasses import dataclass
from enum import StrEnum
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterable

from github_resources import Commit
from github_resources import Commit


class BumpStrategy(StrEnum):
"""Enum containing the different version bump strategy for semver"""
"""Enum containing the different version bump strategy for semver."""

MAJOR = "major"
MINOR = "minor"
PATCH = "patch"
SKIP = "skip"


def _env_flag(var_name: str, *, default: bool) -> bool:
"""Return a boolean flag from an environment variable using a safe default."""
return os.environ.get(var_name, str(default)).strip().lower() == "true"


@dataclass
class Configuration:
"""Configuration resource"""
"""Configuration resource populated from the environment."""

BIND_TO_MAJOR: bool = False
DEFAULT_BUMP_STRATEGY: BumpStrategy = BumpStrategy.SKIP
Expand All @@ -32,11 +41,10 @@ class Configuration:
DRY_RUN: bool = False

@classmethod
def from_env(cls) -> "Configuration":
"""Create default configuration instance with values from env variables"""
def from_env(cls) -> Configuration:
"""Create default configuration instance with values from env variables."""
return cls(
BIND_TO_MAJOR=os.environ.get("INPUT_BIND_TO_MAJOR", cls.BIND_TO_MAJOR)
== "true",
BIND_TO_MAJOR=_env_flag("INPUT_BIND_TO_MAJOR", default=cls.BIND_TO_MAJOR),
DEFAULT_BUMP_STRATEGY=BumpStrategy(
os.environ.get("INPUT_DEFAULT_BUMP_STRATEGY", cls.DEFAULT_BUMP_STRATEGY)
),
Expand All @@ -45,14 +53,15 @@ def from_env(cls) -> "Configuration":
PREFIX=os.environ.get("INPUT_PREFIX", cls.PREFIX),
REPOSITORY=os.environ.get("GITHUB_REPOSITORY", ""),
SUFFIX=os.environ.get("INPUT_SUFFIX", cls.SUFFIX),
DRY_RUN=os.environ.get("INPUT_DRY_RUN", cls.DRY_RUN) == "true",
DRY_RUN=_env_flag("INPUT_DRY_RUN", default=cls.DRY_RUN),
)

def get_bump_strategy_from_commits(self, commits: list[Commit]) -> BumpStrategy:
"""Get the bump strategy from a list of commits parsing the keywords [#<strategy>]"""
strategies = [strategy.value for strategy in BumpStrategy]
def get_bump_strategy_from_commits(self, commits: Iterable[Commit]) -> BumpStrategy:
"""Get the bump strategy from a list of commits parsing the keywords [#<strategy>]."""
strategies = tuple(strategy.value for strategy in BumpStrategy)
for commit in commits:
lowered_message = commit.message.lower()
for strategy in strategies:
if f"[#{strategy.lower()}]" in commit.message:
if f"[#{strategy}]" in lowered_message:
return BumpStrategy(strategy)
return self.DEFAULT_BUMP_STRATEGY
Loading
Loading