Skip to content

Commit

Permalink
Update applications-download, uses jsonschema-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 8, 2024
1 parent 7c79a73 commit 69e7e9c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
datasourceTemplate: 'python-version',
depNameTemplate: 'python',
},
{
fileMatch: ['^tag_publish/versions.yaml$'],
matchStrings: ['(?<depName>.*): (?<currentValue>.*) # (?<datasource>.*)'],
},
],
packageRules: [
/** Automerge the patch, the minor and the dev dependency */
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ twine = "5.1.1"
PyYAML = "6.0.2"
id = "1.4.0"
security-md = "0.2.3"
application-download = "0.0.1.dev3"
applications-download = "0.7.1"
jsonschema-validator-new = "0.1.0"
PyGithub = "2.5.0"
debian-inspector = "31.1.0"
multi-repo-automation = "1.4.1"
Expand Down
44 changes: 36 additions & 8 deletions tag_publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
Tag Publish main module.
"""

import json
import os.path
import pkgutil
import re
import subprocess # nosec
from re import Match, Pattern
from typing import Any, Optional, TypedDict, cast
from typing import Any, Optional, TypedDict, TypeVar, cast

import application_download.cli
import applications_download
import github
import jsonschema_validator
import requests
import ruamel.yaml
import security_md
import yaml

import tag_publish.configuration

Expand Down Expand Up @@ -94,9 +98,14 @@ def get_config(gh: GH) -> tag_publish.configuration.Configuration:
"""
config: tag_publish.configuration.Configuration = {}
if os.path.exists(".github/publish.yaml"):
schema_data = pkgutil.get_data("tag_publish", "schema.json")
assert schema_data is not None
schema = json.loads(schema_data)

with open(".github/publish.yaml", encoding="utf-8") as open_file:
yaml_ = ruamel.yaml.YAML()
config = yaml_.load(open_file)
jsonschema_validator.validate(".github/publish.yaml", cast(dict[str, Any], config), schema)

merge(
{
Expand Down Expand Up @@ -235,17 +244,36 @@ def add_authorization_header(headers: dict[str, str]) -> dict[str, str]:
return headers


BINARY_FILENAME = TypeVar("T", str, Optional[str])


def download_application(application_name: str, binary_filename: BINARY_FILENAME = None) -> BINARY_FILENAME:
"""
Download the application if necessary, with the included version.
"""
binary_full_filename = (
os.path.expanduser(os.path.join("~", ".local", "bin", binary_filename)) if binary_filename else None
)

if not os.path.exists(binary_full_filename) if binary_full_filename else True:
applications = applications_download.load_applications(None)
versions_data = pkgutil.get_data("tag_publish", "versions.yaml")
assert versions_data is not None
versions = yaml.safe_load(versions_data)
applications_download.download_applications(
applications, {application_name: versions[application_name]}
)

return binary_full_filename


def snyk_exec() -> tuple[str, dict[str, str]]:
"""Get the Snyk cli executable path."""
env = {**os.environ}
env["FORCE_COLOR"] = "true"
snyk_bin = os.path.expanduser(os.path.join("~", ".local", "bin", "snyk"))

if not os.path.exists(snyk_bin):
folder = os.path.expanduser(os.path.join("~", ".config", "application_download"))
if not os.path.exists(folder):
os.makedirs(folder)
application_download.cli.download_application("snyk/cli")
snyk_bin = download_application("snyk/cli", "snyk")
assert snyk_bin is not None

if "SNYK_TOKEN" not in env:
env["SNYK_TOKEN"] = subprocess.run(
Expand Down
5 changes: 2 additions & 3 deletions tag_publish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from re import Match
from typing import Optional, cast

import application_download.cli
import security_md
import yaml

Expand Down Expand Up @@ -219,7 +218,7 @@ def _handle_pypi_publish(
if "packages" in pypi_config:
tag_publish.lib.oidc.pypi_login()

for package in pypi_config["packages"]:
for package in pypi_config.get("packages", []):
if package.get("group", tag_publish.configuration.PIP_PACKAGE_GROUP_DEFAULT) == group:
publish = version_type in pypi_config.get(
"versions", tag_publish.configuration.PYPI_VERSIONS_DEFAULT
Expand Down Expand Up @@ -466,7 +465,7 @@ def _handle_helm_publish(
if helm_config.get("folders") and version_type in helm_config.get(
"versions", tag_publish.configuration.HELM_VERSIONS_DEFAULT
):
application_download.cli.download_application("helm/chart-releaser")
tag_publish.download_application("helm/chart-releaser")

owner = github.repo.owner.login
repo = github.repo.name
Expand Down
File renamed without changes.

0 comments on commit 69e7e9c

Please sign in to comment.