This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #833 from laverya/template-noproxy-github-assets
render templates in noproxy github assets
- Loading branch information
Showing
15 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
integration/init/github-template-funcs/expected/.ship/state.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"v1": { | ||
"config": { | ||
"option": "abc123" | ||
}, | ||
"releaseName": "ship", | ||
"upstream": "https://github.com/replicatedhq/test-charts/tree/fd6c6c83ff38d272311b0ed00d6e579ba8b3579e/template-functions-noproxy", | ||
"contentSHA": "a28253e6e1fa4a1768c62f11be8fbc97eec2abe1d8ed77c19faaee4cd0a386d7" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...b-template-funcs/expected/installer/github-noslash/template-functions/config.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#This file tests a part of the Config suite of template functions in Ship | ||
|
||
Config option: abc123 |
4 changes: 4 additions & 0 deletions
4
...late-funcs/expected/installer/github-noslash/template-functions/installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Integration suite of template functions in Ship | ||
|
||
Release semver: | ||
|
4 changes: 4 additions & 0 deletions
4
...b-template-funcs/expected/installer/github-noslash/template-functions/static.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Static suite of template functions in Ship | ||
|
||
TwoPlusTwo: 4 | ||
UPPERCASE: UPPERCASE |
3 changes: 3 additions & 0 deletions
3
...hub-template-funcs/expected/installer/github-slash/template-functions/config.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#This file tests a part of the Config suite of template functions in Ship | ||
|
||
Config option: abc123 |
4 changes: 4 additions & 0 deletions
4
...mplate-funcs/expected/installer/github-slash/template-functions/installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Integration suite of template functions in Ship | ||
|
||
Release semver: | ||
|
4 changes: 4 additions & 0 deletions
4
...hub-template-funcs/expected/installer/github-slash/template-functions/static.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Static suite of template functions in Ship | ||
|
||
TwoPlusTwo: 4 | ||
UPPERCASE: UPPERCASE |
3 changes: 3 additions & 0 deletions
3
...gration/init/github-template-funcs/expected/installer/github-stripped/config.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#This file tests a part of the Config suite of template functions in Ship | ||
|
||
Config option: abc123 |
4 changes: 4 additions & 0 deletions
4
...n/init/github-template-funcs/expected/installer/github-stripped/installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Integration suite of template functions in Ship | ||
|
||
Release semver: | ||
|
4 changes: 4 additions & 0 deletions
4
...gration/init/github-template-funcs/expected/installer/github-stripped/static.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#This file tests a part of the Static suite of template functions in Ship | ||
|
||
TwoPlusTwo: 4 | ||
UPPERCASE: UPPERCASE |
3 changes: 3 additions & 0 deletions
3
integration/init/github-template-funcs/expected/installer/scripts/install.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
echo "installing nothing" | ||
echo "semver: " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
upstream: "https://github.com/replicatedhq/test-charts/tree/fd6c6c83ff38d272311b0ed00d6e579ba8b3579e/template-functions-noproxy" | ||
args: ["--prefer-git"] | ||
skip_cleanup: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package templates | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
func BuildDir(buildPath string, fs *afero.Afero, builder *Builder) error { | ||
isDir, err := fs.IsDir(buildPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "check if dir %s", buildPath) | ||
} | ||
if !isDir { | ||
return buildFile(buildPath, fs, builder) | ||
} | ||
|
||
files, err := fs.ReadDir(buildPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "read dir %s", buildPath) | ||
} | ||
for _, file := range files { | ||
childPath := filepath.Join(buildPath, file.Name()) | ||
if file.IsDir() { | ||
err = BuildDir(childPath, fs, builder) | ||
if err != nil { | ||
return errors.Wrapf(err, "build dir %s", childPath) | ||
} | ||
} else { | ||
err = buildFile(childPath, fs, builder) | ||
if err != nil { | ||
return errors.Wrapf(err, "build file %s", childPath) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func buildFile(buildPath string, fs *afero.Afero, builder *Builder) error { | ||
fileContents, err := fs.ReadFile(buildPath) | ||
if err != nil { | ||
return errors.Wrapf(err, "read file %s", buildPath) | ||
} | ||
|
||
newContents, err := builder.String(string(fileContents)) | ||
if err != nil { | ||
return errors.Wrapf(err, "template file %s", buildPath) | ||
} | ||
|
||
err = fs.WriteFile(buildPath, []byte(newContents), os.FileMode(777)) | ||
if err != nil { | ||
return errors.Wrapf(err, "write file %s", buildPath) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package templates | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/replicatedhq/ship/pkg/testing/logger" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBuildDir(t *testing.T) { | ||
type file struct { | ||
contents string | ||
path string | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
buildPath string | ||
inputFiles []file | ||
outputFiles []file | ||
}{ | ||
{ | ||
name: "no templates", | ||
buildPath: "dir", | ||
inputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
}, | ||
outputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "template not in dir", | ||
buildPath: "dir", | ||
inputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
{ | ||
contents: `{{repl ConfigOption "option_1"}}`, | ||
path: "notDir/template.txt", | ||
}, | ||
}, | ||
outputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
{ | ||
contents: `{{repl ConfigOption "option_1"}}`, | ||
path: "notDir/template.txt", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "template in dir", | ||
buildPath: "dir", | ||
inputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
{ | ||
contents: `{{repl ConfigOption "option_1"}}`, | ||
path: "dir/template.txt", | ||
}, | ||
}, | ||
outputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "dir/file.txt", | ||
}, | ||
{ | ||
contents: "Option 1", | ||
path: "dir/template.txt", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "template in subdir", | ||
buildPath: "anotherdir", | ||
inputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "anotherdir/file.txt", | ||
}, | ||
{ | ||
contents: `{{repl ConfigOption "option_2"}}`, | ||
path: "anotherdir/subdir/template.txt", | ||
}, | ||
}, | ||
outputFiles: []file{ | ||
{ | ||
contents: "notATemplate", | ||
path: "anotherdir/file.txt", | ||
}, | ||
{ | ||
contents: "Option 2", | ||
path: "anotherdir/subdir/template.txt", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
req := require.New(t) | ||
|
||
fs := afero.Afero{Fs: afero.NewMemMapFs()} | ||
|
||
for _, file := range tt.inputFiles { | ||
req.NoError(fs.WriteFile(file.path, []byte(file.contents), os.FileMode(777))) | ||
} | ||
|
||
builderBuilder := &BuilderBuilder{ | ||
Logger: &logger.TestLogger{T: t}, | ||
Viper: viper.New(), | ||
} | ||
|
||
builder := builderBuilder.NewBuilder( | ||
builderBuilder.NewStaticContext(), | ||
testContext{}, | ||
) | ||
|
||
err := BuildDir(tt.buildPath, &fs, &builder) | ||
req.NoError(err) | ||
|
||
for _, file := range tt.outputFiles { | ||
actualContents, err := fs.ReadFile(file.path) | ||
req.NoError(err) | ||
req.Equal(file.contents, string(actualContents)) | ||
} | ||
}) | ||
} | ||
} |