Skip to content

Commit 026d8c3

Browse files
authored
feat: attest generated bcr files (#237)
1 parent fd61c9f commit 026d8c3

File tree

14 files changed

+938
-159
lines changed

14 files changed

+938
-159
lines changed

.github/workflows/action-e2e.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,36 @@ jobs:
6363
local-registry: bazel-central-registry
6464
- name: Test repository substitution
6565
run: this/e2e/action/test-github-repository-default-substitution.sh
66+
test-attestations:
67+
# Test that attestations are created when `attest` is set to true
68+
runs-on: ubuntu-latest
69+
permissions:
70+
id-token: write
71+
attestations: write
72+
steps:
73+
- uses: actions/checkout@v2
74+
with:
75+
path: this
76+
- name: Setup test fixture
77+
run: this/e2e/action/setup-test-fixture.sh versioned versioned-1.0.0
78+
- name: Create registry
79+
run: |
80+
mkdir -p bazel-central-registry/modules
81+
cd bazel-central-registry
82+
git init
83+
- name: Create entry
84+
uses: ./this
85+
with:
86+
attest: true
87+
attestations-dest: attestations
88+
tag: v1.0.0
89+
module-version: 1.0.0
90+
github-repository: foobar/versioned
91+
templates-dir: this/e2e/fixtures/versioned/.bcr
92+
local-registry: bazel-central-registry
93+
- name: Test attestations exist
94+
run: |
95+
set -o errexit -o nounset -o pipefail -o xtrace
96+
97+
[ -f attestations/MODULE.bazel.intoto.jsonl ]
98+
[ -f attestations/source.json.intoto.jsonl ]

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ git_override(
2424

2525
bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
2626
bazel_lib.bats()
27+
bazel_lib.jq()
28+
use_repo(bazel_lib, "jq_toolchains")
2729

2830
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
2931
multitool.hub(lockfile = "//tools:tools.lock.json")

action.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
name: 'Publish to BCR'
22
description: 'Create a new module version entry in a Bazel registry'
33
inputs:
4+
attest:
5+
description: 'Whether to generate attestations for files created by Publish to BCR.'
6+
required: false
7+
default: false
8+
attestations-dest:
9+
description: 'Directory to output attestations to. Attestations are not included in the entry.'
10+
required: false
11+
default: ''
12+
gh-token:
13+
description: 'Token for persisting attestations to the repo. This must be a token with id-token and attestation write permissions.'
14+
required: false
15+
default: ${{ github.token }}
416
github-repository:
517
description: 'GitHub repository for the module being published. Used to substititue the OWNER and REPO vars into the source template. Defaults to the repository this action runs in.'
618
required: false

dist/action/index.js

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

dist/cli/index.js

Lines changed: 23 additions & 23 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ bats_test(
1111
"//e2e/fixtures:versioned",
1212
"//e2e/fixtures:zip",
1313
"//src/application/cli:bundle",
14+
"@jq_toolchains//:resolved_toolchain",
1415
"@nodejs_toolchains//:resolved_toolchain",
1516
],
1617
env = {
1718
"CLI_BIN": "$(rootpath //src/application/cli:bundle)",
19+
"JQ_BIN": "$(JQ_BIN)",
1820
"NODE_BIN": "$(rootpath @nodejs_toolchains//:resolved_toolchain)",
1921
},
22+
toolchains = [
23+
"@jq_toolchains//:resolved_toolchain",
24+
],
2025
)

e2e/cli/e2e.bats

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ bats_load_library "bats-support"
55
setup() {
66
export REGISTRY_PATH="${TEST_TMPDIR}/bazel-central-registry"
77
mkdir -p "${REGISTRY_PATH}/modules"
8+
9+
export jq="../${JQ_BIN#"external/"}"
810
}
911

1012
teardown() {
11-
rm -rf "${TEST_TMPDIR}/*"
13+
rm -rf "${TEST_TMPDIR}"/*
1214
}
1315

1416
swap_source_url() {
@@ -94,4 +96,22 @@ swap_source_url() {
9496
assert_failure
9597

9698
assert_output --partial 'Did you forget to pass --github-repository to substitute the OWNER and REPO variables?'
99+
}
100+
101+
@test 'outputs json blob with info about entry to stdout' {
102+
FIXTURE="e2e/fixtures/versioned"
103+
cp -R "${FIXTURE}" "${TEST_TMPDIR}/"
104+
FIXTURE="${TEST_TMPDIR}/$(basename "${FIXTURE}")"
105+
TEMPLATES_DIR="${FIXTURE}/.bcr"
106+
RELEASE_ARCHIVE="e2e/fixtures/versioned-versioned-1.0.0.tar"
107+
108+
swap_source_url "${TEMPLATES_DIR}/source.template.json" "file://$(realpath "${RELEASE_ARCHIVE}")"
109+
110+
STDOUT=$("${NODE_BIN}" "${CLI_BIN}" create-entry --local-registry "${REGISTRY_PATH}" --templates-dir "${TEMPLATES_DIR}" --module-version 1.0.0 --github-repository owner/versioned --tag v1.0.0)
111+
ENTRY_PATH="${REGISTRY_PATH}/modules/versioned/1.0.0"
112+
113+
ACTUAL=$("${jq}" <<< ${STDOUT} .)
114+
EXPECTED=$("${jq}" --null-input "{moduleName: \"versioned\", entryPath: \"${ENTRY_PATH}\"}")
115+
116+
assert_equal "${EXPECTED}" "${ACTUAL}"
97117
}

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"gcp-build": ""
1616
},
1717
"dependencies": {
18+
"@actions/attest": "^1.5.0",
1819
"@actions/core": "^1.11.1",
1920
"@actions/exec": "^1.1.1",
2021
"@google-cloud/functions-framework": "^3.1.2",
@@ -32,6 +33,7 @@
3233
"axios-retry": "^4.0.0",
3334
"chalk": "^4.1.2",
3435
"diff": "^5.1.0",
36+
"encoding": "0.1.13",
3537
"exponential-backoff": "3.1.1",
3638
"extract-zip": "^2.0.1",
3739
"gcp-metadata": "^6.0.0",
@@ -84,6 +86,11 @@
8486
"pnpm": {
8587
"onlyBuiltDependencies": [],
8688
"packageExtensions": {
89+
"@actions/github": {
90+
"dependencies": {
91+
"undici": "*"
92+
}
93+
},
8794
"@google-cloud/secret-manager": {
8895
"dependencies": {
8996
"long": "5.2.3"
@@ -98,6 +105,11 @@
98105
"dependencies": {
99106
"debug": "*"
100107
}
108+
},
109+
"node-fetch": {
110+
"dependencies": {
111+
"encoding": "*"
112+
}
101113
}
102114
}
103115
}

0 commit comments

Comments
 (0)