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

OSOE-188: YAML Linting #302

Merged
merged 64 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
93c976c
Set yaml-linting step as a reusable action
tteguayco Dec 11, 2023
ef69227
Add workflow extension
tteguayco Dec 11, 2023
cbfe603
Point to actions in feature branch
tteguayco Dec 11, 2023
23ddd43
Fix wrong workflow path
tteguayco Dec 11, 2023
5aa9ee3
Fix indentation
tteguayco Dec 11, 2023
eb66182
Add 'shell' missing param for GH action
tteguayco Dec 11, 2023
79c11ec
Add path to yamllint config file in trunk folder
tteguayco Dec 11, 2023
7726c35
Fix path to yamllint config file in trunk folder
tteguayco Dec 11, 2023
172d3a6
Comment out linting step for Linux
tteguayco Dec 11, 2023
4343038
Fix path for Windows step
tteguayco Dec 11, 2023
1ca5f97
Add parameters to linting action
tteguayco Dec 11, 2023
660e5fe
Fix typo
tteguayco Dec 11, 2023
5636c13
Add type property to action inputs
tteguayco Dec 11, 2023
8c79a09
Same step for both OS
tteguayco Dec 11, 2023
96f4085
Remove references to feature branch
tteguayco Dec 11, 2023
5a626e1
Fix trailing whitespaces in Lombiq.GitHub.Actions
tteguayco Dec 16, 2023
64422f7
Add YAML linting instructions
tteguayco Dec 16, 2023
d59d9d5
Remove unsed yamllint.yaml files
tteguayco Dec 16, 2023
4bcdde3
Merge branch 'dev' of https://github.com/Lombiq/GitHub-Actions into i…
tteguayco Dec 16, 2023
7d94d84
Add file-existance safe check to Get-GHA-Items-From-File-List.ps1 script
tteguayco Dec 18, 2023
1f1fea1
Update YAML Linting Job Name
tteguayco Dec 18, 2023
fc7c708
Change references to new feature branch in new yaml linting workflow
tteguayco Dec 18, 2023
602d694
Change references to new feature branch in new yaml linting workflow
tteguayco Dec 18, 2023
f631ab4
Remove extra whitespaces
tteguayco Dec 18, 2023
0e0fb42
Open brances in new line
tteguayco Dec 18, 2023
fd8dcee
Change reference to feature branch for get-changed-files-from-git-dif…
tteguayco Dec 18, 2023
3fbd2f7
Change reference to feature branch for get-changed-files-from-git-dif…
tteguayco Dec 18, 2023
b086325
Typo
tteguayco Dec 18, 2023
e3f78e6
Add runtimes as valid work for spell checker
tteguayco Dec 23, 2023
8ebff7e
Replace if-else with Test-Path by Try-Catch
tteguayco Dec 23, 2023
b7fabb9
Add previous if-else to workflow filtering logic
tteguayco Dec 23, 2023
e04870d
Update target branch in GHA workflow
tteguayco Dec 23, 2023
c3911c8
update target branch ref in failing workflows
tteguayco Dec 23, 2023
de782d4
update target branch ref in failing workflows
tteguayco Dec 23, 2023
cdcef75
Revert Get-GHA-Items-From-File.ps1 script changes
tteguayco Dec 23, 2023
d3c6304
Revert Get-GHA-Items-From-File.ps1 script changes
tteguayco Dec 23, 2023
ce87cac
Start brace in a new line
tteguayco Dec 23, 2023
483f193
Remove machine-type parameter from GHA workflow
tteguayco Dec 28, 2023
9fdd830
Set quotes style for YAML linting
tteguayco Dec 28, 2023
e1bb753
Improve documentation for YAML linting workflow
tteguayco Dec 28, 2023
21ad035
Fix markdown styles
tteguayco Dec 28, 2023
64a16c3
Update search-path for yaml linting
tteguayco Dec 28, 2023
df13251
Merge branch 'dev' of https://github.com/Lombiq/GitHub-Actions into i…
tteguayco Jan 8, 2024
dcb4a77
Update Docs/Workflows/Productivity/YamlLinting.md
tteguayco Jan 8, 2024
e9fcb59
Add required new line
tteguayco Jan 8, 2024
4fcbc3d
Update Docs/Workflows/Productivity/YamlLinting.md
tteguayco Jan 9, 2024
dcaed62
Update Docs/Workflows/Productivity/YamlLinting.md
tteguayco Jan 9, 2024
bbc455b
Merge branch 'dev' of https://github.com/Lombiq/GitHub-Actions into i…
tteguayco Jan 16, 2024
1dee81b
Update doc
tteguayco Jan 16, 2024
046f74f
Update doc
tteguayco Jan 16, 2024
319b9aa
Rename ps script file
tteguayco Jan 16, 2024
49b59f1
Replacing issue actions with dev
DemeSzabolcs Jan 17, 2024
b7ef6dc
Apply file lookup only on .github folder
tteguayco Jan 23, 2024
d11532b
Merge branch 'issue/OSOE-188' of https://github.com/Lombiq/GitHub-Act…
tteguayco Jan 23, 2024
18d44a4
Update branch ref
tteguayco Jan 23, 2024
9b2b004
Revert branch ref
tteguayco Jan 23, 2024
8a8896b
Changing actions/get-changed-gha-items to issue branch
DemeSzabolcs Jan 24, 2024
04fe7df
Revert "Changing actions/get-changed-gha-items to issue branch"
DemeSzabolcs Jan 24, 2024
c5ab129
Revert "Replacing issue actions with dev"
DemeSzabolcs Jan 24, 2024
f7b2809
Using issue branch
DemeSzabolcs Jan 24, 2024
f1624b9
Remove unnecessary try-catch block
tteguayco Jan 25, 2024
4625c0b
Merge branch 'issue/OSOE-188' of https://github.com/Lombiq/GitHub-Act…
tteguayco Jan 25, 2024
d69fcd5
Merge remote-tracking branch 'origin/dev' into issue/OSOE-188
DemeSzabolcs Jan 26, 2024
70e6288
Using dev branch in workflows
DemeSzabolcs Jan 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH

