【Github】Github Actions ~ YAML Linter ~

■ はじめに

https://dk521123.hatenablog.com/entry/2024/08/08/202314

の続き。

今回は、YAMLファイルをGithub Actionsでチェックする方法について
調べてみた。

目次

【1】Third-Party Github Action を利用する
【2】サンプル

【1】Third-Party Github Action を利用する

* 以下を利用できる

karancode/yamllint-github-action
https://github.com/marketplace/actions/yamllint-github-action
ibiqlik/action-yamllint
https://github.com/marketplace/actions/yaml-lint

* Reviewdog も対応してくれている

reviewdog/action-yamllint
https://github.com/reviewdog/action-yamllint

【2】サンプル

.github/workflows/demo-validate-yaml.yml

name: ValidateYaml

on:
  push:
    paths:
      # YAML ファイル (.yaml or .yml) をプッシュするたびに実行
      - '**.yaml'
      - '**.yml'
jobs:
  validate-yaml:
    runs-on: ubuntu-latest

    steps:
      - name: "Checkout"
        uses: actions/checkout@v4
      - name: Validate YAML file
        uses: karancode/yamllint-github-action@v2.1.1
        with:
          yamllint_file_or_dir: .

動作確認

test.yaml

hello:
  world:
    key1: value1
    key2: value2

出力結果例

  Warning: 1:1 [document-start] missing document start "---"
  Warning: 3:1 [truthy] truthy value should be one of [false, true]
  Error: 10:34 [trailing-spaces] trailing spaces
  Error: 15:81 [line-length] line too long (106 > 80 characters)
  Error: 19:81 [line-length] line too long (108 > 80 characters)
  Error: 23:81 [line-length] line too long (105 > 80 characters)
  Error: 33:1 [empty-lines] too many blank lines (1 > 0)

参考文献

https://qiita.com/EnKUMA/items/6974e310221fc9765c2f

関連記事

Github Actions ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2021/11/04/142835
Github Actions ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2022/06/16/151443
Github Actions ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2023/12/22/195715
Github Actions ~ Pythonを使うには ~
https://dk521123.hatenablog.com/entry/2024/02/04/011205
Github Actions ~ Python関連 ~
https://dk521123.hatenablog.com/entry/2022/06/21/143624
Github Actions ~ SQL Linter ~
https://dk521123.hatenablog.com/entry/2024/03/04/180308
Github Actions ~ Scala Linter ~
https://dk521123.hatenablog.com/entry/2024/04/02/002828
Github Actions ~ JSON Linter ~
https://dk521123.hatenablog.com/entry/2024/08/08/202314
Github Actions ~ TOML Linter ~
https://dk521123.hatenablog.com/entry/2024/08/10/115429
Python ~ 基本編 / コマンドライン引数 ~
https://dk521123.hatenablog.com/entry/2019/10/11/223651
reviewdog ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2024/04/18/161200