From cf8d99984cd2ae6612f6f34781c27b94d7b8f3b4 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Fri, 1 Mar 2024 16:42:49 -0500 Subject: [PATCH 1/4] Issue #101: Adding unified yaml linting rule to the yaml lint reusable workflow --- .github/workflows/workflow-yaml-check.md | 24 ++++++++++++++++------- .github/workflows/workflow-yaml-check.yml | 4 +++- .yamllint.yml | 8 +++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/workflow-yaml-check.md b/.github/workflows/workflow-yaml-check.md index 5cded6f..8c496ae 100644 --- a/.github/workflows/workflow-yaml-check.md +++ b/.github/workflows/workflow-yaml-check.md @@ -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. diff --git a/.github/workflows/workflow-yaml-check.yml b/.github/workflows/workflow-yaml-check.yml index d071b9b..40a38ed 100644 --- a/.github/workflows/workflow-yaml-check.yml +++ b/.github/workflows/workflow-yaml-check.yml @@ -34,7 +34,9 @@ jobs: if [ -n "${{ github.event.inputs.config-file-path }}" ]; then yamllint -c "${{ github.workspace }}/${{ github.event.inputs.config-file-path }}" "$file" else - yamllint "$file" + default_config_url="https://raw.githubusercontent.com/ai-cfia/github-workflows/main/.yamllint.yml" + curl -s -O $default_config_url + yamllint -c "./$(basename $default_config_url)" "$file" fi fi done diff --git a/.yamllint.yml b/.yamllint.yml index ceae632..ad3e5e5 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -1,7 +1,9 @@ --- extends: default +ignore: | + .git/ + rules: - line-length: - max: 120 - allow-non-breakable-inline-mappings: true + line-length: disable + truthy: disable From 9143388a8eedc45460d9892a3ae418ced79c1ccb Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 4 Mar 2024 11:46:19 -0500 Subject: [PATCH 2/4] Issue #101: Updating yaml linting workflow with cleaner solution --- .github/workflows/workflow-yaml-check.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow-yaml-check.yml b/.github/workflows/workflow-yaml-check.yml index 40a38ed..cb689bd 100644 --- a/.github/workflows/workflow-yaml-check.yml +++ b/.github/workflows/workflow-yaml-check.yml @@ -25,6 +25,13 @@ jobs: - 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 + - name: Lint YAML files run: | files=$(echo '${{ steps.files.outputs.all }}' | jq -r '.[]') @@ -34,9 +41,7 @@ jobs: if [ -n "${{ github.event.inputs.config-file-path }}" ]; then yamllint -c "${{ github.workspace }}/${{ github.event.inputs.config-file-path }}" "$file" else - default_config_url="https://raw.githubusercontent.com/ai-cfia/github-workflows/main/.yamllint.yml" - curl -s -O $default_config_url - yamllint -c "./$(basename $default_config_url)" "$file" + yamllint -c github-workflows/.yamllint.yml "$file" fi fi done From 6b7d966e495ecaa5ac5066145aef53ced5855707 Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Mon, 4 Mar 2024 12:26:58 -0500 Subject: [PATCH 3/4] Issue #101: Updating yaml linting workflow to checkout only config file --- .github/workflows/workflow-yaml-check.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/workflow-yaml-check.yml b/.github/workflows/workflow-yaml-check.yml index cb689bd..0f0add3 100644 --- a/.github/workflows/workflow-yaml-check.yml +++ b/.github/workflows/workflow-yaml-check.yml @@ -31,6 +31,9 @@ jobs: repository: ai-cfia/github-workflows path: github-workflows ref: main + sparse-checkout: | + .yamllint.yml + sparse-checkout-cone-mode: false - name: Lint YAML files run: | From 87d6d54476239b834a17568ee989e4bafc32544f Mon Sep 17 00:00:00 2001 From: SonOfLope Date: Tue, 5 Mar 2024 16:04:45 -0500 Subject: [PATCH 4/4] Issue #90: Fix issue were deleted files are parsed for linting --- .github/workflows/workflow-yaml-check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow-yaml-check.yml b/.github/workflows/workflow-yaml-check.yml index 0f0add3..16a935c 100644 --- a/.github/workflows/workflow-yaml-check.yml +++ b/.github/workflows/workflow-yaml-check.yml @@ -22,6 +22,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} + - name: Install yamllint run: pip install yamllint @@ -39,7 +40,7 @@ jobs: 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"