Skip to content

Commit 73e27f6

Browse files
authored
ci: build wheel only on origin, make sbom test more robust (#4126)
* fixes #4115 This moves the artifact/wheel build into a separate yml file and makes sure it's run only on the main repo (since it needs some info only available there) Because test_SBOM started failing while I was working on this, I also improved the test_SBOM failure message so it's not trying to show you the diff of the whole log and instead diffs the relevant lines, then made it a bit more robust to data changes by giving a number range for "number of products with CVEs" instead of a specific number. This should hopefully stop this test from failing a couple of times per year due to data changes, and make it more obvious what's going wrong if it does. --------- Signed-off-by: Terri Oda <[email protected]>
1 parent 9e92db8 commit 73e27f6

File tree

3 files changed

+71
-47
lines changed

3 files changed

+71
-47
lines changed

.github/workflows/build-wheel.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build pip wheel
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
workflow_dispatch:
7+
8+
build:
9+
name: Build wheel
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
attestations: write
14+
contents: read
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version:
19+
- "3.12"
20+
if: github.repository == 'intel/cve-bin-tool' && github.ref == 'refs/heads/main' # run on origin repo only
21+
steps:
22+
- name: Harden Runner
23+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
24+
with:
25+
egress-policy: audit
26+
27+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
28+
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
cache: 'pip'
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip setuptools wheel build
35+
- name: Build
36+
run: |
37+
python -m build .
38+
- name: Get built filenames
39+
id: filename
40+
run: |
41+
echo "tar=$(cd dist/ && echo *.tar.gz)" >> $GITHUB_OUTPUT
42+
echo "whl=$(cd dist/ && echo *.tar.gz)" >> $GITHUB_OUTPUT
43+
- name: Attest Build Provenance for tar
44+
uses: actions/attest-build-provenance@951c0c5f8e375ad4efad33405ab77f7ded2358e4 # v1.1.1
45+
with:
46+
subject-path: "dist/${{ steps.filename.outputs.tar }}"
47+
- name: Attest Build Provenance for whl
48+
uses: actions/attest-build-provenance@951c0c5f8e375ad4efad33405ab77f7ded2358e4 # v1.1.1
49+
with:
50+
subject-path: "dist/${{ steps.filename.outputs.whl }}"
51+
# TODO Upload to pypi on release creation

.github/workflows/testing.yml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -588,46 +588,3 @@ jobs:
588588
name: codecov-umbrella
589589
fail_ci_if_error: false
590590

591-
build:
592-
name: Build wheel
593-
runs-on: ubuntu-latest
594-
permissions:
595-
id-token: write
596-
attestations: write
597-
contents: read
598-
strategy:
599-
fail-fast: false
600-
matrix:
601-
python-version:
602-
- "3.12"
603-
steps:
604-
- name: Harden Runner
605-
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
606-
with:
607-
egress-policy: audit
608-
609-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
610-
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
611-
with:
612-
python-version: ${{ matrix.python-version }}
613-
cache: 'pip'
614-
- name: Install dependencies
615-
run: |
616-
python -m pip install --upgrade pip setuptools wheel build
617-
- name: Build
618-
run: |
619-
python -m build .
620-
- name: Get built filenames
621-
id: filename
622-
run: |
623-
echo "tar=$(cd dist/ && echo *.tar.gz)" >> $GITHUB_OUTPUT
624-
echo "whl=$(cd dist/ && echo *.tar.gz)" >> $GITHUB_OUTPUT
625-
- name: Attest Build Provenance for tar
626-
uses: actions/attest-build-provenance@951c0c5f8e375ad4efad33405ab77f7ded2358e4 # v1.1.1
627-
with:
628-
subject-path: "dist/${{ steps.filename.outputs.tar }}"
629-
- name: Attest Build Provenance for whl
630-
uses: actions/attest-build-provenance@951c0c5f8e375ad4efad33405ab77f7ded2358e4 # v1.1.1
631-
with:
632-
subject-path: "dist/${{ steps.filename.outputs.whl }}"
633-
# TODO Upload to pypi on release creation

test/test_cli.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import logging
88
import os
9+
import re
910
import shutil
1011
import sys
1112
import tempfile
@@ -630,11 +631,26 @@ def test_SBOM(self, caplog):
630631
]
631632
)
632633

634+
# find the "known CVEs detected" line from caplog
635+
known_cves_message = None
636+
# tuple is (tool_name, log_level, log_message) but we only care about the last
637+
for _, _, log_message in caplog.record_tuples:
638+
if re.search(r"with known CVEs detected", log_message):
639+
known_cves_message = log_message
640+
633641
assert (
634-
"cve_bin_tool",
635-
logging.INFO,
636-
"There are 3 products with known CVEs detected",
637-
) in caplog.record_tuples
642+
known_cves_message is not None
643+
), "Expected 3 products with cves, none found"
644+
645+
# since sometimes this test breaks due to data changes, let's just say we want at least 2
646+
# products with cves (though there should be 3 at time of writing)
647+
m = re.match(
648+
r"There are (?P<product_number>\d*) products with known CVEs detected",
649+
known_cves_message,
650+
)
651+
assert (
652+
int(m.group("product_number")) >= 2
653+
), "Not enough products with cves found in output"
638654

639655
def test_sbom_detection(self, caplog):
640656
SBOM_PATH = Path(__file__).parent.resolve() / "sbom"

0 commit comments

Comments
 (0)