Debian Codegraph @

hack/update-json-library.sh

raw
1 #!/usr/bin/env bash
2 # This script can be called via ./hack/update-json-library.sh` to update the
3 # go-json-experiment fork in the repo.
4
5 # The HASH parameter may be set as part of the invocation to this script or
6 # the default hash from ./hack/JSON-EXPERIMENTAL-HASH will be used.
7 HASH="${HASH:-$(cat ./hack/JSON-EXPERIMENTAL-HASH)}"
8 GO_JSON_EXPERIMENT_DIR="pkg/internal/third_party/go-json-experiment/json"
9 rm -rf $GO_JSON_EXPERIMENT_DIR
10 git clone https://github.com/go-json-experiment/json $GO_JSON_EXPERIMENT_DIR
11 cd $GO_JSON_EXPERIMENT_DIR
12 git reset --hard $HASH
13 # If HASH was set to a keyword like HEAD, get the actual commit ID
14 HASH=$(git rev-parse HEAD)
15 cat <<EOF > ../README.md
16 Forked from: https://github.com/go-json-experiment/json
17 Commit Hash: $HASH
18
19 This internal fork exists to prevent dependency issues with go-json-experiment
20 until its API stabilizes.
21 EOF
22
23 # Remove git directories
24 rm -rf ".git"
25 rm -rf ".github"
26 # Remove images
27 rm *.png
28 # Remove go.{mod|sum}
29 # NOTE: go-json-experiment has no go mod dependencies at the moment.
30 # If this changes, the code will need to be updated.
31 rm go.mod go.sum
32 # Remove large testdata files and the tests that depend on them.
33 rm bench_test.go
34 rm intern_test.go
35 rm internal/jsontest/testdata.go
36 rm jsontext/fuzz_test.go
37 rm v1/bench_test.go
38 rm -rf internal/jsontest/testdata
39 # Only used to decompress the testdata fixtures removed above.
40 rm -rf internal/zstd
41 # Update references to point to the fork
42 find . -type f -name "*.go" -print0 | xargs -0 perl -pi -e "s#github.com/go-json-experiment/json#k8s.io/kube-openapi/${GO_JSON_EXPERIMENT_DIR}#g"
43
44 # eliminate links to stdlib
45 rm -fr v1
46 rm -fr alias.go jsontext/alias.go
47 # remove conditional build tags
48 find . -type f -name "*.go" -print0 | xargs -0 perl -pi -e 's#\Q//go:build !goexperiment.jsonv2 || !go1.25\E##g'
49 find . -type f -name "*.go" -print0 | xargs -0 gofmt -w -s