Skip to content
Snippets Groups Projects
Unverified Commit e6f7afb7 authored by Florian Forster's avatar Florian Forster
Browse files

feat(yamlfmt): Migrate to the "pattern file" discovery method.

This new feature in yamlfmt 0.15.0 allows us to specify which files to format
(and which to ignore) using a file with the "gitignore" syntax.
parent cb786c6b
No related branches found
No related tags found
No related merge requests found
Pipeline #24648787 passed
Loading
Loading
@@ -20,7 +20,27 @@ include:
 
The *yamlfmt* job provides very limited configuration options. This is by design.
 
### Excluding files
### Including and excluding files
 
To exclude files, create a file named `.yamlfmtignore` at the root of your repository.
The file uses [gitignore](https://git-scm.com/docs/gitignore) syntax to excempt some files, such as test data, from formatting.
The `.yamlfmt.patterns` file allows to specify additional files and/or exclude files from the format check.
It is sometimes desireable to check the format of files that do not have the usual `.yaml` or `.yml` suffix.
At other times it is necessary to exclude files from the format check, for example intentionally malformed test data.
To include or exclude files, create a file named `.yamlfmt.patterns` at the root of your repository.
Files to **include** are added as normal (positive) entries, for example:
```gitignore
/.some-tool # dotfile using YAML syntax but without the suffix
```
Files to **exclude** are added a negated entries, for example:
```gitignore
!testdata/
```
The `.yamlfmt.patterns` file uses [gitignore](https://git-scm.com/docs/gitignore) syntax.
Despite the name, only negated entries (beginning with an exclamation point `!`) are *excluded*, all other entries are *included*.
The `.yamlfmt.patterns` file is combined with [the default `yamlfmt.patterns` file](https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks-images/-/blob/main/yamlfmt/yamlfmt.patterns?ref_type=heads) with the default file coming first and the `.yamlfmt.patterns` file second/below.
Loading
Loading
@@ -11,21 +11,19 @@ yamlfmt:
name: registry.gitlab.com/gitlab-com/gl-infra/common-ci-tasks-images/yamlfmt:${GL_ASDF_YAMLFMT_VERSION}
entrypoint: [""]
script:
# yamlfmt will fail if this file doesn't exist.
- touch .yamlfmtignore
- |
declare -a PATTERNS=('*.yaml' '*.yml')
if [[ -e .yamlfmtextra ]]; then
IFS=' '
while read -r pattern; do
PATTERNS+=("${pattern}")
done <<<$(grep -E -v '^\s*(#|$)' .yamlfmtextra)
fi
- |
# Dump yamlfmt config
echo "# /etc/yamlfmt.yaml"
cat /etc/yamlfmt.yaml
- yamlfmt -conf /etc/yamlfmt.yaml "${PATTERNS[@]}"
- |
# Dump pattern file
PATTERN_FILES=("/etc/yamlfmt.patterns")
if [[ -e .yamlfmt.patterns ]]; then
PATTERN_FILES+=(".yamlfmt.patterns")
fi
echo "# ${PATTERN_FILES[@]}"
cat "${PATTERN_FILES[@]}"
- yamlfmt -conf /etc/yamlfmt.yaml "${PATTERN_FILES[@]}"
- git diff | tee yamlfmt.patch
- |
if [[ -s yamlfmt.patch ]]; then
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment