Skip to content

Commit 39a90d8

Browse files
committed
fix(ci): pin hash for cyclonedx-cli
This also fixes version handling in SBOM.
1 parent 9b8e470 commit 39a90d8

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

.github/renovate.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,31 @@
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
33
"extends": [
44
"github>WeblateOrg/meta:renovate"
5-
]
5+
],
6+
"customManagers": [
7+
{
8+
"customType": "regex",
9+
"description": "Update CycloneDX CLI binary version and GitHub release asset digest",
10+
"managerFilePatterns": [
11+
"/^\\.github\\/workflows\\/setup\\.yml$/"
12+
],
13+
"matchStrings": [
14+
"(?<indentation>[ \\t]*)# renovate-cyclonedx-cli\\r?\\n[ \\t]*CYCLONEDX_CLI_VERSION: (?<currentValue>\\S+)\\r?\\n[ \\t]*CYCLONEDX_CLI_DIGEST: (?<currentDigest>sha256:[a-f0-9]{64})"
15+
],
16+
"depNameTemplate": "CycloneDX/cyclonedx-cli",
17+
"packageNameTemplate": "CycloneDX/cyclonedx-cli",
18+
"datasourceTemplate": "custom.github-release-asset-digest",
19+
"versioningTemplate": "loose",
20+
"autoReplaceStringTemplate": "{{{indentation}}}# renovate-cyclonedx-cli\n{{{indentation}}}CYCLONEDX_CLI_VERSION: {{{newValue}}}\n{{{indentation}}}CYCLONEDX_CLI_DIGEST: {{{newDigest}}}"
21+
}
22+
],
23+
"customDatasources": {
24+
"github-release-asset-digest": {
25+
"defaultRegistryUrlTemplate": "https://api.github.com/repos/{{{packageName}}}/releases?per_page=100",
26+
"format": "json",
27+
"transformTemplates": [
28+
"{\"releases\": $map($[draft = false and prerelease = false and assets[name = \"cyclonedx-linux-x64\"]], function($release) { { \"version\": $release.tag_name, \"digest\": $release.assets[name = \"cyclonedx-linux-x64\"][0].digest, \"releaseTimestamp\": $release.published_at, \"sourceUrl\": $release.html_url } }), \"sourceUrl\": \"https://github.com/CycloneDX/cyclonedx-cli\"}"
29+
]
30+
}
31+
}
632
}

.github/workflows/setup.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ jobs:
107107
- name: Generate SBOM
108108
id: generate-sbom
109109
env:
110-
# renovate: datasource=github-releases depName=CycloneDX/cyclonedx-cli versioning=loose
110+
# renovate-cyclonedx-cli
111111
CYCLONEDX_CLI_VERSION: v0.31.0
112+
CYCLONEDX_CLI_DIGEST: sha256:72c465982796cb930dd7bfabe68d869aea053c9b7a717dff9ceee56b5624eea4
112113
run: |
113-
version=$(sed -n '/^VERSION =/ s/.*"\(.*\)"/\1/p' weblate/utils/version.py)
114-
version=${version%-dev}
115-
version=${version%-rc}
114+
version=$(./scripts/show-version.py)
116115
sbom="build/sbom/weblate-$version-sbom.cdx.json"
117116
mkdir -p build/sbom
118117
uv export --preview-features sbom-export --format cyclonedx1.5 --all-extras --no-dev > build/sbom/python.json
@@ -122,9 +121,11 @@ jobs:
122121
npm sbom --omit dev --sbom-format cyclonedx --sbom-type application > ../build/sbom/javascript.json
123122
cd ..
124123
./scripts/reproducible-sbom.py build/sbom/javascript.json
125-
curl -L "https://github.com/CycloneDX/cyclonedx-cli/releases/download/$CYCLONEDX_CLI_VERSION/cyclonedx-linux-x64" > /tmp/cyclonedx-linux-x64
126-
chmod +x /tmp/cyclonedx-linux-x64
127-
/tmp/cyclonedx-linux-x64 merge --input-files build/sbom/*.json --output-file "$sbom"
124+
cyclonedx_cli=/tmp/cyclonedx-linux-x64
125+
curl -fsSL "https://github.com/CycloneDX/cyclonedx-cli/releases/download/$CYCLONEDX_CLI_VERSION/cyclonedx-linux-x64" > "$cyclonedx_cli"
126+
echo "${CYCLONEDX_CLI_DIGEST#sha256:} $cyclonedx_cli" | sha256sum --check --strict
127+
chmod +x "$cyclonedx_cli"
128+
"$cyclonedx_cli" merge --input-files build/sbom/*.json --output-file "$sbom"
128129
./scripts/reproducible-sbom.py "$sbom"
129130
echo "path=$sbom" >> "$GITHUB_OUTPUT"
130131
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

scripts/show-version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright © Michal Čihař <michal@weblate.org>
4+
#
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
7+
import ast
8+
from pathlib import Path
9+
10+
from packaging.version import Version
11+
12+
module = ast.parse(Path("weblate/utils/version.py").read_text(encoding="utf-8"))
13+
for node in module.body:
14+
if not isinstance(node, ast.Assign):
15+
continue
16+
if any(
17+
isinstance(target, ast.Name) and target.id == "VERSION"
18+
for target in node.targets
19+
):
20+
print(Version(ast.literal_eval(node.value)).base_version)
21+
break
22+
else:
23+
msg = "VERSION not found in weblate/utils/version.py"
24+
raise SystemExit(msg)

0 commit comments

Comments
 (0)