diff --git a/action.yml b/action.yml index bcadc15..49bf119 100644 --- a/action.yml +++ b/action.yml @@ -26,7 +26,7 @@ runs: - run - --forge=github - --branch=${{ inputs.branch }} - - --extra-files=${{ inputs.extra-files }} + - --extra-files="${{ inputs.extra-files }}" env: - GITHUB_TOKEN: ${{ inputs.token }} + GITHUB_TOKEN: "${{ inputs.token }}" GITHUB_USER: "oauth2" diff --git a/cmd/rp/cmd/run.go b/cmd/rp/cmd/run.go index 8fe818f..c29047b 100644 --- a/cmd/rp/cmd/run.go +++ b/cmd/rp/cmd/run.go @@ -95,6 +95,12 @@ func run(cmd *cobra.Command, _ []string) error { } func parseExtraFiles(input string) []string { + // We quote the arg to avoid issues with the expected newlines in the value. + // Need to remove those quotes before parsing the data + input = strings.Trim(input, `"`) + // In some situations we get a "\n" sequence, where we actually expect new lines, + // replace the two characters with an actual new line + input = strings.ReplaceAll(input, `\n`, "\n") lines := strings.Split(input, "\n") extraFiles := make([]string, 0, len(lines)) diff --git a/cmd/rp/cmd/run_test.go b/cmd/rp/cmd/run_test.go new file mode 100644 index 0000000..d4cea7a --- /dev/null +++ b/cmd/rp/cmd/run_test.go @@ -0,0 +1,59 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_parseExtraFiles(t *testing.T) { + tests := []struct { + name string + input string + want []string + }{ + { + name: "empty", + input: ``, + want: []string{}, + }, + { + name: "empty quoted", + input: `""`, + want: []string{}, + }, + { + name: "single", + input: `foo.txt`, + want: []string{"foo.txt"}, + }, + { + name: "single quoted", + input: `"foo.txt"`, + want: []string{"foo.txt"}, + }, + { + name: "multiple", + input: `foo.txt +dir/Chart.yaml`, + want: []string{"foo.txt", "dir/Chart.yaml"}, + }, + { + name: "multiple quoted", + input: `"foo.txt +dir/Chart.yaml"`, + want: []string{"foo.txt", "dir/Chart.yaml"}, + }, + { + name: "multiple with broken new lines", + input: `"action.yml\ntemplates/run.yml\n"`, + want: []string{"action.yml", "templates/run.yml"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := parseExtraFiles(tt.input) + assert.Equal(t, tt.want, got) + }) + } +} diff --git a/templates/run.yml b/templates/run.yml index e1d16a5..27ca27d 100644 --- a/templates/run.yml +++ b/templates/run.yml @@ -33,4 +33,4 @@ releaser-pleaser: rp run \ --forge=gitlab \ --branch=$[[ inputs.branch ]] \ - --extra-files=$[[ inputs.extra-files ]] + --extra-files="$[[ inputs.extra-files ]]"