Skip to content

Commit

Permalink
Merge pull request #102 from ai-cfia/101-as-a-devops-i-would-like-to-…
Browse files Browse the repository at this point in the history
…have-a-unified-set-of-rules-for-yaml-linting

Issue #101: As a Devops, I would like to have a unified set of rules for yaml linting
  • Loading branch information
SonOfLope authored Mar 6, 2024
2 parents 452c3ad + 87d6d54 commit e3fdb01
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/workflow-yaml-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

## Overview

This workflow is designed to maintain and enforce coding standards within YAML files across multiple projects within the organization. It ensures that any changes made to YAML files are consistent with the predefined standards set by the organization.
This workflow is designed to maintain and enforce coding standards within YAML
files across multiple projects within the organization. It ensures that any
changes made to YAML files are consistent with the predefined standards set by
the organization.

## Usage

- **Purpose:** Validate the organization's yaml standards across projects. It is triggered by **pull requests** to ensure that any new or altered YAML files comply with these standards.
- **Purpose:** Validate the organization's yaml standards across projects. It is
triggered by **pull requests** to ensure that any new or altered YAML files
comply with these standards.
- **Steps**
- YAML Lint Test: The workflow runs a linting test on the changed YAML files using the given configuration if specified.
- YAML Lint Test: The workflow runs a linting test on the changed YAML files
using the given configuration if specified.
- **Input:** You can specify specify a custom configuration file path for the
yaml link check. If you have specific rules or configurations for link
validation, you can create a configuration file in the project you are
calling this workflow from and input the path to this workflow. You can
find the documentation for this file
validation, you can create a configuration file in the project you are calling
this workflow from and input the path to this workflow. If you omit to specify
a file path, the default config file from current repository will be used. You
can find the documentation for this file
[here](https://yamllint.readthedocs.io/en/stable/configuration.html)

## YAML Linting Guidelines for Developers

- The [fnando.linter](https://marketplace.visualstudio.com/items?itemName=fnando.linter) extension for Visual Studio Code provides a flexible linter framework, which can be used for linting YAML files.
- The
[fnando.linter](https://marketplace.visualstudio.com/items?itemName=fnando.linter)
extension for Visual Studio Code provides a flexible linter framework, which
can be used for linting YAML files.
15 changes: 13 additions & 2 deletions .github/workflows/workflow-yaml-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}


- name: Install yamllint
run: pip install yamllint

- name: Checkout code
uses: actions/checkout@v4
with:
repository: ai-cfia/github-workflows
path: github-workflows
ref: main
sparse-checkout: |
.yamllint.yml
sparse-checkout-cone-mode: false

- name: Lint YAML files
run: |
files=$(echo '${{ steps.files.outputs.all }}' | jq -r '.[]')
for file in $files; do
if [[ $file == *.yml || $file == *.yaml ]]; then
if [[ -f "$file" && ( $file == *.yml || $file == *.yaml ) ]]; then
# Check if a custom config path is provided and file exists
if [ -n "${{ github.event.inputs.config-file-path }}" ]; then
yamllint -c "${{ github.workspace }}/${{ github.event.inputs.config-file-path }}" "$file"
else
yamllint "$file"
yamllint -c github-workflows/.yamllint.yml "$file"
fi
fi
done
Expand Down
8 changes: 5 additions & 3 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
extends: default

ignore: |
.git/
rules:
line-length:
max: 120
allow-non-breakable-inline-mappings: true
line-length: disable
truthy: disable

0 comments on commit e3fdb01

Please sign in to comment.