Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite - more convert script changes #11799

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions mmv1/provider/file_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class FileTemplate
# Once the file's contents are written, set the proper [chmod] mode and
# format the file with a language-appropriate formatter.
def generate(pwd, template, path, provider)
# If we've modified a file since starting an MM run, it's a reasonable
# assumption that it was this run that modified it.
if File.exist?(path) && File.mtime(path) > @env[:start_time]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gets raised when trying to convert a product.yaml file with product.yaml.temp
I think we are close enough to the migration to turn this off

raise "#{path} was already modified during this run.. check to see if " \
'there is both a .go and .go.erb version of this file'
end

# You're looking at some magic here!
# This is how variables are made available in templates; we iterate
# through each key:value pair in this object, and we set them
Expand Down
19 changes: 16 additions & 3 deletions mmv1/template-converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ func convertTemplate(folder, tempFileTargets string) int {
continue
}
if len(tempSlice) > 1 {
// log.Printf("%s", filePath)
if !slices.Contains(tempSlice, filePath) {
found := false
for _, targetFile := range tempSlice {
parts := strings.Split(targetFile, "mmv1/")
if filePath == parts[len(parts)-1] {
found = true
}
}
if !found {
continue
}
log.Printf("continuing with template temp target %s", filePath)
Expand Down Expand Up @@ -149,7 +155,14 @@ func convertHandwrittenFiles(folder, handwrittenTempFiles string) int {
continue
}
if len(tempSlice) > 1 {
if !slices.Contains(tempSlice, filePath) {
found := false
for _, targetFile := range tempSlice {
parts := strings.Split(targetFile, "mmv1/")
if filePath == parts[len(parts)-1] {
found = true
}
}
if !found {
continue
}
log.Printf("continuing with handwritten temp target %s", filePath)
Expand Down
33 changes: 29 additions & 4 deletions scripts/cherry-pick.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
#!/usr/bin/env bash

# Example command
# sh scripts/cherry-pick <hash of a post-switchover commit>

set -e
safecommit=$1

backupbranch="$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)"
if [[ $backupbranch != *"-backup"* ]]; then
echo "\"-backup\" not detected in the branch name \"${backupbranch}\""
echo "Do you want to still continue with the default branch name \"go-rewrite-convert\"?"
select yn in "Yes" "No"; do
case $yn in
Yes ) backupbranch="go-rewrite-convert"; break;;
No ) exit;;
esac
done
fi
newbranch=${backupbranch%"-backup"}
echo "will use branch \"${newbranch}\""

# prepare temp file commit
git add .
git commit -m "temp file commit"
currentcommit="$(git rev-parse HEAD)"
echo "committed all changes to ${currentcommit}"

# checkout a new branch from a given post-switchover commit
git checkout -b go-rewrite-convert $safecommit

echo $currentcommit
echo "checking out \"${newbranch}\" at post-switchover commit ${safecommit}"
git checkout -b $newbranch $safecommit

# cherry-pick the previous temp file commit to the new post-switchover branch
echo "cherry-picking ${currentcommit}"
git cherry-pick $currentcommit --no-commit

# overwrite the converted files with the temporary files to produce final diff
echo "cherry-picking ${currentcommit}"
files=`git diff --name-only --diff-filter=A --cached`
for file in $files; do
echo "moving ${file} to ${file%".temp"}"
mv $file ${file%".temp"}
done
done

# stage all changes
git add .
git status
29 changes: 23 additions & 6 deletions scripts/convert-go.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

# Example command (in a pre-switchover commit)
# sh scripts/convert-go.sh <provider output directory> <comma separated list of files that have changed in the PR>

set -e
outputPath=$1
files=$2
Expand Down Expand Up @@ -33,13 +37,26 @@ for i in "${file[@]}"; do
fi
done

# run yaml conversion with given .yaml files
bundle exec compiler.rb -e terraform -o $1 -v beta -a --go-yaml-files $yamlstring
go run . --yaml-temp
pushd mmv1

if [[ $yamlstring != "" ]]; then
# run yaml conversion with given .yaml files
bundle exec compiler.rb -e terraform -o $1 -v beta -a --go-yaml-files $yamlstring
go run . --yaml-temp
for i in `find . -name "*.temp" -type f`; do
echo "removing go/ paths in ${i}"
perl -pi -e 's/go\///g' $i
done

fi


# convert .erb files with given .erb files
go run . --template-temp $erbstring
go run . --handwritten-temp $erbstring
if [[ $erbstring != "" ]]; then
# convert .erb files with given .erb files
go run . --template-temp $erbstring
go run . --handwritten-temp $erbstring
fi
popd

# add temporary file for all other files that do not need conversion
for i in "${otherlist[@]}"
Expand Down
Loading