Skip to content

Commit

Permalink
added docusaurus docs (#37)
Browse files Browse the repository at this point in the history
* added docusaurus docs
* add pylint
* pylint rules
* missing vale files
* update commit message
  • Loading branch information
petercrocker authored Feb 1, 2025
1 parent dc46f8f commit d819e21
Show file tree
Hide file tree
Showing 41 changed files with 19,723 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .github/build-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

cd docs && npm install && npm run build
25 changes: 25 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
ci_config: &ci_config
- ".github/workflows/ci.yml"
- ".github/file-filters.yml"

github_workflows: &github_workflows
- ".github/workflows/*.yml"

doc_files: &doc_files
- "docs/**"
- package.json
- package-lock.json

python_all: &python_all
- "**/*.py"

yaml_all: &yaml_all
- "**/*.{yml,yaml}"

markdown_all: &markdown_all
- "**/*.{md,mdx}"

documentation_all:
- *doc_files
- *markdown_all
8 changes: 8 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"group/ci":
- changed-files:
- any-glob-to-any-file: [".github/**"]

"type/documentation":
- changed-files:
- any-glob-to-any-file: ["docs/**"]
171 changes: 147 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,115 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
VALE_VERSION: "3.7.1"

jobs:
lint:
files-changed:
name: Detect which file has changed
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
documentation: ${{ steps.changes.outputs.documentation_all }}
python: ${{ steps.changes.outputs.python_all }}
yaml: ${{ steps.changes.outputs.yaml_all }}
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: Check for file changes
uses: opsmill/[email protected]
id: changes
with:
token: ${{ github.token }}
filters: .github/file-filters.yml

python-lint:
if: needs.files-changed.outputs.python == 'true'
needs: ["files-changed"]
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version:
- "3.12"
poetry-version:
- "1.8.5"
timeout-minutes: 5
steps:
- name: "Check out repository code"
uses: "actions/checkout@v3"
- name: "Setup environment"
uses: "actions/checkout@v4"

- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v5"
with:
python-version: ${{ matrix.python-version }}
- name: "Install Poetry ${{ matrix.poetry-version }}"
uses: "snok/install-poetry@v1"
with:
version: ${{ matrix.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: "Setup Python environment"
run: |
pipx install poetry invoke
- name: "Install Linters"
run: "poetry install --only=dev"
- name: "Linting"
run: "poetry run invoke lint"
poetry config virtualenvs.create true --local
poetry env use ${{ matrix.python-version }}
- name: "Install dependencies"
run: "poetry install --no-interaction --no-ansi --with dev"

- name: "Linting: ruff check"
run: "poetry run ruff check ."
- name: "Linting: ruff format"
run: "poetry run ruff format --check --diff ."
- name: "Mypy Tests"
run: "poetry run mypy --show-error-codes nornir_infrahub"
- name: "Pylint Tests"
run: "poetry run pylint nornir_infrahub *.py"

yaml-lint:
if: needs.files-changed.outputs.yaml == 'true'
needs: ["files-changed"]
runs-on: "ubuntu-latest"
timeout-minutes: 5
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
with:
submodules: true
- name: "Setup environment"
run: "pip install yamllint==1.35.1"
- name: "Linting: yamllint"
run: "yamllint -s ."

python-tests:
if: needs.files-changed.outputs.python == 'true'
needs: ["files-changed"]
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
needs: ["lint"]
runs-on: "ubuntu-latest"
poetry-version:
- "1.8.5"
timeout-minutes: 30
steps:
- name: "Check out repository code"
uses: "actions/checkout@v3"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: python
uses: "actions/checkout@v4"
- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v5"
with:
python-version: ${{ matrix.python-version }}
- name: "Setup environment"
- name: "Install Poetry ${{ matrix.poetry-version }}"
uses: "snok/install-poetry@v1"
with:
version: ${{ matrix.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: "Setup Python environment"
run: |
pipx install poetry
env:
PIPX_DEFAULT_PYTHON: ${{ steps.python.outputs.python-path }}
- name: "Install Nornir Infrahub"
run: "poetry install --with=dev"
poetry config virtualenvs.create true --local
poetry env use ${{ matrix.python-version }}
- name: "Install dependencies"
run: "poetry install --no-interaction --no-ansi --with dev"
- name: "Pytest Tests"
run: "poetry run pytest -v tests/"

Expand All @@ -70,3 +138,58 @@ jobs:
# with:
# carryforward: "nornir-unit"
# parallel-finished: true

documentation:
defaults:
run:
working-directory: ./docs
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.files-changed.outputs.documentation == 'true'
needs: ["files-changed", "yaml-lint", "python-lint"]
runs-on: "ubuntu-22.04"
timeout-minutes: 5
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
with:
submodules: true
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: docs/package-lock.json
- name: "Install dependencies"
run: npm install
- name: "Setup Python environment"
run: "pip install invoke toml"
- name: "Build docs website"
run: "invoke docs"

validate-documentation-style:
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
needs: ["files-changed", "yaml-lint", "python-lint"]
runs-on: "ubuntu-22.04"
timeout-minutes: 5
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
with:
submodules: true

# The official GitHub Action for Vale doesn't work, installing manually instead:
# https://github.com/errata-ai/vale-action/issues/103
- name: Download Vale
run: |
curl -sL "https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz" -o vale.tar.gz
tar -xzf vale.tar.gz
env:
VALE_VERSION: ${{ env.VALE_VERSION }}
- name: "Validate documentation style"
run: ./vale $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \) )
38 changes: 38 additions & 0 deletions .github/workflows/sync-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# yamllint disable rule:truthy rule:truthy rule:line-length
name: Sync Docs Folders
on:
push:
branches:
- main
paths:
- 'docs/docs/**'
- 'docs/sidebars.ts'

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
path: source-repo

- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: opsmill/infrahub-docs
token: ${{ secrets.PAT_TOKEN }}
path: target-repo

- name: Sync folders
run: |
rm -rf target-repo/docs/docs-nornir/*
rm -f target-repo/docs/sidebars-nornir.ts
cp -r source-repo/docs/docs/* target-repo/docs/docs-nornir/
cp source-repo/docs/sidebars.ts target-repo/docs/sidebars-nornir.ts
cd target-repo
git config user.name github-actions
git config user.email [email protected]
git add .
if ! (git diff --quiet && git diff --staged --quiet); then git commit -m "Sync docs from nornir-infrahub repo" && git push; fi
16 changes: 16 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
default: true
MD007:
indent: 4 # sets indent size to 4 spaces
MD013: false # disables max line-length
MD024: false # disables 'no duplicate headings',
# which we use in tabs for instructions
MD025:
front_matter_title: "" # prevent collisions with h1s
# and frontmatter titles
MD029: false # allows manually creating ordered lists
MD033: false # allows inline html to override markdown styles
MD034: false # no-bare-urls
MD045: false # no alt text around images
MD047: false # single trailing newline
MD014: false # dollar signs used before commands
15 changes: 15 additions & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
StylesPath = .vale/styles

MinAlertLevel = warning

[formats]
mdx = md

[docs/**/*.md]
BasedOnStyles = Infrahub
;(import.*?\n) to ignore import statement in .mdx
;(```.*?```\n) to ignore code block in .mdx
BlockIgnores = (?s) *((import.*?\n)|(```.*?```\n))

[*]
BasedOnStyles = Infrahub
14 changes: 14 additions & 0 deletions .vale/styles/Infrahub/branded-terms-case-swap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
extends: substitution
message: Use '%s' instead of '%s'
level: error
ignorecase: false
action:
name: replace
swap:
(?i:[^/]Github): GitHub
(?i:gitpod): GitPod
(?i:[^/]Graphql): GraphQL
infrahub(?:\s|$): Infrahub
(?i:Openconfig): OpenConfig
opsmill(?:\s|$): OpsMill
8 changes: 8 additions & 0 deletions .vale/styles/Infrahub/colon-space.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: substitution
message: "Use a space after a colon, but not before"
level: warning
ignorecase: true
nonword: true
swap:
'(?<=\s):(?=\s+)': ': '
12 changes: 12 additions & 0 deletions .vale/styles/Infrahub/eg-ie.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
extends: substitution
message: "Instead of %s, use ',i.e.,' or 'for example:'."
level: warning
ignorecase: true
nonword: true
action:
name: replace
swap:
- e\.g\.: i.e.
- e\. g\.: i.e.
- i\. e\.: i.e.
8 changes: 8 additions & 0 deletions .vale/styles/Infrahub/oxford-comma.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: existence
message: "Use a comma before the last 'and' or 'or' in a list of items."
level: suggestion
scope: sentence
nonword: true
tokens:
- '(?:[^\s,]+,){1,} \w+ (?:and|or) \w+[.?!]'
Loading

0 comments on commit d819e21

Please sign in to comment.