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-744: Add wrapper for the markdownlint-cli2 action #351

Merged
merged 41 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
79e77b8
Adding markdown-lint action and workflow
BenedekFarkas May 17, 2024
8399fda
Updating spelling dictionary and workflow references
BenedekFarkas May 17, 2024
eb24156
Updating configuration and workflow references
BenedekFarkas May 17, 2024
4d749e8
Updating markdown-lint-this-repo parameters to exclude License.md
BenedekFarkas May 17, 2024
c273b76
Fixing temporary spelling configuration
BenedekFarkas May 17, 2024
3c9b081
Fixing temporary spelling configuration again
BenedekFarkas May 17, 2024
30b2e9f
I really should RTFM I wrote
BenedekFarkas May 17, 2024
f2b2871
Updating markdown file detection glob
BenedekFarkas May 17, 2024
07aa3f9
Testing error detection by changing the configuration file
BenedekFarkas May 17, 2024
16be086
Removing concurrency configuration from the markdown-lint workflow, b…
BenedekFarkas May 17, 2024
1b7b4cf
Revert "Testing error detection by changing the configuration file"
BenedekFarkas May 17, 2024
cc1801b
Merge branch 'dev' into issue/OSOE-744
BenedekFarkas May 24, 2024
5201b25
Upgrading markdownlint-cli2-action to v16.0.0 (markdownlint v0.34.0)
BenedekFarkas May 24, 2024
574c7dc
Adding comments about keeping markdownlint and its configuration in s…
BenedekFarkas May 24, 2024
951a1a9
Apply suggestions from code review
BenedekFarkas May 28, 2024
fa92850
Fixing PowerShell syntax in the spelling workflow
BenedekFarkas May 28, 2024
63ebd42
Removing "Stub repo layout" step from the markdown-lint workflow to c…
BenedekFarkas May 28, 2024
d3c121d
Update lombiq.markdownlint.json
sarahelsaig May 28, 2024
6d3a1c5
Fix spacing in lombiq.markdownlint.json
sarahelsaig May 28, 2024
a2cdb52
Configuration to use markdown-lint automatic fixes
BenedekFarkas May 28, 2024
1c640e0
Braking some markdown syntax to be fixed
BenedekFarkas May 28, 2024
3e36dcc
Removing trailing spaces from the markdown-lint workflow
BenedekFarkas May 28, 2024
e843480
Testing the artifact upload of files fixed by markdown-lint
BenedekFarkas May 28, 2024
a5847ac
Moving custom logic from workflow to action
BenedekFarkas May 28, 2024
195c51e
Fixing syntax
BenedekFarkas May 28, 2024
a154978
Attempting to fix artifact upload
BenedekFarkas May 28, 2024
f213092
Updating error output
BenedekFarkas May 28, 2024
1b0d75f
Updating error output
BenedekFarkas May 28, 2024
3c0831d
Fixing error output
BenedekFarkas May 28, 2024
2695706
Merge remote-tracking branch 'origin/dev' into issue/OSOE-744
BenedekFarkas Jun 3, 2024
b930abb
Reverting Docs/Workflows.md to test artifact upload if there's only o…
BenedekFarkas Jun 3, 2024
3b2d3e4
Disabling some of the workflows for now
BenedekFarkas Jun 3, 2024
a7dc08a
Updating markdown-lint action to upload fixed files while keeping the…
BenedekFarkas Jun 3, 2024
766ce37
Revert "Reverting Docs/Workflows.md to test artifact upload if there'…
BenedekFarkas Jun 3, 2024
6f53788
Breaking .github/actions/spelling/advice.md too
BenedekFarkas Jun 3, 2024
7d0dca2
Committing files fixed automatically by markdown-lint
BenedekFarkas Jun 3, 2024
b935c7e
Revert "Disabling some of the workflows for now"
BenedekFarkas Jun 3, 2024
fb3e3d5
Reverting .github/actions/spelling/advice.md changes
BenedekFarkas Jun 3, 2024
5777a46
Fixing .github/actions/markdown-lint/action.yml whitespace
BenedekFarkas Jun 3, 2024
095986d
Updating comment about the markdown-lint action's parameters
BenedekFarkas Jun 3, 2024
25d094e
revert branch selectors
sarahelsaig Jun 5, 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
70 changes: 70 additions & 0 deletions .github/actions/markdown-lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Markdown Linting
description: >
Lints markdown files by wrapping the markdownlint-cli2 action
(https://github.com/DavidAnson/markdownlint-cli2-action).

# When updating defaults here also update them in the `markdown-lint` workflow.
inputs:
config:
description: Path to a file to use for the base configuration object (defaults to "lombiq.markdownlint.json").
default: 'lombiq.markdownlint.json'
required: false
fix:
description: Whether to fix issues automatically for the rules that support it (any truthy value enables).
default: ''
required: false
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved
globs:
description: Glob expression(s) of files to lint (newline-delimited).
default: '**/*.{md,markdown}'
required: false
separator:
description: String to use as a separator for the "globs" input (defaults to newline).
default: "\n"
required: false
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved

runs:
using: 'composite'
steps:
- name: Markdown Linting
# When upgrading, also update Lombiq.NodeJs.Extensions to use the corresponding version of the markdownlint package.
uses: DavidAnson/markdownlint-cli2-action@b4c9feab76d8025d1e83c653fa3990936df0e6c8 # v16.0.0
with:
config: ${{ inputs.config }}
fix: ${{ inputs.fix }}
globs: ${{ inputs.globs }}
separator: ${{ inputs.separator }}

- name: Setup Scripts
shell: pwsh
run: (Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH

- name: Copy files updated by markdown-lint automatic fixes
if: inputs.fix == 'true'
id: markdown-lint-fix-files
shell: pwsh
run: |
$artifactFolder = [System.Guid]::NewGuid()
$files = git diff --name-only '*.md' '*.markdown'
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved
$files | ForEach-Object {
$destination = "$artifactFolder/$PSItem"
New-Item -ItemType File -Path $destination -Force
Copy-Item -Path $PSItem -Destination $destination -Force
}

Set-GitHubOutput 'has-fixes' ($files.Length -gt 0).ToString().ToLower()
Set-GitHubOutput 'artifact-path' $artifactFolder

- name: Upload files fixed by markdown-lint
uses: Lombiq/GitHub-Actions/.github/actions/upload-artifact@dev
if: inputs.fix == 'true' && steps.markdown-lint-fix-files.outputs.has-fixes == 'true'
with:
name: markdown-lint-fixed-files
path: ${{ steps.markdown-lint-fix-files.outputs.artifact-path }}
retention-days: 1

- name: Fail workflow if markdown-lint fixes were made
if: inputs.fix == 'true' && steps.markdown-lint-fix-files.outputs.has-fixes == 'true'
shell: pwsh
run: |
Write-Output '::error::Some files were modified by markdown-lint and are available to download as artifacts.'
exit 1
9 changes: 9 additions & 0 deletions .github/actions/markdown-lint/lombiq.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// When updating, also update the same configuration file in Lombiq.NodeJs.Extensions.
{
"default": true,
"MD004": { "style": "dash" },
"MD013": false,
"MD033": { "allowed_elements": [ "kbd" ] },
"MD049": { "style": "underscore" },
"MD050": { "style": "asterisk" }
}
2 changes: 1 addition & 1 deletion .github/actions/spelling/advice.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Spell-checking configuration advice

What to do with false positives that aren't actually spelling mistakes? If the word is only used in a few cases, add the `#spell-check-ignore-line` comment to ignore the whole line. For a more common occurrence, add it to the appropriate dictionary file or define a pattern that matches it and similar cases.
_What to do with_ false positives that aren't actually spelling mistakes? If the word is only used in a few cases, add the `#spell-check-ignore-line` comment to ignore the whole line. For a more common occurrence, add it to the appropriate dictionary file or define a pattern that matches it and similar cases.

For further details, please read [our recommendations for maintaining the spell-checking configuration](https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/SpellCheckingConfiguration.md) carefully!
1 change: 1 addition & 0 deletions .github/actions/spelling/dictionaries/Lombiq.common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ linting
loglevel
lombiq
lucene
markdownlint
mediafield
mediatheme
mentoring
Expand Down
3 changes: 1 addition & 2 deletions .github/actions/yaml-lint/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: YAML Linting
description: Runs a linter on YAML files.


inputs:
config-file-path:
description: 'Path to the yamllint configuration file'
Expand All @@ -14,7 +13,7 @@ inputs:
default: '.'

runs:
using: "composite"
using: 'composite'
steps:
- name: Run yamllint
run: yamllint -c "${{ inputs.config-file-path }}" "${{ inputs.search-path }}"
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/markdown-lint-this-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Markdown Linting

# Runs for PRs opened for any branch, and pushes to the dev branch.
on:
pull_request:
push:
branches:
- dev

jobs:
markdown-linting:
name: Markdown Linting
uses: Lombiq/GitHub-Actions/.github/workflows/markdown-lint.yml@issue/OSOE-744
with:
globs: '**/*.{md,markdown};!License.md'
separator: ';'
fix: true
62 changes: 62 additions & 0 deletions .github/workflows/markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Markdown 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.

# When updating defaults here also update them in the `markdown-lint` action.
inputs:
cancel-workflow-on-failure:
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
config:
description: Path to a file to use for the base configuration object (defaults to "lombiq.markdownlint.json").
type: string
default: '.github/actions/markdown-lint/lombiq.markdownlint.json'
fix:
description: Whether to fix issues automatically for the rules that support it (any truthy value enables).
type: string
default: ''
globs:
description: Glob expression(s) of files to lint (newline-delimited).
type: string
default: '**/*.{md,markdown}'
separator:
description: String to use as a separator for the "globs" input (defaults to newline).
type: string
default: "\n"
timeout-minutes:
type: number
default: 1
description: Configuration for the timeout-minutes parameter of the workflow.

jobs:
markdown-linting:
name: Markdown Linting
runs-on: ubuntu-22.04
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev
with:
token: ${{ secrets.CHECKOUT_TOKEN }}

- name: Markdown Linting
uses: Lombiq/GitHub-Actions/.github/actions/markdown-lint@issue/OSOE-744
with:
config: ${{ inputs.config }}
fix: ${{ inputs.fix }}
globs: ${{ inputs.globs }}
separator: ${{ inputs.separator }}

- 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 }}
6 changes: 5 additions & 1 deletion .github/workflows/spelling-this-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ on:
jobs:
spelling:
name: Spelling
uses: Lombiq/GitHub-Actions/.github/workflows/spelling.yml@dev
uses: Lombiq/GitHub-Actions/.github/workflows/spelling.yml@issue/OSOE-744
with:
additional-dictionaries: |
cspell:companies/src/companies.txt
additional-configuration-source-prefixes: >
{
"lombiq-lgha": "https://raw.githubusercontent.com/Lombiq/GitHub-Actions/issue/OSOE-744/.github/actions/spelling/"
}
4 changes: 2 additions & 2 deletions .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ jobs:
run: |
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
Remove-Item .\.git\ -recurse -force
Remove-Item .\.git\ -Recurse -Force
git init .
git add .
git commit -m 'stub commit -- includes submodules'

