Skip to content

Commit

Permalink
feat: add no_readme option in .craft
Browse files Browse the repository at this point in the history
Signed-off-by: kilianpaquier <kilian@kilianpaquier.com>
  • Loading branch information
kilianpaquier committed Oct 3, 2024
1 parent c56f1a5 commit 8b100be
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 56 deletions.
113 changes: 59 additions & 54 deletions .schemas/craft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
"type": "object",
"additionalProperties": false,
"$defs": {
"maintainer": {
"description": "Maintainer definition",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"description": "Maintainer name (can be any entity, person name, group name, etc.).",
"type": "string"
},
"email": {
"description": "Maintainer email.",
"type": "string"
},
"url": {
"description": "Maintainer URL.",
"type": "string"
}
},
"required": [
"name"
]
},
"ci": {
"description": "CI definition to help generate specific files.",
"type": "object",
Expand Down Expand Up @@ -90,17 +68,17 @@
"description": "Static deployment configuration.",
"type": "object",
"properties": {
"auto": {
"description": "Whether to automatically deploy static builds or not on main branches for github and on protected branches for gitlab.",
"type": "boolean"
},
"name": {
"description": "Static deployment name.",
"type": "string",
"enum": [
"netlify",
"pages"
]
},
"auto": {
"description": "Whether to automatically deploy static builds or not on main branches for github and on protected branches for gitlab.",
"type": "boolean"
}
}
}
Expand All @@ -114,30 +92,42 @@
"type": "object",
"additionalProperties": false,
"properties": {
"registry": {
"description": "Docker registry associated to project. It will be used for CI docker build & push alongside chart image pull.",
"type": "string",
"default": "ghcr.io"
},
"port": {
"description": "Container port to override the default one, 3000.",
"type": "integer",
"default": 3000
},
"registry": {
"description": "Docker registry associated to project. It will be used for CI docker build & push alongside chart image pull.",
"type": "string",
"default": "ghcr.io"
}
}
},
"maintainer": {
"description": "Maintainer definition",
"type": "object",
"additionalProperties": false,
"properties": {
"email": {
"description": "Maintainer email.",
"type": "string"
},
"name": {
"description": "Maintainer name (can be any entity, person name, group name, etc.).",
"type": "string"
},
"url": {
"description": "Maintainer URL.",
"type": "string"
}
},
"required": [
"name"
]
}
},
"properties": {
"description": {
"description": "Description, only useful when working with docker option and helm generations.",
"type": "string"
},
"maintainers": {
"description": "List of maintainers.",
"type": "array",
"$ref": "#/$defs/maintainer",
"minItems": 1
},
"bot": {
"description": "Bot in charge of keeping dependencies up to date.",
"type": "string",
Expand All @@ -146,6 +136,20 @@
"renovate"
]
},
"ci": {
"description": "CI definition to help generate specific files.",
"type": "object",
"$ref": "#/$defs/ci"
},
"description": {
"description": "Description, only useful when working with docker option and helm generations.",
"type": "string"
},
"docker": {
"description": "Docker definition.",
"type": "object",
"$ref": "#/$defs/docker"
},
"license": {
"description": "License name.",
"type": "string",
Expand All @@ -166,19 +170,11 @@
"unlicense"
]
},
"ci": {
"description": "CI definition to help generate specific files.",
"type": "object",
"$ref": "#/$defs/ci"
},
"platform": {
"description": "Platform for README.md badges (automatically parsed with git origin URL by default).",
"type": "string"
},
"docker": {
"description": "Docker definition.",
"type": "object",
"$ref": "#/$defs/docker"
"maintainers": {
"description": "List of maintainers.",
"type": "array",
"$ref": "#/$defs/maintainer",
"minItems": 1
},
"no_chart": {
"description": "Disable and remove chart generation.",
Expand All @@ -194,6 +190,15 @@
"description": "Disable and remove makefile generation.",
"type": "boolean",
"default": false
},
"no_readme": {
"description": "Disable and remove README.md generation.",
"type": "boolean",
"default": false
},
"platform": {
"description": "Platform for README.md badges (automatically parsed with git origin URL by default).",
"type": "string"
}
},
"required": [
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ no_goreleaser: true | false
# this option is automatically disabled when working with nodejs generation
no_makefile: true | false

# whether to generate a README.md with initial badges and informations (optional)
no_readme: true | false

# platform override in case of gitlab on premise, bitbucket on premise, etc.
# by default, an on premise gitlab will be matched if the host contains "gitlab"
# by default, an on premise bitbucket will be matched if the host contains "bitbucket" or "stash"
Expand Down
1 change: 1 addition & 0 deletions pkg/craft/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Configuration struct {
NoChart bool `json:"-" yaml:"no_chart,omitempty"`
NoGoreleaser bool `json:"-" yaml:"no_goreleaser,omitempty"`
NoMakefile bool `json:"-" yaml:"no_makefile,omitempty"`
NoReadme bool `json:"-" yaml:"no_readme,omitempty"`
Platform string `json:"-" yaml:"platform,omitempty" validate:"omitempty,oneof=bitbucket gitea github gitlab"`
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/generate/filehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func MetaHandlers() []MetaHandler {
Gitlab,
Goreleaser,
Makefile,
Readme,
Releaserc,
Renovate,
Sonar,
Expand Down Expand Up @@ -140,13 +141,13 @@ func githubWorkflows(metadata Metadata) FileHandler { //nolint:cyclop
}
}

var _actionRegexp = regexp.MustCompile(`\.github/actions/[\w]+/action\.yml\.tmpl$`)
var githubActionFileRegexp = regexp.MustCompile(`\.github/actions/[\w]+/action\.yml\.tmpl$`)

// githubActions returns the handler for all files related to .github/actions directory.
func githubActions(metadata Metadata) FileHandler {
return func(src, _, _ string) (_ bool, _ bool) {
// files related to dir .github/actions
if !_actionRegexp.MatchString(src) {
if !githubActionFileRegexp.MatchString(src) {
return false, false
}

Expand Down Expand Up @@ -198,6 +199,16 @@ func Makefile(metadata Metadata) FileHandler {
}
}

// Readme returns the handler for README.md option generation matching.
func Readme(metadata Metadata) FileHandler {
return func(src, dest, name string) (ok bool, apply bool) {
if name != "README.md" {
return false, false
}
return true, !metadata.NoReadme
}
}

// Releaserc returns the handler for releaserc option generation matching.
func Releaserc(metadata Metadata) FileHandler {
return func(_, _, name string) (_ bool, _ bool) {
Expand Down

0 comments on commit 8b100be

Please sign in to comment.