Debian Codegraph @

service-protos/sync-rekor-tiles.sh

raw
1 #!/usr/bin/env bash
2
3 # A simple utility to copy protos from the rekor-tiles repository into protobuf specs for distribution
4 set -o pipefail -o errexit -o nounset
5
6 command -v gh &>/dev/null || { echo "gh not found" 1>&2; exit 1; }
7
8 latest_tag=$(gh api graphql -f query='{repository(owner: "sigstore", name: "rekor-tiles"){refs(refPrefix: "refs/tags/", last: 1){nodes{name}}}}' --jq '.data.repository.refs.nodes[].name')
9
10 if [ -z "$latest_tag" ]; then
11 echo "latest tag not found"
12 exit 1
13 fi
14
15 # clean up last sync
16 rm ./rekor/v2/*.proto || echo "nothing to clean up"
17
18 # mkdir just in case
19 mkdir -p ./rekor/v2
20
21 # copy all protos over except rekor_service.proto
22 echo "syncing protos with ${latest_tag}"
23 git clone --filter=blob:none --no-checkout --depth=1 https://github.com/sigstore/rekor-tiles.git ./rekor-tiles
24 cd ./rekor-tiles
25 git sparse-checkout set --no-cone '/api/proto/rekor/v2/*.proto' '!**/rekor_service.proto'
26 git fetch origin tag "$latest_tag" --no-tags
27 git checkout "$latest_tag"
28 cd ../
29 cp -R ./rekor-tiles/api/proto/* .
30 rm -rf ./rekor-tiles
31
32 # replace the go package from the service definition to the protobuf out
33 echo "replacing go-package"
34 sed -i -e 's|^option go_package.*$|option go_package = "github.com/sigstore/protobuf-specs/gen/pb-go/rekor/v2";|' ./rekor/v2/*.proto