Skip to content

Commit

Permalink
Add CI workflow to check Markdown files for problems
Browse files Browse the repository at this point in the history
On every push and pull request that affects relevant files, and periodically, check the repository's Markdown files for
problems:

- Use markdownlint to check for common problems and formatting.
- Use markdown-link-check to check for broken links.

The Arduino tooling Markdown style is defined by the `.markdownlint.yml` file.

In the event the repository contains externally maintained Markdown files, markdownlint can be configured to ignore them
via a `.markdownlintignore` file:
https://github.com/igorshubovych/markdownlint-cli#ignoring-files

markdown-link-check is configured via the `.markdown-link-check.json` file:
https://github.com/tcort/markdown-link-check#config-file-format
  • Loading branch information
per1234 committed Mar 25, 2023
1 parent 9e2f592 commit 62e80d3
Show file tree
Hide file tree
Showing 8 changed files with 1,311 additions and 2 deletions.
112 changes: 112 additions & 0 deletions .github/workflows/check-markdown-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-markdown-task.md
name: Check Markdown

env:
# See: https://github.com/actions/setup-node/#readme
NODE_VERSION: 16.x

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-markdown-task.ya?ml"
- ".markdown-link-check.json"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**/.markdownlint*"
- "**.mdx?"
- "**.mkdn"
- "**.mdown"
- "**.markdown"
pull_request:
paths:
- ".github/workflows/check-markdown-task.ya?ml"
- ".markdown-link-check.json"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
- "**/.markdownlint*"
- "**.mdx?"
- "**.mkdn"
- "**.mdown"
- "**.markdown"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by external changes.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi
echo "result=$RESULT" >> $GITHUB_OUTPUT
lint:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Initialize markdownlint-cli problem matcher
uses: xt0rted/markdownlint-problem-matcher@v2

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Lint
run: task markdown:lint

links:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check links
run: task --silent markdown:check-links
13 changes: 13 additions & 0 deletions .markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"httpHeaders": [
{
"urls": ["https://docs.github.com/"],
"headers": {
"Accept-Encoding": "gzip, deflate, br"
}
}
],
"retryOn429": true,
"retryCount": 3,
"aliveStatusCodes": [200, 206]
}
62 changes: 62 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown/.markdownlint.yml
# See: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
# The code style defined in this file is the official standardized style to be used in all Arduino projects and should
# not be modified.
# Note: Rules disabled solely because they are redundant to Prettier are marked with a "Prettier" comment.

default: false
MD001: false
MD002: false
MD003: false # Prettier
MD004: false # Prettier
MD005: false # Prettier
MD006: false # Prettier
MD007: false # Prettier
MD008: false # Prettier
MD009:
br_spaces: 0
strict: true
list_item_empty_lines: false # Prettier
MD010: false # Prettier
MD011: true
MD012: false # Prettier
MD013: false
MD014: false
MD018: true
MD019: false # Prettier
MD020: true
MD021: false # Prettier
MD022: false # Prettier
MD023: false # Prettier
MD024: false
MD025:
level: 1
front_matter_title: '^\s*"?title"?\s*[:=]'
MD026: false
MD027: false # Prettier
MD028: false
MD029:
style: one
MD030:
ul_single: 1
ol_single: 1
ul_multi: 1
ol_multi: 1
MD031: false # Prettier
MD032: false # Prettier
MD033: false
MD034: false
MD035: false # Prettier
MD036: false
MD037: true
MD038: true
MD039: true
MD040: false
MD041: false
MD042: true
MD043: false
MD044: false
MD045: true
MD046:
style: fenced
MD047: false # Prettier
4 changes: 4 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown/.markdownlintignore
.licenses/
__pycache__/
node_modules/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Check Files status](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-files-task.yml)
[![Check General Formatting status](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-general-formatting-task.yml)
[![Check License status](https://github.com/arduino/compile-sketches/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-license.ym
[![Check Markdown status](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-markdown-task.yml)
[![Check Python status](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/check-python-task.yml)
[![Spell Check status](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/spell-check-task.yml)
[![Sync Labels status](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/compile-sketches/actions/workflows/sync-labels-npm.yml)
Expand Down
83 changes: 83 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ tasks:
- task: action:validate
- task: general:check-formatting
- task: general:check-spelling
- task: markdown:check-links
- task: markdown:lint
- task: python:lint
- task: python:test

fix:
desc: Make automated corrections to the project's files
deps:
- task: general:correct-spelling
- task: markdown:fix
- task: python:format

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-action-metadata-task/Taskfile.yml
Expand All @@ -42,6 +45,11 @@ tasks:
-s "{{.ACTION_METADATA_SCHEMA_PATH}}" \
-d "action.yml"
docs:generate:
desc: Create all generated documentation content
# This is an "umbrella" task used to call any documentation generation processes the project has.
# It can be left empty if there are none.

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-files-task/Taskfile.yml
general:check-filenames:
desc: Check for non-portable filenames
Expand Down Expand Up @@ -171,6 +179,81 @@ tasks:
cmds:
- poetry run codespell --write-changes

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:check-links:
desc: Check for broken links
deps:
- task: docs:generate
- task: npm:install-deps
cmds:
- |
if [[ "{{.OS}}" == "Windows_NT" ]]; then
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
# so the Windows user is required to have markdown-link-check installed and in PATH.
if ! which markdown-link-check &>/dev/null; then
echo "markdown-link-check not found or not in PATH."
echo "Please install: https://github.com/tcort/markdown-link-check#readme"
exit 1
fi
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
# exit status, but it's better to check all links before exiting.
set +o errexit
STATUS=0
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
# \ characters special treatment on Windows in an attempt to support them as path separators.
for file in $(
find . \
-type d -name '.git' -prune -o \
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-regex ".*[.]md" -print
); do
markdown-link-check \
--quiet \
--config "./.markdown-link-check.json" \
"$file"
STATUS=$(( $STATUS + $? ))
done
exit $STATUS
else
npx --package=markdown-link-check --call='
STATUS=0
for file in $(
find . \
-type d -name '.git' -prune -o \
-type d -name '.licenses' -prune -o \
-type d -name '__pycache__' -prune -o \
-type d -name 'node_modules' -prune -o \
-regex ".*[.]md" -print
); do
markdown-link-check \
--quiet \
--config "./.markdown-link-check.json" \
"$file"
STATUS=$(( $STATUS + $? ))
done
exit $STATUS
'
fi
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:fix:
desc: Automatically correct linting violations in Markdown files where possible
deps:
- task: npm:install-deps
cmds:
- npx markdownlint-cli --fix "**/*.md"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
markdown:lint:
desc: Check for problems in Markdown files
deps:
- task: npm:install-deps
cmds:
- npx markdownlint-cli "**/*.md"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
npm:install-deps:
desc: Install dependencies managed by npm
Expand Down
Loading

0 comments on commit 62e80d3

Please sign in to comment.