Skip to content

Commit 72f5382

Browse files
committed
schema package: Build a python package for the schema
This will allow schema users to pip install the schema instead of using something like git submodules to place the schema files at some local path. Signed-off-by: BJ Hargrave <[email protected]>
1 parent 126c5ad commit 72f5382

25 files changed

+583
-38
lines changed

.github/dependabot.yml

-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,3 @@ updates:
1313
directory: "/.github/workflows"
1414
schedule:
1515
interval: "daily"
16-
17-
# Maintain dependencies for Python scripts
18-
- package-ecosystem: "pip"
19-
directory: "/.github/scripts"
20-
schedule:
21-
interval: "daily"

.github/scripts/requirements.txt

-3
This file was deleted.

.github/workflows/actionlint.yml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3939
with:
4040
fetch-depth: 0
41-
submodules: true
4241

4342
- name: "Download actionlint"
4443
run: |

.github/workflows/docs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4141
with:
4242
fetch-depth: 0
43-
submodules: true
4443
- name: "Check Markdown documents"
4544
uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16.0.0
4645
with:

.github/workflows/lint.yml

+39-26
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
name: Lint Schema
3+
name: Lint
44

55
on:
6-
workflow_dispatch:
76
push:
87
branches:
9-
- main
8+
- "main"
109
paths:
11-
- 'v*/**/*.json'
10+
- '**.py'
11+
- 'src/instructlab/schema/v*/**/*.json'
12+
- 'pyproject.toml'
13+
- 'tox.ini'
14+
- 'scripts/**'
1215
- '.github/workflows/lint.yml' # This workflow
13-
- '.github/scripts/**' # Scripts used by this workflow
1416

1517
pull_request:
1618
branches:
17-
- main
19+
- "main"
1820
paths:
19-
- 'v*/**/*.json'
21+
- '**.py'
22+
- 'src/instructlab/schema/v*/**/*.json'
23+
- 'pyproject.toml'
24+
- 'tox.ini'
25+
- 'scripts/**'
2026
- '.github/workflows/lint.yml' # This workflow
21-
- '.github/scripts/**' # Scripts used by this workflow
2227

2328
env:
2429
LC_ALL: en_US.UTF-8
@@ -33,6 +38,25 @@ permissions:
3338
jobs:
3439
lint:
3540
runs-on: ubuntu-latest
41+
name: "${{ matrix.lint.name }}"
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
lint:
46+
- name: "jsonschema"
47+
commands: |
48+
tox -e jsonschema
49+
- name: "ruff"
50+
commands: |
51+
tox -e ruff -- check
52+
- name: "pylint"
53+
commands: |
54+
echo "::add-matcher::.github/workflows/matchers/pylint.json"
55+
tox -e pylint
56+
- name: "mypy"
57+
commands: |
58+
echo "::add-matcher::.github/workflows/matchers/mypy.json"
59+
tox -e mypy
3660
steps:
3761
- name: "Harden Runner"
3862
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
@@ -49,24 +73,13 @@ jobs:
4973
with:
5074
python-version: "3.11"
5175

52-
- name: "Install Python Packages"
76+
- name: "Install tox"
5377
run: |
54-
pip install -r .github/scripts/requirements.txt
78+
python -m pip install --upgrade pip
79+
python -m pip install tox tox-gh
5580
56-
- name: "Find changed schema files"
57-
id: changed-files
58-
uses: tj-actions/changed-files@d6babd6899969df1a11d14c368283ea4436bca78 # v44.5.2
59-
with:
60-
files: |
61-
v*/**/*.json
62-
63-
- name: "Check changed schema file contents"
64-
if: steps.changed-files.outputs.any_changed == 'true'
65-
run: |
66-
check-jsonschema --verbose --schemafile https://json-schema.org/draft/2020-12/schema ${{ steps.changed-files.outputs.all_changed_files }}
67-
68-
- name: "Check all schema file contents"
69-
if: steps.changed-files.outputs.any_changed != 'true'
81+
- name: "${{ matrix.lint.name }}"
7082
run: |
71-
# shellcheck disable=SC2046
72-
check-jsonschema --verbose --schemafile https://json-schema.org/draft/2020-12/schema $(find v* -name "*.json")
83+
${{ matrix.lint.commands }}
84+
env:
85+
RUFF_OUTPUT_FORMAT: github

.github/workflows/matchers/mypy.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "mypy",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):(\\d+):\\s(error|warning):\\s(.+)$",
8+
"file": 1,
9+
"line": 2,
10+
"severity": 3,
11+
"message": 4
12+
}
13+
]
14+
}
15+
]
16+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "pylint-error",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{4}):\\s.+)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"message": 4,
13+
"code": 5
14+
}
15+
]
16+
},
17+
{
18+
"owner": "pylint-warning",
19+
"severity": "warning",
20+
"pattern": [
21+
{
22+
"regexp": "^(.+):(\\d+):(\\d+):\\s(([CRW]\\d{4}):\\s.+)$",
23+
"file": 1,
24+
"line": 2,
25+
"column": 3,
26+
"message": 4,
27+
"code": 5
28+
}
29+
]
30+
}
31+
]
32+
}