- name: Check Spelling
id: check-spelling-action
uses: Lombiq/GitHub-Actions/.github/actions/spelling@dev
uses: Lombiq/GitHub-Actions/.github/actions/spelling@issue/OSOE-744
with:
merge-file-excludes: ${{ inputs.merge-file-excludes }}
merge-forbidden-patterns: ${{ inputs.merge-forbidden-patterns }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yaml-lint-this-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
yaml-linting:
name: YAML Linting
uses: Lombiq/GitHub-Actions/.github/workflows/yaml-lint.yml@dev
uses: Lombiq/GitHub-Actions/.github/workflows/yaml-lint.yml@issue/OSOE-744
with:
config-file-path: '.trunk/configs/.yamllint.yaml'
search-path: '.'
4 changes: 2 additions & 2 deletions .github/workflows/yaml-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
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"
default: 'true'
config-file-path:
description: 'Path to the yamllint configuration file'
required: true
Expand All @@ -43,7 +43,7 @@ jobs:
token: ${{ secrets.CHECKOUT_TOKEN }}

- name: YAML Linting
uses: Lombiq/GitHub-Actions/.github/actions/yaml-lint@dev
uses: Lombiq/GitHub-Actions/.github/actions/yaml-lint@issue/OSOE-744
with:
config-file-path: ${{ inputs.config-file-path }}
search-path: ${{ inputs.search-path }}
Expand Down
2 changes: 2 additions & 0 deletions Docs/Actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ In addition to the below short explanations, check out the inline documentation
- `cancel-workflow`: Cancels the current workflow run, i.e. all jobs. Useful if you want to cancel the rest of the workflow when one job fails. Suitable workflows in this project expose this functionality via the `cancel-workflow-on-failure` parameter.
- `check-merge-conflict`: Labels and comments on pull requests with merge conflicts.
- `create-jira-issues-for-community-activities`: Creates Jira issues for community activities happening on GitHub, like issues, discussions, and pull requests being opened. Pull requests are only taken into account if they're not already related to a Jira issue (by starting their title with a Jira issue key).
- `markdown-lint`: Checks for linting errors in markdown files, allowing for an optional configuration file to be used. Based on the [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2-action) action.
- `publish-nuget`: Publishes the content of the current directory as a NuGet package.
- `update-github-issue-and-pull-request`: Adds the Jira issue key prefix and link to pull requests as well as a Fixes reference to a GitHub issue, if a suitable one is found.
- `verify-submodule-pull-request`: Assuming that the current repository is a submodule in another repository, this action verifies that a pull request with a matching issue code has been opened there as well.
- `spelling`: Checks for spelling mistakes in a repository. Check out [this action's own documentation](SpellCheckingConfiguration.md) on how to use it and contribute to the configuration and dictionaries.
- `yaml-lint`: Checks for linting errors in YAML-files, allowing for an optional configuration file to be used.

## Azure hosting

Expand Down
3 changes: 2 additions & 1 deletion Docs/Workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ These features are designed to reduce resource usage (like paid GitHub Actions m
## Productivity

- [Create Jira issues for community activities](Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md)
- [Markdown linting](Workflows/Productivity/MarkdownLinting.md)
- [Post-pull request checks automation](Workflows/Productivity/PostPullRequestChecksAutomation.md)
- [Publish NuGet package](Workflows/Productivity/PublishNuGetPackage.md)
- [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)
- [YAML linting](Workflows/Productivity/YamlLinting.md)

## Azure hosting

Expand Down
16 changes: 16 additions & 0 deletions Docs/Workflows/Productivity/MarkdownLinting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Markdown Linting

This workflow uses [`markdownlint-cli2`](https://github.com/DavidAnson/markdownlint-cli2) through its wrapper action for linting markdown files according to an optional configuration file. Such a configuration file includes a set of rules that are checked against when linting the files and can be found in `../../../.github/actions/markdown-lint/lombiq.markdownlint.json` and is used by default.

You would typically consume the corresponding GHA workflow for markdown linting like this:

```yaml
...

jobs:
markdown-linting:
name: Markdown Linting
uses: Lombiq/GitHub-Actions/.github/workflows/markdown-lint.yml@dev
```

The list of input parameters specific to the behavior of `markdownlint` are the the same as its wrapper action and [described in its readme](https://github.com/DavidAnson/markdownlint-cli2-action?tab=readme-ov-file#inputs). The values are passed on directly, but the defaults are changed to use Lombiq's configuration file.
2 changes: 1 addition & 1 deletion Docs/Workflows/Productivity/YamlLinting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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`.
This workflow 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:

Expand Down
Loading