Skip to content

Commit c462e22

Browse files
authored
Merge pull request package-url#514 from package-url/purl_type_schema-refined
Refine Purl type schema
2 parents 3f9cd76 + 526126f commit c462e22

121 files changed

Lines changed: 11169 additions & 1280 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Check and generate PURL Type Docs and Index
2+
3+
on:
4+
push:
5+
paths:
6+
- "types/*.json"
7+
- "schemas/*.json"
8+
- "etc/"
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
# All permissions should be specified at the job level
13+
permissions: { }
14+
15+
jobs:
16+
generate-index-and-docs:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
content: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.x'
29+
30+
- name: Install dependencies
31+
run: make conf
32+
33+
- name: Validate code and data formats
34+
run: make check
35+
36+
- name: Generate index and docs
37+
run: make gendocs
38+
39+
- name: Commit and push changes
40+
run: |
41+
git config --global user.name "github-actions[bot]"
42+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
43+
git add types/ types-doc/
44+
git commit -s -m "Generate updated PURL type documentation" || echo "No changes to commit"
45+
git push

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/tmp/
2+
/venv/
3+
/.python-version
4+
.ruff_cache/

Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (c) the purl authors
3+
# Visit https://github.com/package-url/purl-spec and https://packageurl.org for support
4+
5+
PYTHON_EXE?=python3
6+
VENV_LOCATION=venv
7+
ACTIVATE?=. ${VENV_LOCATION}/bin/activate;
8+
9+
CODEGEN?=datamodel-codegen \
10+
--target-python-version 3.10 \
11+
--use-double-quotes \
12+
--use-exact-imports \
13+
--use-standard-collections \
14+
--wrap-string-literal \
15+
--enum-field-as-literal all \
16+
--formatters ruff-format \
17+
--field-constraints \
18+
--disable-timestamp \
19+
--keep-model-order \
20+
--custom-file-header-path LICENSE \
21+
--input-file-type jsonschema \
22+
--output-model-type pydantic_v2.BaseModel
23+
24+
virtualenv:
25+
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
26+
${PYTHON_EXE} -m venv ${VENV_LOCATION}
27+
28+
conf: virtualenv
29+
@echo "-> Install dependencies"
30+
@${ACTIVATE} pip install -r etc/scripts/requirements.txt
31+
32+
formatcode:
33+
@echo "-> Run Ruff format"
34+
@${ACTIVATE} ruff check --select I --fix
35+
@${ACTIVATE} ruff format
36+
@echo "-> Run Ruff linter"
37+
@${ACTIVATE} ruff check --fix
38+
39+
formatjson:
40+
@echo "-> Format JSON files"
41+
@${ACTIVATE} python etc/scripts/format_json.py schemas/
42+
@${ACTIVATE} python etc/scripts/format_json.py types/
43+
@${ACTIVATE} python etc/scripts/format_json.py tests/
44+
45+
format: formatcode formatjson
46+
@echo "-> Format all files"
47+
48+
checkjson:
49+
@echo "-> Validate JSON schemas"
50+
@${ACTIVATE} check-jsonschema --check-metaschema --verbose schemas/*.json
51+
@echo "-> Validate JSON data files against the schemas"
52+
@${ACTIVATE} check-jsonschema --schemafile schemas/purl-types-index.schema.json --verbose purl-types-index.json
53+
@${ACTIVATE} check-jsonschema --schemafile schemas/purl-type-definition.schema.json --verbose types/*-definition.json
54+
@${ACTIVATE} check-jsonschema --schemafile schemas/purl-test.schema.json --verbose tests/*/*-test.json
55+
56+
checkcode:
57+
@echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)"
58+
@${ACTIVATE} ruff --config etc/scripts/pyproject.toml check
59+
@echo "-> Run Ruff format validation"
60+
@${ACTIVATE} ruff --config etc/scripts/pyproject.toml format --check
61+
62+
check: checkjson checkcode
63+
@echo "-> Run all checks"
64+
65+
clean:
66+
@echo "-> Clean the Python env"
67+
rm -rf .venv/
68+
find . -type f -name '*.py[co]' -delete
69+
70+
gencode:
71+
@echo "-> Generate Python code from schemas"
72+
@${ACTIVATE} ${CODEGEN} \
73+
--input schemas/purl-types-index.schema.json \
74+
--output etc/scripts/purl_types_index.py
75+
@${ACTIVATE} ${CODEGEN} \
76+
--input schemas/purl-type-definition.schema.json \
77+
--output etc/scripts/purl_type_definition.py
78+
@${ACTIVATE} ${CODEGEN} \
79+
--input schemas/purl-test.schema.json \
80+
--output etc/scripts/purl_test.py
81+
@echo "-> Run Black format for generated code"
82+
@${ACTIVATE} black -l 100 --preview --enable-unstable-feature string_processing etc/scripts/*.py
83+
84+
gendocs:
85+
@${ACTIVATE} python etc/scripts/generate_index_and_docs.py
86+
87+
88+
.PHONY: virtualenv conf formatcode formatjson format checkcode checkjson check clean gencode gendocs

0 commit comments

Comments
 (0)