-
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-744: Add wrapper for the markdownlint-cli2 action
- Loading branch information
Showing
13 changed files
with
189 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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. These parameters are passed on directly | ||
# to the markdownlint-cli2 action, see: https://github.com/DavidAnson/markdownlint-cli2-action/blob/main/action.yml. | ||
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 | ||
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 | ||
|
||
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' | ||
$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 |
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,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" } | ||
} |
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 |
---|---|---|
|
@@ -71,6 +71,7 @@ linting | |
loglevel | ||
lombiq | ||
lucene | ||
markdownlint | ||
mediafield | ||
mediatheme | ||
mentoring | ||
|
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,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@dev | ||
with: | ||
globs: '**/*.{md,markdown};!License.md' | ||
separator: ';' | ||
fix: true |
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,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@dev | ||
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 }} |
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
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 @@ | ||
# 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. |
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