diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index 5294b7d7..e99b6e75 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -9,6 +9,7 @@ on: - 'www/*' - 'cmd/*' - 'internal/cmd/*' + - 'files/*' jobs: docs: diff --git a/Taskfile.yml b/Taskfile.yml index a28e8747..350f2b6e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -88,6 +88,7 @@ tasks: - ./scripts/cmd_docs.sh sources: - cmd/*.go + - files/*.go - nfpm.go - ./scripts/cmd_docs.sh - CONTRIBUTING.md diff --git a/apk/apk_test.go b/apk/apk_test.go index 1fb3ec70..6b2dfbe9 100644 --- a/apk/apk_test.go +++ b/apk/apk_test.go @@ -76,6 +76,11 @@ func exampleInfo() *nfpm.Info { Destination: "/etc/fake/fake.conf", Type: "config", }, + { + Source: "../testdata/whatever.conf", + Destination: "/etc/fake/fake2.conf", + Type: "config|noreplace", + }, { Destination: "/var/log/whatever", Type: "dir", @@ -105,7 +110,7 @@ func TestCreateBuilderData(t *testing.T) { require.NoError(t, builderData(tw)) - require.Equal(t, 11784, buf.Len()) + require.Equal(t, 13832, buf.Len()) } func TestCombineToApk(t *testing.T) { @@ -140,6 +145,7 @@ func TestDefaultWithArch(t *testing.T) { "usr/share/doc/fake/fake.txt": "96c335dc28122b5f09a4cef74b156cd24c23784c", "usr/local/bin/fake": "f46cece3eeb7d9ed5cb244d902775427be71492d", "etc/fake/fake.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c", + "etc/fake/fake2.conf": "96c335dc28122b5f09a4cef74b156cd24c23784c", } for _, arch := range []string{"386", "amd64"} { arch := arch diff --git a/deb/deb_test.go b/deb/deb_test.go index 6e20c79d..539956f0 100644 --- a/deb/deb_test.go +++ b/deb/deb_test.go @@ -73,6 +73,11 @@ func exampleInfo() *nfpm.Info { Destination: "/etc/fake/fake.conf", Type: "config", }, + { + Source: "../testdata/whatever.conf", + Destination: "/etc/fake/fake2.conf", + Type: "config|noreplace", + }, { Destination: "/var/log/whatever", Type: "dir", diff --git a/files/files.go b/files/files.go index 868e7e01..7b220fea 100644 --- a/files/files.go +++ b/files/files.go @@ -15,8 +15,8 @@ import ( // of one file to copy into a package. type Content struct { Source string `yaml:"src,omitempty" json:"src,omitempty"` - Destination string `yaml:"dst,omitempty" json:"dst,omitempty"` - Type string `yaml:"type,omitempty" json:"type,omitempty"` + Destination string `yaml:"dst" json:"dst"` + Type string `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"enum=symlink,enum=ghost,enum=config,enum=config|noreplace,enum=dir,enum=,default="` Packager string `yaml:"packager,omitempty" json:"packager,omitempty"` FileInfo *ContentFileInfo `yaml:"file_info,omitempty" json:"file_info,omitempty"` } @@ -150,7 +150,7 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents // Ghost, symlinks and dirs need to be in the list, but dont glob // them because they do not really exist files = append(files, f.WithFileInfoDefaults()) - default: + case "config", "config|noreplace", "file", "": globbed, err = glob.Glob(f.Source, f.Destination, disableGlobbing) if err != nil { return nil, err @@ -160,6 +160,8 @@ func ExpandContentGlobs(contents Contents, disableGlobbing bool) (files Contents if err != nil { return nil, err } + default: + return files, fmt.Errorf("invalid file type: %s", f.Type) } } diff --git a/files/files_test.go b/files/files_test.go index 06dceeec..19240146 100644 --- a/files/files_test.go +++ b/files/files_test.go @@ -382,3 +382,48 @@ func TestDestEndsWithSlash(t *testing.T) { require.Len(t, result, 1) require.Equal(t, "foo/a.txt", result[0].Destination) } + +func TestInvalidFileType(t *testing.T) { + var config testStruct + dec := yaml.NewDecoder(strings.NewReader(`--- +contents: +- src: testdata/globtest/**/* + dst: /bla + type: filr +`)) + dec.KnownFields(true) + require.NoError(t, dec.Decode(&config)) + _, err := files.ExpandContentGlobs(config.Contents, false) + require.EqualError(t, err, "invalid file type: filr") +} + +func TestValidFileTypes(t *testing.T) { + var config testStruct + dec := yaml.NewDecoder(strings.NewReader(`--- +contents: +- src: testdata/globtest/a.txt + dst: /f1.txt +- src: testdata/globtest/a.txt + dst: /f2.txt + type: file +- src: testdata/globtest/a.txt + dst: /f3.txt + type: config +- src: testdata/globtest/a.txt + dst: /f4.txt + type: config|noreplace +- src: testdata/globtest/a.txt + dst: /f5.txt + type: symlink +- src: testdata/globtest/a.txt + dst: /f6.txt + type: dir +- src: testdata/globtest/a.txt + dst: /f7.txt + type: ghost +`)) + dec.KnownFields(true) + require.NoError(t, dec.Decode(&config)) + _, err := files.ExpandContentGlobs(config.Contents, false) + require.NoError(t, err) +} diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index 8856fa34..1a57c0e3 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -317,7 +317,16 @@ "type": "string" }, "type": { - "type": "string" + "type": "string", + "enum": [ + "symlink", + "ghost", + "config", + "config|noreplace", + "dir", + "" + ], + "default": "" }, "packager": { "type": "string" @@ -327,7 +336,10 @@ } }, "additionalProperties": false, - "type": "object" + "type": "object", + "required": [ + "dst" + ] }, "ContentFileInfo": { "properties": {