Skip to content

Commit

Permalink
Verify formatting of code snippets in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Jan 20, 2025
1 parent 3cf0926 commit f8cdd56
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .ci.readme.fmt.sh
Original file line number Diff line number Diff line change
@@ -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 README.md'?"
exit 1
fi
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go_version }}
- uses: actions/setup-node@v4
- run: ./.ci.gogenerate.sh
- run: ./.ci.gofmt.sh
- run: ./.ci.govet.sh
Expand All @@ -37,3 +38,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 changes: 12 additions & 0 deletions .mdsf.json
Original file line number Diff line number Diff line change
@@ -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"
]
]
}
}

0 comments on commit f8cdd56

Please sign in to comment.