From 3d98d6540301fb49288780692b600e766eabe3d3 Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Tue, 26 Sep 2023 08:33:41 +0200 Subject: [PATCH 1/3] Add additional common pre-commit-hooks I have these hooks enabled on many of my projects, but for some reason forgot them here which led to the issue described in https://github.com/zoni/obsidian-export/pull/181 This should help prevent that from happening again. --- .pre-commit-config.yaml | 8 +++++++- CONTRIBUTING.md | 2 +- README.md | 6 +++--- docs/.obsidian/config | 2 +- docs/.obsidian/workspace | 2 +- docs/.obsidian/workspaces.json | 2 +- docs/_edit-warning.md | 2 +- docs/usage-advanced.md | 2 +- docs/usage-basic.md | 4 ++-- tests/testdata/input/main-samples/bulb.svg | 2 +- tests/testdata/input/main-samples/section-ref-a.md | 2 +- .../same-filename-different-directories/dir2/Note.md | 2 +- 12 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3bf09f4..f87f283 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,9 +2,15 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 9136088a246768144165fcc3ecc3d31bb686920a # frozen: v3.3.0 + rev: 38b88246ccc552bffaaf54259d064beeee434539 # frozen: v4.0.1 hooks: + - id: check-case-conflict + - id: check-symlinks - id: check-yaml + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + exclude: '^(README.md|tests/testdata/expected/.*)$' - repo: local hooks: - id: rustfmt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e42eb3c..8b0b377 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,7 +39,7 @@ Code is formatted with [rustfmt](https://github.com/rust-lang/rustfmt) using the In addition, all default [clippy](https://github.com/rust-lang/rust-clippy) checks on the latest stable Rust compiler must also pass. Both of these are enforced through CI using GitHub actions. -> **💡 Tip: install pre-commit hooks** +> **💡 Tip: install pre-commit hooks** > > This codebase is set up with the [pre-commit framework](https://pre-commit.com/) to automatically run the appropriate checks locally whenever you commit. > Assuming you [have pre-commit installed](https://pre-commit.com/#install), all you need to do is run `pre-commit install` once to get this set up. diff --git a/README.md b/README.md index c3f29a5..2d27c75 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ WARNING: the docs directory. Instead of editing README.md, edit the corresponding Markdown files in the - docs directory and run generate.sh. + docs directory and run generate.sh. To add new sections, create new files under docs and add these to _combined.md @@ -58,7 +58,7 @@ If you built from source, upgrade by running `cargo install obsidian-export` aga The main interface of *obsidian-export* is the `obsidian-export` CLI command. As a text interface, this must be run from a terminal or Windows PowerShell. -It is assumed that you have basic familiarity with command-line interfaces and that you set up your `PATH` correctly if you installed with `cargo`. +It is assumed that you have basic familiarity with command-line interfaces and that you set up your `PATH` correctly if you installed with `cargo`. Running `obsidian-export --version` should print a version number rather than giving some kind of error. > @@ -101,7 +101,7 @@ Using the `--start-at` argument, you can export just a subset of your vault. Given the following vault structure: ```` -my-obsidian-vault +my-obsidian-vault ├── Notes/ ├── Books/ └── People/ diff --git a/docs/.obsidian/config b/docs/.obsidian/config index dc8a0e8..d102c54 100644 --- a/docs/.obsidian/config +++ b/docs/.obsidian/config @@ -1 +1 @@ -{"theme":"moonstone","pluginEnabledStatus":{"Open in default app":true,"file-explorer":true,"global-search":true,"switcher":true,"graph":true,"backlink":true,"command-palette":true,"markdown-importer":false,"word-count":true,"tag-pane":false,"daily-notes":false,"slides":false,"open-with-default-app":true,"random-note":false,"page-preview":true,"zk-prefixer":false,"starred":false,"outline":true,"templates":false,"workspaces":false},"isSidebarCollapsed":false,"isRightSidedockCollapsed":true,"lastOpenSidebarTab":"File explorer","useTab":false,"showLineNumber":true,"foldHeading":true,"foldIndent":true,"vimMode":true,"newFileLocation":"current","hotkeys":{"switcher:open":[{"modifiers":["Mod"],"key":" "}],"app:go-back":[{"modifiers":["Mod"],"key":"o"}],"app:go-forward":[{"modifiers":["Mod"],"key":"i"}],"editor:toggle-bold":[{"modifiers":["Mod"],"key":"8"}],"editor:toggle-italics":[{"modifiers":["Mod"],"key":"-"}],"editor:toggle-highlight":[{"modifiers":["Mod"],"key":"="}],"editor:delete-paragraph":[],"editor:focus-top":[{"modifiers":["Alt"],"key":"k"}],"editor:focus-bottom":[{"modifiers":["Alt"],"key":"j"}],"editor:focus-left":[{"modifiers":["Alt"],"key":"h"}],"editor:focus-right":[{"modifiers":["Alt"],"key":"l"}],"workspace:split-horizontal":[{"modifiers":["Alt"],"key":"s"}],"workspace:split-vertical":[{"modifiers":["Alt"],"key":"v"}],"workspace:toggle-pin":[{"modifiers":["Alt"],"key":"t"}],"graph:open":[],"backlink:open-backlinks":[{"modifiers":["Alt"],"key":"b"}],"workspace:close":[{"modifiers":["Alt"],"key":"w"}],"editor:swap-line-up":[{"modifiers":["Mod","Shift"],"key":"K"}],"editor:swap-line-down":[{"modifiers":["Mod","Shift"],"key":"J"}],"outline:open":[{"modifiers":["Alt"],"key":"o"}],"app:toggle-left-sidebar":[{"modifiers":["Alt"],"key":","}],"app:toggle-right-sidebar":[{"modifiers":["Alt"],"key":"."}],"graph:open-local":[{"modifiers":["Alt"],"key":"g"}]},"lastOpenRightSidedockTab":"Backlinks","sideDockWidth":{"left":300,"right":301},"fileSortOrder":"alphabetical","promptDelete":false,"readableLineLength":true,"alwaysUpdateLinks":true,"spellcheck":true,"strictLineBreaks":true,"spellcheckDictionary":[],"autoPairMarkdown":false,"autoPairBrackets":false,"showFrontmatter":true,"enabledPlugins":["todoist-sync-plugin"],"defaultViewMode":"preview","obsidianCss":false} \ No newline at end of file +{"theme":"moonstone","pluginEnabledStatus":{"Open in default app":true,"file-explorer":true,"global-search":true,"switcher":true,"graph":true,"backlink":true,"command-palette":true,"markdown-importer":false,"word-count":true,"tag-pane":false,"daily-notes":false,"slides":false,"open-with-default-app":true,"random-note":false,"page-preview":true,"zk-prefixer":false,"starred":false,"outline":true,"templates":false,"workspaces":false},"isSidebarCollapsed":false,"isRightSidedockCollapsed":true,"lastOpenSidebarTab":"File explorer","useTab":false,"showLineNumber":true,"foldHeading":true,"foldIndent":true,"vimMode":true,"newFileLocation":"current","hotkeys":{"switcher:open":[{"modifiers":["Mod"],"key":" "}],"app:go-back":[{"modifiers":["Mod"],"key":"o"}],"app:go-forward":[{"modifiers":["Mod"],"key":"i"}],"editor:toggle-bold":[{"modifiers":["Mod"],"key":"8"}],"editor:toggle-italics":[{"modifiers":["Mod"],"key":"-"}],"editor:toggle-highlight":[{"modifiers":["Mod"],"key":"="}],"editor:delete-paragraph":[],"editor:focus-top":[{"modifiers":["Alt"],"key":"k"}],"editor:focus-bottom":[{"modifiers":["Alt"],"key":"j"}],"editor:focus-left":[{"modifiers":["Alt"],"key":"h"}],"editor:focus-right":[{"modifiers":["Alt"],"key":"l"}],"workspace:split-horizontal":[{"modifiers":["Alt"],"key":"s"}],"workspace:split-vertical":[{"modifiers":["Alt"],"key":"v"}],"workspace:toggle-pin":[{"modifiers":["Alt"],"key":"t"}],"graph:open":[],"backlink:open-backlinks":[{"modifiers":["Alt"],"key":"b"}],"workspace:close":[{"modifiers":["Alt"],"key":"w"}],"editor:swap-line-up":[{"modifiers":["Mod","Shift"],"key":"K"}],"editor:swap-line-down":[{"modifiers":["Mod","Shift"],"key":"J"}],"outline:open":[{"modifiers":["Alt"],"key":"o"}],"app:toggle-left-sidebar":[{"modifiers":["Alt"],"key":","}],"app:toggle-right-sidebar":[{"modifiers":["Alt"],"key":"."}],"graph:open-local":[{"modifiers":["Alt"],"key":"g"}]},"lastOpenRightSidedockTab":"Backlinks","sideDockWidth":{"left":300,"right":301},"fileSortOrder":"alphabetical","promptDelete":false,"readableLineLength":true,"alwaysUpdateLinks":true,"spellcheck":true,"strictLineBreaks":true,"spellcheckDictionary":[],"autoPairMarkdown":false,"autoPairBrackets":false,"showFrontmatter":true,"enabledPlugins":["todoist-sync-plugin"],"defaultViewMode":"preview","obsidianCss":false} diff --git a/docs/.obsidian/workspace b/docs/.obsidian/workspace index 775c383..cd657c0 100644 --- a/docs/.obsidian/workspace +++ b/docs/.obsidian/workspace @@ -107,4 +107,4 @@ "Usage.md", "License.md" ] -} \ No newline at end of file +} diff --git a/docs/.obsidian/workspaces.json b/docs/.obsidian/workspaces.json index 9e26dfe..0967ef4 100644 --- a/docs/.obsidian/workspaces.json +++ b/docs/.obsidian/workspaces.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/docs/_edit-warning.md b/docs/_edit-warning.md index c60d430..ed36171 100644 --- a/docs/_edit-warning.md +++ b/docs/_edit-warning.md @@ -6,7 +6,7 @@ WARNING: the docs directory. Instead of editing README.md, edit the corresponding Markdown files in the - docs directory and run generate.sh. + docs directory and run generate.sh. To add new sections, create new files under docs and add these to _combined.md diff --git a/docs/usage-advanced.md b/docs/usage-advanced.md index 6e1817d..de168f2 100644 --- a/docs/usage-advanced.md +++ b/docs/usage-advanced.md @@ -112,4 +112,4 @@ With these hooks in place, links to both notes as well as file attachments shoul [gitignore]: https://git-scm.com/docs/gitignore [hugo-relative-linking]: https://notes.nick.groenen.me/notes/relative-linking-in-hugo/ [hugo]: https://gohugo.io -[markdown render hooks]: https://gohugo.io/getting-started/configuration-markup#markdown-render-hooks +[markdown render hooks]: https://gohugo.io/getting-started/configuration-markup#markdown-render-hooks diff --git a/docs/usage-basic.md b/docs/usage-basic.md index 7cae68d..19c7798 100644 --- a/docs/usage-basic.md +++ b/docs/usage-basic.md @@ -3,7 +3,7 @@ The main interface of _obsidian-export_ is the `obsidian-export` CLI command. As a text interface, this must be run from a terminal or Windows PowerShell. -It is assumed that you have basic familiarity with command-line interfaces and that you set up your `PATH` correctly if you installed with `cargo`. +It is assumed that you have basic familiarity with command-line interfaces and that you set up your `PATH` correctly if you installed with `cargo`. Running `obsidian-export --version` should print a version number rather than giving some kind of error. > If you downloaded a pre-built binary and didn't put it a location referenced by `PATH` (for example, you put it in `Downloads`), you will need to provide the full path to the binary instead. @@ -44,7 +44,7 @@ Using the `--start-at` argument, you can export just a subset of your vault. Given the following vault structure: ``` -my-obsidian-vault +my-obsidian-vault ├── Notes/ ├── Books/ └── People/ diff --git a/tests/testdata/input/main-samples/bulb.svg b/tests/testdata/input/main-samples/bulb.svg index 3eb07fd..ecbfb2e 100644 --- a/tests/testdata/input/main-samples/bulb.svg +++ b/tests/testdata/input/main-samples/bulb.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/testdata/input/main-samples/section-ref-a.md b/tests/testdata/input/main-samples/section-ref-a.md index 0c1840b..e2f3955 100644 --- a/tests/testdata/input/main-samples/section-ref-a.md +++ b/tests/testdata/input/main-samples/section-ref-a.md @@ -4,4 +4,4 @@ ## This is a header -This is a block ^dda637 \ No newline at end of file +This is a block ^dda637 diff --git a/tests/testdata/input/same-filename-different-directories/dir2/Note.md b/tests/testdata/input/same-filename-different-directories/dir2/Note.md index 0a2138a..8709600 100644 --- a/tests/testdata/input/same-filename-different-directories/dir2/Note.md +++ b/tests/testdata/input/same-filename-different-directories/dir2/Note.md @@ -1 +1 @@ -Note in dir2. \ No newline at end of file +Note in dir2. From 5985ad70d68bdf0c2599f4f493762ea3ad5836e6 Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Tue, 26 Sep 2023 09:06:19 +0200 Subject: [PATCH 2/3] Run pre-commit on GitHub Actions --- .github/workflows/test.yml | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 898556d..8c5e377 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,6 +58,47 @@ jobs: - run: cargo check - run: cargo clippy -- -D warnings + + pre-commit: + name: Run pre-commit + runs-on: ubuntu-latest + needs: build + env: + # These hooks are expensive and already run as dedicated jobs above + SKIP: "tests,clippy" + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: "cargo-lint-${{ needs.build.outputs.rustc_cache_key }}-${{ hashFiles('**/Cargo.lock') }}" + restore-keys: | + cargo-lint-${{ env.RUSTC_CACHEKEY }} + cargo-base-${{ env.RUSTC_CACHEKEY }} + fail-on-cache-miss: true + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + + - uses: actions/setup-python@v3 + - name: set PYVERSION + run: echo "PYVERSION=$(python --version | tr ' ' '-')" >> $GITHUB_ENV + - uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + # Changes to pre-commit-config.yaml may require the installation of + # new binaries/scripts. When a cache hit occurs, changes to the cache + # aren't persisted at the end of the run, so making the key dependent + # on the configuration file ensures we always persist a complete cache. + key: pre-commit-${{ env.PYVERSION }}-${{ hashFiles('.pre-commit-config.yaml') }} + + - run: pip install pre-commit + - run: pre-commit run --all --color=always --show-diff-on-failure + test-linux: name: Test on Linux runs-on: ubuntu-latest From 4c74371b9e0fe54bacc8f9fc1166c3eeec4a0a04 Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Tue, 26 Sep 2023 09:08:56 +0200 Subject: [PATCH 3/3] Use /bin/bash when generating README set -o pipefail is a bashism that not all shells support. Notably, this fails with the default /bin/sh on GitHub Actions Linux runners --- docs/generate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/generate.sh b/docs/generate.sh index 5cb0a02..b47f9c3 100755 --- a/docs/generate.sh +++ b/docs/generate.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -euo pipefail