.github/workflows/pypi.yml

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
name: Build, test, and upload PyPI package
4+
5+
on:
6+
push:
7+
branches:
8+
- "main"
9+
tags:
10+
- "v*"
11+
pull_request:
12+
branches:
13+
- "main"
14+
release:
15+
types:
16+
- published
17+
18+
env:
19+
LC_ALL: en_US.UTF-8
20+
21+
defaults:
22+
run:
23+
shell: bash
24+
25+
permissions:
26+
contents: read
27+
28+
jobs:
29+
# Create and verify release artifacts
30+
# - build source dist (tar ball) and wheel
31+
# - validate artifacts with various tools
32+
# - upload artifacts to GHA
33+
build-package:
34+
name: Build and check packages
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: "Harden Runner"
38+
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
39+
with:
40+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
41+
42+
43+
- name: "Checkout"
44+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
45+
with:
46+
# for setuptools-scm
47+
fetch-depth: 0
48+
49+
- name: "Build and Inspect"
50+
uses: hynek/build-and-inspect-python-package@b4fc3f6ba2b3da04f09659be99e2a29fb6146a61 # v2.6.0
51+
52+
# push to Test PyPI on
53+
# - a new GitHub release is published
54+
# - a PR is merged into main branch
55+
publish-test-pypi:
56+
name: Publish packages to test.pypi.org
57+
# environment: publish-test-pypi
58+
if: ${{ (github.repository_owner == 'instructlab') && ((github.event.action == 'published') || ((github.event_name == 'push') && (github.ref == 'refs/heads/main'))) }}
59+
permissions:
60+
contents: read
61+
# see https://docs.pypi.org/trusted-publishers/
62+
id-token: write
63+
runs-on: ubuntu-latest
64+
needs: build-package
65+
66+
steps:
67+
- name: "Harden Runner"
68+
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
69+
with:
70+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
71+
72+
- name: "Download build artifacts"
73+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
74+
with:
75+
name: Packages
76+
path: dist
77+
78+
- name: "Upload to Test PyPI"
79+
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450 # v1.8.14
80+
with:
81+
repository-url: https://test.pypi.org/legacy/
82+
83+
# push to Production PyPI on
84+
# - a new GitHub release is published
85+
publish-pypi:
86+
name: Publish release to pypi.org
87+
# environment: publish-pypi
88+
if: ${{ (github.repository_owner == 'instructlab') && (github.event.action == 'published') }}
89+
permissions:
90+
# see https://docs.pypi.org/trusted-publishers/
91+
id-token: write
92+
# allow gh release upload
93+
contents: write
94+
95+
runs-on: ubuntu-latest
96+
needs: build-package
97+
98+
steps:
99+
- name: "Harden Runner"
100+
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
101+
with:
102+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
103+
104+
- name: "Download build artifacts"
105+
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
106+
with:
107+
name: Packages
108+
path: dist
109+
110+
- name: "Sigstore sign package"
111+
uses: sigstore/gh-action-sigstore-python@61f6a500bbfdd9a2a339cf033e5421951fbc1cd2 # v2.1.1
112+
with:
113+
inputs: |
114+
./dist/*.tar.gz
115+
./dist/*.whl
116+
117+
- name: "Upload artifacts and signatures to GitHub release"
118+
run: |
119+
gh release upload '${{ github.ref_name }}' dist/* --repo '${{ github.repository }}'
120+
env:
121+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
123+
# PyPI does not accept .sigstore artifacts and
124+
# gh-action-pypi-publish has no option to ignore them.
125+
- name: "Remove sigstore signatures before uploading to PyPI"
126+
run: |
127+
rm ./dist/*.sigstore
128+
129+
- name: "Upload to PyPI"
130+
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450 # v1.8.14

.github/workflows/test.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
name: Test
4+
5+
on:
6+
push:
7+
branches:
8+
- "main"
9+
paths:
10+
- '**.py'
11+
- 'src/instructlab/schema/v*/**/*.json'
12+
- 'pyproject.toml'
13+
- 'tox.ini'
14+
- 'scripts/**'
15+
- '.github/workflows/test.yml' # This workflow
16+
pull_request:
17+
branches:
18+
- "main"
19+
paths:
20+
- '**.py'
21+
- 'src/instructlab/schema/v*/**/*.json'
22+
- 'pyproject.toml'
23+
- 'tox.ini'
24+
- 'scripts/**'
25+
- '.github/workflows/test.yml' # This workflow
26+
27+
env:
28+
LC_ALL: en_US.UTF-8
29+
30+
defaults:
31+
run:
32+
shell: bash
33+
34+
permissions:
35+
contents: read
36+
37+
jobs:
38+
test:
39+
name: "${{ matrix.python }} on ${{ matrix.platform }}"
40+
runs-on: "${{ matrix.platform }}"
41+
strategy:
42+
matrix:
43+
python:
44+
- "3.9"
45+
- "3.10"
46+
- "3.11"
47+
- "3.12"
48+
platform:
49+
- "ubuntu-latest"
50+
steps:
51+
- name: "Harden Runner"
52+
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
53+
with:
54+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
55+
56+
- name: "Checkout"
57+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
58+
with:
59+
fetch-depth: 0
60+
61+
- name: "Setup Python ${{ matrix.python }}"
62+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
63+
with:
64+
python-version: ${{ matrix.python }}
65+
66+
- name: "Install tox"
67+
run: |
68+
python -m pip install --upgrade pip
69+
python -m pip install tox tox-gh
70+
71+
- name: "Unit tests"
72+
run: |
73+
tox

0 commit comments

Comments
 (0)