Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gherkin Linting to Megalinter Workflow and Update Implementation #292

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions artifacts/linting_rules/.gherkin-lintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"no-files-without-scenarios" : "on",
"no-unnamed-features": "on",
"no-unnamed-scenarios": "on",
"no-dupe-scenario-names": ["on", "in-feature"],
"no-dupe-feature-names": "on",
"no-partially-commented-tag-lines": "on",
"indentation" : [
"on", {
"Feature": 0,
"Background": 2,
"Scenario": 2,
"Step": 2,
"Examples": 4,
"example": 6,
"given": 4,
"when": 4,
"then": 4,
"and": 4,
"but": 4,
"feature tag": 2,
"scenario tag": 2
}
],
"no-trailing-spaces": "on",
"new-line-at-eof": ["on", "no"],
"no-multiple-empty-lines": "on",
"no-empty-file": "on",
"no-scenario-outlines-without-examples": "on",
"name-length": ["on", {"Feature": 90, "Step": 190, "Scenario": 190}],
"no-restricted-tags": ["on", {"tags": ["@watch", "@wip"]}],
"use-and": "on",
"keywords-in-logical-order": "on",
"no-duplicate-tags": "on",
"no-superfluous-tags": "on",
"no-homogenous-tags": "on",
"one-space-between-tags": "on",
"no-unused-variables": "on",
"no-background-only-scenario": "on",
"no-empty-background": "on",
"scenario-size": ["on", { "steps-length": {"Background": 15, "Scenario": 15}}],
"only-one-when": "off",
"allowed-tags": ["on", {
"patterns": [
"^@watch$",
"^@wip$",
"^@.*$"
]
}],
"file-name": ["off", {"style": "kebab-case"}],
"max-scenarios-per-file": ["on", {"maxScenarios": 50, "countOutlineExamples": true}],
"no-restricted-patterns": ["on", {
"Global": [
"^globally restricted pattern"
],
"Feature": [
"poor description",
"validate",
"verify"
],
"Background": [
"show last response",
"a debugging step"
],
"Scenario": [
"show last response",
"a debugging step"
]
}],
"required-tags": ["on", {
"tags": ["^@.*$"], // Allow any tag starting with '@'
"ignoreUntagged": false // Enforce tagging
}]
}
4 changes: 4 additions & 0 deletions artifacts/linting_rules/.github/workflows/megalinter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
run: npm install -g @stoplight/spectral
- name: Install Spectral functions
run: npm install -g @stoplight/spectral-functions
- name: Install Gherkin Linter
run: npm install -g gherkin-lint
- name: Run Gherkin Linting
run: gherkin-lint code/Test_definitions/*.feature
# - name: Run spectral:oas Spectral Linting
# run: spectral lint code/API_definitions/*.yaml --verbose --ruleset .spectral.yml
# Replace openapi.yaml file with your API specification file
Expand Down
39 changes: 36 additions & 3 deletions documentation/API-linting-Implementation-Guideline.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# CAMARA OpenAPI Linting Rules Implementaion Guideline [ How to integrate the rules into CAMARA repository ]
# CAMARA OpenAPI and Gherkin Linting Rules Implementaion Guideline [ How to integrate the rules into CAMARA repository ]

## Introduction

This guide provides instructions how to implement linting rules for the CAMARA APIs using two methods: **[GitHub Actions](API-linting-Implementation-Guideline.md#github-actions-integration)** and **[local deployment](API-linting-Implementation-Guideline.md#github-actions-integration)**, both methods use [Spectral tool](https://docs.stoplight.io/docs/spectral/674b27b261c3c-overview).
This guide provides instructions how to implement linting rules for the CAMARA APIs using two methods: **[GitHub Actions](API-linting-Implementation-Guideline.md#github-actions-integration)** and **[local deployment](API-linting-Implementation-Guideline.md#github-actions-integration)**, both methods use [Spectral tool](https://docs.stoplight.io/docs/spectral/674b27b261c3c-overview).
All needed files are stored in [artifacts subfolder](https://github.com/camaraproject/Commonalities/tree/API-linting-Implementation-Guideline/artifacts/linting_rules).

Additionally, it provides an overview of how to integrate Gherkin linting to test the feature files of test contributions.

The target method is linting rules integration with CAMARA API subproject repositories using GitHub Actions.


Expand All @@ -21,8 +23,12 @@ This file consolidates all rules:
2. Spectral rules with built-in functions
3. Spectral rules with custom<a href="https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/lint_function"> JavaScript functions</a>

## Gherkin Linting Configuration

The Gherkin Linting configuration consists of <b><a href="https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/.gherkin-lintrc"> .gherkin-lintrc</a></b> file, which contains all the rules defined for API Testing Guideline as described in [API-Testing-Guidelines.md](API-Testing-Guidelines.md)

## GitHub Actions Integration

## GitHub Actions Integration (Spectral)

1. Add **[.spectral.yml](https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/.spectral.yml)** (rules) file to -> root location of repository

Expand All @@ -36,6 +42,13 @@ This file consolidates all rules:
4. Add <b>[megalinter.yml](https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/.github/workflows/megalinter.yml)</b> to GitHub action workflows in `.github/workflows` folder
which includes the configuration of Megalinter and Spectral for GitHub actions.

## GitHub Actions Integration (Gherkin)

1. Add **[.gherkin-lintrc](https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/.gherkin-lintrc)** (rules) file to -> root location of repository

2. Add <b>[megalinter.yml](https://github.com/camaraproject/Commonalities/blob/main/artifacts/linting_rules/.github/workflows/megalinter.yml)</b> to GitHub action workflows in `.github/workflows` folder
which includes the configuration of Megalinter and Spectral for GitHub actions.

### Manually running linting workflow

**spectral_oas_lint.yml** includes configuration of the OAS linting workflow to be run manually as described in [GitHub Actions documentation](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow).
Expand Down Expand Up @@ -79,3 +92,23 @@ Additionally, Megalinter also supports linting of YAML files. To enable this, us
spectral lint openapi.yaml --verbose --ruleset .spectral.yml

*Replace **'openapi.yaml'** with the path to your OpenAPI specification file.*

## Gherkin Integration for Test Contribution Feature Files for local deployment

To integrate Gherkin linting into the Megalinter setup, follow these steps:

1. Install Gherkin Linter locally:

npm install -g gherkin-lint

2. Save files locally:

Save .gherkin-lintrc file at the root location of your repository with the desired linting rules.

3. Apply Gherkin rules on Test defination feature file loacally:

gherkin-lint Test.feature

*Replace **'test.feature'** with the path to your Test defination feature file.*