Verify formatting of code snippets in CI

pull/1687/head
Oleksandr Redko 2025-01-20 19:41:28 +02:00
parent 3cf0926564
commit dfda68b86f
3 changed files with 34 additions and 0 deletions

10
.ci.readme.fmt.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# Verify that the code snippets in README.md are formatted.
# The tool https://github.com/hougesen/mdsf is used.
if [ -n "$(mdsf verify --config .mdsf.json README.md 2>&1)" ]; then
echo "Go code in the README.md is not formatted."
echo "Did you forget to run 'mdsf format --config .mdsf.json README.md'?"
exit 1
fi

View File

@ -37,3 +37,15 @@ jobs:
with:
go-version: ${{ matrix.go_version }}
- run: go test -v -race ./...
format:
name: Check formatting of code snippets in markdown files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable
- run: npm install -g mdsf-cli
- run: ./.ci.gofmt.sh
- run: ./.ci.readme.fmt.sh

12
.mdsf.json Normal file
View File

@ -0,0 +1,12 @@
{
"$schema": "https://raw.githubusercontent.com/hougesen/mdsf/main/schemas/v0.4.1/mdsf.schema.json",
"format_finished_document": false,
"languages": {
"go": [
[
"gofmt",
"goimports"
]
]
}
}