-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-188: YAML Linting
- Loading branch information
Showing
13 changed files
with
194 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
runtimes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: YAML Linting | ||
description: Runs a linter on YAML files. | ||
|
||
|
||
inputs: | ||
config-file-path: | ||
description: 'Path to the yamllint configuration file' | ||
required: true | ||
default: '.yamllint.yaml' | ||
|
||
search-path: | ||
description: 'Path to search for YAML files' | ||
required: true | ||
default: '.' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Run yamllint | ||
run: yamllint -c "${{ inputs.config-file-path }}" "${{ inputs.search-path }}" | ||
shell: pwsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: YAML Linting | ||
|
||
# Runs for PRs opened for any branch, and pushes to the dev branch. | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
yaml-linting: | ||
name: YAML Linting | ||
uses: Lombiq/GitHub-Actions/.github/workflows/yaml-lint.yml@dev | ||
with: | ||
config-file-path: '.trunk/configs/.yamllint.yaml' | ||
search-path: '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: YAML Linting | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
CHECKOUT_TOKEN: | ||
required: false | ||
description: > | ||
The GitHub token to authenticate checkout. Pass in a GitHub personal access token if authenticated submodules | ||
are used. | ||
inputs: | ||
timeout-minutes: | ||
required: false | ||
type: number | ||
default: 10 | ||
description: Configuration for the timeout-minutes parameter of the workflow. GitHub's default is 360. | ||
cancel-workflow-on-failure: | ||
description: If set to "true", this will cancel the current workflow run with all jobs if this workflow fails. | ||
required: false | ||
type: string | ||
default: "true" | ||
config-file-path: | ||
description: 'Path to the yamllint configuration file' | ||
required: true | ||
type: string | ||
default: '.yamllint.yaml' | ||
search-path: | ||
description: 'Path to search for YAML files' | ||
required: true | ||
type: string | ||
default: '.' | ||
|
||
jobs: | ||
yaml-linting: | ||
runs-on: ubuntu-22.04 | ||
name: YAML Linting Job | ||
timeout-minutes: ${{ inputs.timeout-minutes }} | ||
steps: | ||
- name: Checkout | ||
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev | ||
with: | ||
token: ${{ secrets.CHECKOUT_TOKEN }} | ||
|
||
- name: YAML Linting | ||
uses: Lombiq/GitHub-Actions/.github/actions/yaml-lint@dev | ||
with: | ||
config-file-path: ${{ inputs.config-file-path }} | ||
search-path: ${{ inputs.search-path }} | ||
|
||
- name: Cancel Workflow on Failure | ||
if: failure() && inputs.cancel-workflow-on-failure == 'true' | ||
uses: Lombiq/GitHub-Actions/.github/actions/cancel-workflow@dev | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*out | ||
*logs | ||
*actions | ||
*notifications | ||
*tools | ||
plugins | ||
user_trunk.yaml | ||
user.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
yaml-files: | ||
- '*.yaml' | ||
- '*.yml' | ||
- '.yamllint' | ||
|
||
ignore: | | ||
**/node_modules/** | ||
**/.trunk/** | ||
rules: | ||
trailing-spaces: {} | ||
key-duplicates: {} | ||
quoted-strings: { | ||
quote-type: any, | ||
required: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file controls the behavior of Trunk: https://docs.trunk.io/cli | ||
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
version: 0.1 | ||
cli: | ||
version: 1.17.2 | ||
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) | ||
plugins: | ||
sources: | ||
- id: trunk | ||
ref: v1.3.0 | ||
uri: https://github.com/trunk-io/plugins | ||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
runtimes: | ||
enabled: | ||
- [email protected] | ||
- [email protected] | ||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) | ||
lint: | ||
enabled: | ||
- [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# YAML Linting | ||
|
||
This solution uses [`yamllint`](https://github.com/adrienverge/yamllint) for linting YAML files according to a configuration file. Such a configuration file includes a set of rules that are checked against when linting the files and can be found in `/.trunk/configs/.yamllint.yaml`. | ||
|
||
You would typically consume the corresponding GHA workflow for YAML linting like this: | ||
|
||
```yaml | ||
... | ||
|
||
jobs: | ||
yaml-linting: | ||
name: YAML Linting | ||
uses: Lombiq/GitHub-Actions/.github/workflows/yaml-lint.yml@dev | ||
with: | ||
config-file-path: 'tools/Lombiq.GitHub.Actions/.trunk/configs/.yamllint.yaml' | ||
search-path: '.' | ||
``` | ||
Where: | ||
- `config-file-path`: Specifies the location of the `yamllint` rules file to use. See more details about such file [here](https://yamllint.readthedocs.io/en/stable/rules.html). | ||
- `search-path`: Where the files to lint should be searched. | ||
|
||
## Integration with VSCode | ||
|
||
During local development, YAML linting can be enabled in VSCode via the [Trunk Check](https://marketplace.visualstudio.com/items?itemName=Trunk.io) extension. Such a tool will look for the `yamllint` configuration file located in the folder `/.trunk`, which is already setup. | ||
|
||
Additionally, the linter can be run as a standalone tool: | ||
|
||
```bash | ||
yamllint -c ./.trunk/configs/.yamllint.yaml ./github | ||
``` | ||
|
||
Optionally, the Trunk Code extension can be used in conjunction with the [YAML by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) extension, which provides IntelliSense and description-on-hover capabilities based on a schema. |