Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 11 additions & 49 deletions .github/workflows/sbom-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
echo "product_release=[${RELEASE_ARRAY}]" >> $GITHUB_OUTPUT
fi

# Build PURLs for TEA dedup and component PURL
# Build component PURLs
SOURCE_TYPE=$(yq -r '.source.type // ""' "$CONFIG")
IMAGE=$(yq -r '.source.image // ""' "$CONFIG")
REGISTRY=$(yq -r '.source.registry // ""' "$CONFIG")
Expand Down Expand Up @@ -219,67 +219,29 @@ jobs:
ENRICH: true
UPLOAD: false

# Phase 2: Check if this version is already published via TEA PURL lookup
- name: Install uv
if: steps.config.outputs.component_id != '' && !inputs.dry_run
uses: astral-sh/setup-uv@v4

- name: Check TEA for existing version
id: tea-check
# Phase 2: Check if this component already has this version on sbomify.
# Checked per component, not via TEA: a TEA PURL lookup resolves to the
# product release, which components sharing a repo (keycloak/keycloak-js)
# or a bundle product share, so the second one would never be uploaded.
- name: Check sbomify for existing version
id: upload-decision
if: steps.config.outputs.component_id != '' && !inputs.dry_run
run: |
purl="${{ steps.config.outputs.purl }}"
if [[ -z "$purl" ]]; then
echo "No PURL available, will upload"
echo "should_upload=true" >> "$GITHUB_OUTPUT"
exit 0
fi

tei="urn:tei:purl:library.sbomify.com:${purl}"
echo "TEI: $tei"

result=$(uvx --from 'libtea[cli]' tea-cli inspect "$tei" --json 2>/dev/null || true)
if [[ -z "$result" || "$result" == "{}" || "$result" == "null" ]]; then
echo "Version not found on TEA, will upload"
echo "should_upload=true" >> "$GITHUB_OUTPUT"
else
echo "Version already published on TEA, skipping upload"
echo "should_upload=false" >> "$GITHUB_OUTPUT"
fi

- name: Check sbomify for existing digest
id: sbomify-check
if: >-
steps.config.outputs.component_id != '' && !inputs.dry_run
&& (steps.config.outputs.source_type == 'docker'
|| steps.config.outputs.source_type == 'chainguard')
run: |
source scripts/lib/common.sh
source scripts/lib/sbomify-api.sh
rc=0
sbomify_digest_exists \
sbomify_version_exists \
"${{ steps.config.outputs.component_id }}" \
"${{ steps.digest.outputs.image_digest }}" || rc=$?
"${{ steps.digest.outputs.image_digest || steps.config.outputs.version }}" || rc=$?
case "$rc" in
0) echo "Digest already exists, skipping upload"
0) echo "Version already exists, skipping upload"
echo "should_upload=false" >> "$GITHUB_OUTPUT" ;;
1) echo "New digest, will upload"
1) echo "New version, will upload"
echo "should_upload=true" >> "$GITHUB_OUTPUT" ;;
*) echo "::error::Could not query sbomify (OIDC binding or API failure)"
exit 1 ;;
esac

- name: Resolve upload decision
id: upload-decision
if: steps.config.outputs.component_id != '' && !inputs.dry_run
run: |
src="${{ steps.config.outputs.source_type }}"
if [[ "$src" == "docker" || "$src" == "chainguard" ]]; then
echo "should_upload=${{ steps.sbomify-check.outputs.should_upload || 'true' }}" >> "$GITHUB_OUTPUT"
else
echo "should_upload=${{ steps.tea-check.outputs.should_upload || 'true' }}" >> "$GITHUB_OUTPUT"
fi

# Phase 3: Upload only if SBOM is new
- name: Upload SBOM (from existing SBOM)
if: >-
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tea-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# Runs hourly to detect when upstream images change without a version bump.
# Triggers the SBOM builder for all docker/chainguard apps. The builder
# itself handles deduplication via TEA hash lookup — if the augmented SBOM
# is already published, the upload is skipped.
# itself skips the upload when the component already has an SBOM for the
# current image digest.

name: TEA Sync

Expand Down
13 changes: 7 additions & 6 deletions scripts/lib/sbomify-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ sbomify_token() {
echo "$token"
}

# Check if a component already has an SBOM with this digest as version
# Usage: sbomify_digest_exists <component_id> <digest>
# Check if a component already has an SBOM with this version (the image
# digest for docker/chainguard, the config version otherwise).
# Usage: sbomify_version_exists <component_id> <version>
# Returns: 0 if exists, 1 if not, 2 if sbomify could not be queried
# (auth or network failure must not be mistaken for "new digest").
sbomify_digest_exists() {
local component_id="$1" digest="$2"
# (auth or network failure must not be mistaken for "new version").
sbomify_version_exists() {
local component_id="$1" version="$2"

local token sboms
token=$(sbomify_token "$component_id") || return 2
Expand All @@ -74,7 +75,7 @@ sbomify_digest_exists() {
log_error "Could not list SBOMs for component ${component_id}"
return 2
}
jq -e --arg d "$digest" 'any(.items[]?; .sbom.version == $d)' <<< "$sboms" > /dev/null 2>&1
jq -e --arg v "$version" 'any(.items[]?; .sbom.version == $v)' <<< "$sboms" > /dev/null 2>&1
}

# Remove old SBOMs for a component (keep only current digest)
Expand Down
39 changes: 12 additions & 27 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -278,33 +278,18 @@ process_app() {
# -------------------------------------------------------------------------
local should_upload=true

# Checked per component, not via TEA: a TEA PURL lookup resolves to the
# product release, which components sharing a repo (keycloak/keycloak-js)
# or a bundle product share, so the second one would never be uploaded.
if ! is_dry_run; then
if [[ "$source_type" == "docker" || "$source_type" == "chainguard" ]]; then
# Check sbomify for existing digest
local rc=0
sbomify_digest_exists "$component_id" "$image_digest" || rc=$?
case "$rc" in
0) log_info "Digest already exists on sbomify, skipping upload"
should_upload=false ;;
1) log_info "New digest, will upload" ;;
*) die "Could not query sbomify for $app (OIDC binding or API failure)" ;;
esac
else
# TEA check for github_release/lockfile
local purl tei result
purl=$(build_purl "$app")
if [[ -n "$purl" ]]; then
tei="urn:tei:purl:library.sbomify.com:${purl}"
log_debug "TEI: $tei"
result=$(uvx --from 'libtea[cli]' tea-cli inspect "$tei" --json 2>/dev/null || true)
if [[ -n "$result" && "$result" != "{}" && "$result" != "null" ]]; then
log_info "Version already published on TEA, skipping upload"
should_upload=false
else
log_info "Version not found on TEA, will upload"
fi
fi
fi
local rc=0
sbomify_version_exists "$component_id" "$component_version" || rc=$?
case "$rc" in
0) log_info "Version ${component_version} already exists on sbomify, skipping upload"
should_upload=false ;;
1) log_info "New version ${component_version}, will upload" ;;
*) die "Could not query sbomify for $app (OIDC binding or API failure)" ;;
esac
fi

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -375,7 +360,7 @@ check_tools() {
require_cmd "yq" "Install with: brew install yq"
require_cmd "jq" "Install with: brew install jq"

# Check uvx (needed for sbomify-action and tea-cli)
# Check uvx (needed for sbomify-action)
if ! command -v uvx &>/dev/null; then
die "Required command 'uvx' not found. Install with: pip install uv"
fi
Expand Down
Loading