adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.85k stars 273 forks source link

Question using the validate-yaml job (github actions) #576

Closed malatinigreenly closed 1 year ago

malatinigreenly commented 1 year ago

Hi ! I found this very useful snippet in stackoverflow

name: Validate-YAML

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  validate-yaml:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Validate YAML file
        run: yamllint .

I would need to edit the configuration file to have an extremely relaxed config. But I am not very used to github actions so I am not sure how to do it.

I would like to have the necessary rules to make sure that the file is well formatted and would be compiled, but I would like other warning or errors (such as line length) to be disabled. I am doing this silly change :

run: echo "---\n\nyaml-files:\n  - '*.yaml'\n - '*.yml'\n - '*.yamllint'\n" > yamllint.yaml && echo "rules:\n" >> yamllint.yaml && echo " anchors:" >> yamllint.yaml && echo " enable\n" >> yamllint.yaml && echo " braces:" >> yamllint.yaml && echo " enable\n  colons:" >> yamllint.yaml && echo "enable\n commas:" >> yamllint.yaml && echo " enable\n" >> yamllint.yaml && echo "  document-end:" >> yamllint.yaml && echo " enable\n  document-start:" >> yamllint.yaml && echo " disable\n" >> yamllint.yaml && yamllint -c ./yamllint.yaml && yamllint .

but it does not work. Would you have some tips please ?

Please excuse my bad English.

Could you help me please ?

Thanks a lot guys !!

andrewimeson commented 1 year ago

If all you want is to validate the YAML and not to actually lint it for style issues or potentially misleading syntax, you probably don't want to use yamllint.

Deaddy commented 1 year ago

I think you could put the config directly into a file in your repo (e.g. .yamllint.yml) and then have the following run: yamllint . -c .yamllint.yml.

In your run command you also have && yamllint -c ./yamllint.yaml && yamllint . at the end, so you will once use your relaxed config and then the default config, which might be confusing.

malatinigreenly commented 1 year ago

Ok thanks @Deaddy, @andrewimeson ! :D I found a solution doing this :

name: Validate-YAML

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  validate-yaml:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Validate relaxed YAML file
        run:  ./.github/workflows/config/script.sh
        shell: bash

With

#!/bin/bash
yamllint --no-warnings -d "{extends:relaxed,rules:{ document-start: disable, trailing-spaces: disable}}" ./apps/
malatinigreenly commented 1 year ago

I thought at first not using yamllint @andrewimeson but then I was not sure what else to use