Skip to content

Commit

Permalink
Add CI for docs and fix dash (#44)
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
  • Loading branch information
saswatamcode authored Jun 15, 2021
1 parent 06888e7 commit 2e71ff4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: docs

on:
push:
branches:
- main
tags:
pull_request:

jobs:
check:
runs-on: ubuntu-latest
name: Documentation check
env:
GOBIN: /tmp/.bin
steps:
- name: Checkout code into the Go module directory.
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.15.x

- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Check docs
run: make check-docs
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ docs: build ## Generates config snippets and doc formatting.
@echo ">> generating docs $(PATH)"
@PATH=$(GOBIN) mdox fmt -l *.md

.PHONY: check-docs
check-docs: build ## Checks docs for discrepancies in formatting and links.
@echo ">> checking formatting and links $(PATH)"
@PATH=$(GOBIN) mdox fmt --check -l *.md

.PHONY: format
format: ## Formats Go code.
format: $(GOIMPORTS)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ Flags:
--links.validate.config-file=<file-path>
Path to YAML file for skipping link check, with
spec defined in
github.com/bwplotka/mdox/pkg/linktransformer.Config
github.com/bwplotka/mdox/pkg/linktransformer.ValidatorConfig
--links.validate.config=<content>
Alternative to 'links.validate.config-file'
flag (mutually exclusive). Content of YAML file
for skipping link check, with spec defined in
github.com/bwplotka/mdox/pkg/linktransformer.Config
github.com/bwplotka/mdox/pkg/linktransformer.ValidatorConfig
Args:
<files> Markdown file(s) to process.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ This directive runs executable with arguments and put its stderr and stdout outp
"Absolute path links will be converted to relative links to anchor dir as well.").Regexp()
// TODO(bwplotka): Add cache in file?
linksValidateEnabled := cmd.Flag("links.validate", "If true, all links will be validated").Short('l').Bool()
linksValidateConfig := extflag.RegisterPathOrContent(cmd, "links.validate.config", "YAML file for skipping link check, with spec defined in github.com/bwplotka/mdox/pkg/linktransformer.Config", extflag.WithEnvSubstitution())
linksValidateConfig := extflag.RegisterPathOrContent(cmd, "links.validate.config", "YAML file for skipping link check, with spec defined in github.com/bwplotka/mdox/pkg/linktransformer.ValidatorConfig", extflag.WithEnvSubstitution())

cmd.Run(func(ctx context.Context, logger log.Logger) (err error) {
var opts []mdformatter.Option
Expand Down
2 changes: 1 addition & 1 deletion pkg/mdformatter/linktransformer/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func toHeaderID(header []byte) string {
switch h {
case '{':
return string(id)
case ' ':
case ' ', '-':
id = append(id, '-')
default:
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/mdformatter/linktransformer/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ func TestValidator_TransformDestination(t *testing.T) {
testutil.Equals(t, 0, len(diff), diff.String())
})

t.Run("check valid local links with dash", func(t *testing.T) {
testFile := filepath.Join(tmpDir, "repo", "docs", "test", "valid-local-links-with-dash.md")
testutil.Ok(t, ioutil.WriteFile(testFile, []byte(`# Expose UI on a sub-path
[1](#expose-ui-on-a-sub-path)
# Run-time deduplication of HA groups
[2](#run-time-deduplication-of-ha-groups)
`), os.ModePerm))

diff, err := mdformatter.IsFormatted(context.TODO(), logger, []string{testFile})
testutil.Ok(t, err)
testutil.Equals(t, 0, len(diff), diff.String())

diff, err = mdformatter.IsFormatted(context.TODO(), logger, []string{testFile}, mdformatter.WithLinkTransformer(
MustNewValidator(logger, []byte(""), anchorDir),
))
testutil.Ok(t, err)
testutil.Equals(t, 0, len(diff), diff.String())
})

t.Run("check invalid local links", func(t *testing.T) {
testFile := filepath.Join(tmpDir, "repo", "docs", "test", "invalid-local-links.md")
filePath := "/repo/docs/test/invalid-local-links.md"
Expand Down

0 comments on commit 2e71ff4

Please sign in to comment.