- name: Check Current Workflow Equals Latest
shell: pwsh
id: check-current-workflow-equals-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/check-merge-queue-adds/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Check Merge Queue Adds
description: >
Checks current pull request timeline add events to determine if it was ever added to a
merge queue. Intentionally not documented in Actions.md since it's only meant for
Checks current pull request timeline add events to determine if it was ever added to a
merge queue. Intentionally not documented in Actions.md since it's only meant for
internal use.

outputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ param(

# Filter actions based on files in action directory.
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
[array]$actionFiles = $FileIncludeList | Where-Object -FilterScript {
(Get-Item $PSitem).Directory.GetFiles('action.yml').Count -gt 0 -or
(Get-Item $PSitem).Directory.GetFiles('action.yaml').Count -gt 0
try
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
{
(Get-Item $PSitem).Directory.GetFiles('action.yml').Count -gt 0 -or
(Get-Item $PSitem).Directory.GetFiles('action.yaml').Count -gt 0
}
catch
{
return $false
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
}
}

# GitHub Actions are called by directory name. Get directory and de-duplicate list.
[array]$actions = $actionFiles.ForEach({ $PSItem.Replace('/' + $(Get-Item $PSItem).Name, '') }) | Select-Object -Unique

# Filter workflow files excluding action yaml file names.
[array]$workflows = $FileIncludeList | Where-Object -FilterScript {
(Get-Item $PSitem).BaseName -ne 'action' -and
((Get-Item $PSitem).Extension -eq '.yml' -or
(Get-Item $PSitem).Extension -eq '.yaml')
try
{
(Get-Item $PSitem).BaseName -ne 'action' -and
((Get-Item $PSitem).Extension -eq '.yml' -or
(Get-Item $PSitem).Extension -eq '.yaml')
}
catch
{
return $false
}
}

# Combine actions and workflows.
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/get-changed-gha-items/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
required: false
default: '@()'
description: >
PowerShell string array of file names to return corresponding GitHub Actions (GHA) items. The
PowerShell string array of file names to return corresponding GitHub Actions (GHA) items. The
parameter must be a PowerShell string array.
outputs:
changed-items:
Expand All @@ -20,12 +20,12 @@ runs:
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH

- name: Get GHA Items
id: get-gha-items
shell: pwsh
run: |
$params = @{
FileIncludeList = ${{ inputs.file-include-list }}
}
Get-GHA-Items-From-File-List @params
Get-GhaItemsFromFileList @params
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runtimes
21 changes: 21 additions & 0 deletions .github/actions/yaml-lint/action.yml
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
16 changes: 16 additions & 0 deletions .github/workflows/yaml-lint-this-repo.yml
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'
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
search-path: '.'
55 changes: 55 additions & 0 deletions .github/workflows/yaml-lint.yml
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 }}
8 changes: 8 additions & 0 deletions .trunk/.gitignore
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
16 changes: 16 additions & 0 deletions .trunk/configs/.yamllint.yaml
tteguayco marked this conversation as resolved.
Show resolved Hide resolved
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
tteguayco marked this conversation as resolved.
Show resolved Hide resolved
}
20 changes: 20 additions & 0 deletions .trunk/trunk.yaml
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:
- node@18.12.1
- python@3.10.8
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- yamllint@1.33.0
1 change: 1 addition & 0 deletions Docs/Workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ These features are designed to reduce resource usage (like paid GitHub Actions m
- [Spell-checking](Workflows/Productivity/SpellChecking.md)
- [Validate pull request](Workflows/Productivity/ValidatePullRequest.md)
- [Validate submodule](Workflows/Productivity/ValidateSubmodule.md)
- [Lint YAML files](Workflows/Productivity/YamlLinting.md)

## Azure hosting

Expand Down
34 changes: 34 additions & 0 deletions Docs/Workflows/Productivity/YamlLinting.md
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.
Loading