Skip to content

Commit a4fa63b

Browse files
authored
feat: add an attestations.json substitutable template (#239)
1 parent 4f916ea commit a4fa63b

26 files changed

+1207
-108
lines changed

dist/cli/index.js

Lines changed: 78 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/cli/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bats_test(
88
],
99
data = [
1010
"//e2e/fixtures",
11+
"//e2e/fixtures:attestations",
1112
"//e2e/fixtures:versioned",
1213
"//e2e/fixtures:zip",
1314
"//src/application/cli:bundle",

e2e/cli/e2e.bats

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ swap_source_url() {
2121
mv "${TEST_TMPDIR}/tmp" "${SRC}"
2222
}
2323

24+
swap_attestation_url() {
25+
local SRC=$1
26+
local FIELD=$2
27+
local URL=$3
28+
29+
cat "${SRC}" | jq ".attestations[\"${FIELD}\"].url = \"${URL}\"" > "${TEST_TMPDIR}/tmp"
30+
mv "${TEST_TMPDIR}/tmp" "${SRC}"
31+
}
32+
33+
mock_attestation() {
34+
local NAME=$1
35+
36+
FILE="$(mktemp -p "${TEST_TMPDIR}" --directory)/${NAME}"
37+
jq --null-input "{foobar:\"${NAME}\"}" > "${FILE}"
38+
39+
echo -n "${FILE}"
40+
}
41+
2442
@test 'no_args_shows_help' {
2543
run "${NODE_BIN}" "${CLI_BIN}"
2644

@@ -82,6 +100,31 @@ swap_source_url() {
82100
assert_file_exists "${ENTRY_PATH}/1.0.0/presubmit.yml"
83101
}
84102

103+
@test 'create entry with attestations' {
104+
FIXTURE="e2e/fixtures/attestations"
105+
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
106+
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
107+
TEMPLATES_DIR="${FIXTURE}/.bcr"
108+
RELEASE_ARCHIVE="e2e/fixtures/attestations-attestations-1.0.0.tar"
109+
110+
SOURCE_ATTESTATION=$(mock_attestation "source.json.intoto.jsonl")
111+
MODULE_ATTESTATION=$(mock_attestation "MODULE.bazel.intoto.jsonl")
112+
ARCHIVE_ATTESTATION=$(mock_attestation "attestations-v1.0.0.tar.gz.intoto.jsonl")
113+
114+
swap_source_url "${TEMPLATES_DIR}/source.template.json" "file://$(realpath "${RELEASE_ARCHIVE}")"
115+
swap_attestation_url "${TEMPLATES_DIR}/attestations.template.json" "source.json" "file://$(realpath "${SOURCE_ATTESTATION}")"
116+
swap_attestation_url "${TEMPLATES_DIR}/attestations.template.json" "MODULE.bazel" "file://$(realpath "${MODULE_ATTESTATION}")"
117+
swap_attestation_url "${TEMPLATES_DIR}/attestations.template.json" "{REPO}-{TAG}.tar.gz.intoto.jsonl" "file://$(realpath "${ARCHIVE_ATTESTATION}")"
118+
119+
run "${NODE_BIN}" "${CLI_BIN}" create-entry --local-registry "${REGISTRY_PATH}" --templates-dir "${TEMPLATES_DIR}" --module-version 1.0.0 --github-repository owner/attestations --tag v1.0.0
120+
121+
assert_success
122+
123+
ENTRY_PATH="${REGISTRY_PATH}/modules/attestations"
124+
125+
assert_file_exists "${ENTRY_PATH}/1.0.0/attestations.json"
126+
}
127+
85128
@test 'missing OWNER/REPO vars' {
86129
FIXTURE="e2e/fixtures/versioned"
87130
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"

e2e/fixtures/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
22
load(":fixture.bzl", "fixture_archive")
33

4+
fixture_archive(
5+
name = "attestations",
6+
archive = "tar",
7+
prefix = "attestations-1.0.0",
8+
)
9+
410
fixture_archive(
511
name = "empty-prefix",
612
archive = "tar",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"types": ["https://slsa.dev/provenance/v1"],
3+
"attestations": {
4+
"source.json": {
5+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/source.json.intoto.jsonl",
6+
"integrity": ""
7+
},
8+
"MODULE.bazel": {
9+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/MODULE.bazel.intoto.jsonl",
10+
"integrity": ""
11+
},
12+
"{REPO}-{TAG}.tar.gz.intoto.jsonl": {
13+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz.intoto.jsonl",
14+
"integrity": ""
15+
}
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"homepage": "https://github.com/testorg/attestations",
3+
"maintainers": [
4+
{
5+
"name": "Foo McBar",
6+
"email": "[email protected]",
7+
"github": "foobar"
8+
}
9+
],
10+
"repository": ["github:testorg/attestations"],
11+
"versions": [],
12+
"yanked_versions": {}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bcr_test_module:
2+
module_path: "e2e/bzlmod"
3+
matrix:
4+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
5+
bazel: [6.x, 7.x]
6+
tasks:
7+
run_tests:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
test_targets:
12+
- "//..."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module(
2+
name = "attestations",
3+
version = "1.0.0",
4+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ruleset repo with `attestations.template.json`.

0 commit comments

Comments
 (0)