Skip to content

Commit

Permalink
Add some helper tooling for dev and docs
Browse files Browse the repository at this point in the history
Also, reformat with black and fix a few ruff findings.
  • Loading branch information
mprpic committed Aug 16, 2024
1 parent 107302c commit 35e9277
Show file tree
Hide file tree
Showing 12 changed files with 1,140 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material[imaging]
- run: pip install -r requirements/docs-requirements.txt
- run: mkdocs gh-deploy --force
31 changes: 0 additions & 31 deletions .github/workflows/schema.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
tox:
name: Run Tox
steps:
- uses: actions/checkout@v2
- name: Run all envs
uses: fedora-python/tox-github-action@main
with:
tox_env: ${{ matrix.tox_env }}
strategy:
matrix:
tox_env: [black, ruff, schema]
runs-on: ubuntu-latest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.cache
*.egg-info/
.tox
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.black]
line-length = 100

[tool.ruff]
line-length = 100

[tool.ruff.lint]
# https://beta.ruff.rs/docs/rules/
select = ["F", "E", "W", "I", "N"]
3 changes: 3 additions & 0 deletions requirements/dev-requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
black
check-jsonschema
ruff
472 changes: 472 additions & 0 deletions requirements/dev-requirements.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements/docs-requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mkdocs-material[imaging]
595 changes: 595 additions & 0 deletions requirements/docs-requirements.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sbom/examples/container_image/from_catalog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import itertools
import json
import secrets
import sys

Expand Down
21 changes: 12 additions & 9 deletions sbom/examples/rpm/from-koji.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import hashlib
import json
import koji
import os
import re
import subprocess
import sys
from tempfile import TemporaryDirectory

import koji

# Script requires these RPMs: brewkoji, rpmdevtools, rpm-build
# Run with: ./from-koji.py brew <NVR>

Expand Down Expand Up @@ -110,14 +111,14 @@ def run_syft(builddir):
relationships.extend(syft_rels)


def mock_openssl_midstream(sfn, sourceN, sname, sver):
def mock_openssl_midstream(sfn, source, sname, sver):
# Model a midstream repository for this.
ext = re.sub(r".*-hobbled\.", "", sfn)
url = f"https://openssl.org/source/openssl-{sver}.{ext}"
# Hard-code example value for 3.0.7
digest = "83049d042a260e696f62406ac5c08bf706fd84383f945cf21bd61e9ed95c396e"
upackage = {
"SPDXID": f"SPDXRef-{sourceN}-origin",
"SPDXID": f"SPDXRef-{source}-origin",
"name": sname,
"versionInfo": sver,
"downloadLocation": url,
Expand All @@ -132,17 +133,19 @@ def mock_openssl_midstream(sfn, sourceN, sname, sver):
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceType": "purl",
"referenceLocator": f"pkg:generic/{sname}@{sver}?download_url={url}&checksum=sha256:{digest}",
"referenceLocator": (
f"pkg:generic/{sname}@{sver}?download_url={url}&checksum=sha256:{digest}",
),
}
],
}

pkgs_by_arch.setdefault(arch, []).append(upackage)
relationships.append(
{
"spdxElementId": f"SPDXRef-{sourceN}",
"spdxElementId": f"SPDXRef-{source}",
"relationshipType": "GENERATED_FROM",
"relatedSpdxElement": f"SPDXRef-{sourceN}-origin",
"relatedSpdxElement": f"SPDXRef-{source}-origin",
}
)

Expand Down Expand Up @@ -213,7 +216,7 @@ def handle_srpm(filename, name):
if not m:
continue

(sourceN, url, _, sfn) = m.groups()
(source, url, _, sfn) = m.groups()

# Parse filename
tarball_match = tarball_re.match(sfn)
Expand All @@ -224,7 +227,7 @@ def handle_srpm(filename, name):

# Special case to fix up example for openssl
if sname == "openssl":
url = mock_openssl_midstream(sfn, sourceN, sname, sver)
url = mock_openssl_midstream(sfn, source, sname, sver)

# Calculate checksum
sha256 = hashlib.sha256()
Expand All @@ -238,7 +241,7 @@ def handle_srpm(filename, name):
if url is None or ":" not in url:
url = "NOASSERTION"

sref = f"SPDXRef-{sourceN}"
sref = f"SPDXRef-{source}"
digest = sha256.hexdigest()
spackage = {
"SPDXID": sref,
Expand Down
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tox]
envlist = black, ruff, schema

[testenv:black]
deps = -r requirements/dev-requirements.txt
commands = black --check .

[testenv:ruff]
deps = -r requirements/dev-requirements.txt
commands = ruff check .

[testenv:schema]
deps = -r requirements/dev-requirements.txt
allowlist_externals = bash
commands =
bash -c 'for example in {tox_root}/sbom/examples/*/*.json; do \
echo "$example"; \
check-jsonschema --schemafile sbom/spdx-2.3-schema.json "$example"; \
done'

0 comments on commit 35e9277

Please sign in to comment.