Skip to content

Commit

Permalink
Merge pull request #4071 from KnVerey/update-yaml-script
Browse files Browse the repository at this point in the history
Update fork updater script
  • Loading branch information
k8s-ci-robot committed Jul 15, 2021
2 parents 34981b6 + f082ac0 commit 339e33d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions kyaml/internal/forked/README.md
Expand Up @@ -6,6 +6,6 @@ This code is used by the starlark runtime. We copied it in to reduce the depende

## go-yaml/yaml

This code is used extensively by kyaml. It is a copy of upstream at a particular revision that kubectl is using, with [a change we need](https://github.com/go-yaml/yaml/pull/753) cherry-picked on top. For background information on this problem, see https://github.com/kubernetes-sigs/kustomize/issues/3946.
This code is used extensively by kyaml. It is a copy of upstream at a particular revision that kubectl is using, with fixes we need cherry-picked on top ([#753](https://github.com/go-yaml/yaml/pull/753), [#766](https://github.com/go-yaml/yaml/pull/766)). For background information on this problem, see https://github.com/kubernetes-sigs/kustomize/issues/3946.

This copy was created using the [git subtree technique](https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec) and can be recreated on top of a new version of go-yaml v3 using the [update-go-yaml.sh](update-go-yaml.sh) script. Please note that there is nothing special about the fork directory, so copy-paste with manual edits will work just fine if you prefer.
This copy was created using the [git subtree technique](https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec) and can be recreated on top of a new version of go-yaml v3 using the [update-go-yaml.sh](update-go-yaml.sh) script. To add an additional go-yaml PR to be cherry-picked, simply update the script's `GO_YAML_PRS` variable. Please note that there is nothing special about the fork directory, so copy-paste with manual edits will work just fine if you prefer.
3 changes: 3 additions & 0 deletions kyaml/internal/forked/github.com/go-yaml/yaml/decode_test.go
Expand Up @@ -46,6 +46,9 @@ var unmarshalTests = []struct {
map[string]string{"v": "hi"},
}, {
"v: hi", map[string]interface{}{"v": "hi"},
}, {
"v: 'hi\nthis is a\nmultiline string\n'",
map[string]interface {}{"v":"hi\nthis is a\nmultiline string\n"},
}, {
"v: true",
map[string]string{"v": "true"},
Expand Down
29 changes: 15 additions & 14 deletions kyaml/internal/forked/update-go-yaml.sh
Expand Up @@ -18,13 +18,12 @@ blue=$(tput setaf 4)
normal=$(tput sgr0)

# This should be the version of go-yaml v3 used by kubectl
# In the original fork, this is 496545a6307b2a7d7a710fd516e5e16e8ab62dbc
export GOYAML_SHA=$1
export GOYAML_REF="goyaml-$GOYAML_SHA"
# In the original fork, this is 496545a6307b2a7d7a710fd516e5e16e8ab62dbc
export GOYAML_SHA=$1
export GOYAML_REF="goyaml-$GOYAML_SHA"

# The PRs we need to cherry-pick onto the above commit
declare -r GO_YAML_PR=753
declare -r KUSTOMIZE_PR=4004
declare -r GO_YAML_PRS=(753 766)

REPO_ROOT=$(git rev-parse --show-toplevel)
declare -r REPO_ROOT
Expand Down Expand Up @@ -77,8 +76,11 @@ function cherry-pick(){
subtree_commit_flag=""

explain "Removing the fork's tree from git, if it exists. We'll write over this commit in a moment, but \`read-tree\` requires a clean directory."
if [[ $(find kyaml/internal/forked/github.com/go-yaml/yaml -type f -delete) ]]; then
git commit --all -m "Temporarily remove go-yaml fork"
find kyaml/internal/forked/github.com/go-yaml/yaml -type f -delete

if [[ $(git diff --exit-code kyaml/internal/forked/github.com/go-yaml/yaml) ]]; then
git add kyaml/internal/forked/github.com/go-yaml/yaml
git commit -m "Temporarily remove go-yaml fork"
subtree_commit_flag="--amend"
fi

Expand All @@ -87,21 +89,20 @@ git fetch --depth=1 https://github.com/go-yaml/yaml.git "$GOYAML_SHA:$GOYAML_REF

explain "Inserting the content we just pulled as a subtree of this repository and squash the changes into the last commit."
git read-tree --prefix=kyaml/internal/forked/github.com/go-yaml/yaml/ -u "$GOYAML_REF"
git commit $subtree_commit_flag --all -m "Internal copy of go-yaml at $GOYAML_SHA"
git add kyaml/internal/forked/github.com/go-yaml/yaml
git commit $subtree_commit_flag -m "Internal copy of go-yaml at $GOYAML_SHA"

explain "Subtree creation successful."

explain "Cherry-picking the commits from our go-yaml/yaml PR"
cherry-pick https://github.com/go-yaml/yaml $GO_YAML_PR
explain "Cherry-picking the commits from our go-yaml/yaml PRs"
for pr in "${GO_YAML_PRS[@]}" ; do
cherry-pick https://github.com/go-yaml/yaml "$pr"
done

explain "Converting module to be internal."
find kyaml/internal/forked/github.com/go-yaml/yaml -name "*.go" -type f | xargs sed -i '' s+"gopkg.in/yaml.v3"+"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"+g
rm kyaml/internal/forked/github.com/go-yaml/yaml/go.mod
git commit --all -m "Internalize forked code"

# This is only necessary in the initial forking of the code
# explain "Cherry-picking the commits from our test fixes in Kustomize PR"
# cherry-pick https://github.com/kubernetes-sigs/kustomize $KUSTOMIZE_PR

explain "SUCCEEDED."
exit 0

0 comments on commit 339e33d

Please sign in to comment.