Skip to content

Commit d819e21

Browse files
authored
added docusaurus docs (#37)
* added docusaurus docs * add pylint * pylint rules * missing vale files * update commit message
1 parent dc46f8f commit d819e21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+19723
-50
lines changed

Diff for: .github/build-docs.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cd docs && npm install && npm run build

Diff for: .github/file-filters.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
ci_config: &ci_config
3+
- ".github/workflows/ci.yml"
4+
- ".github/file-filters.yml"
5+
6+
github_workflows: &github_workflows
7+
- ".github/workflows/*.yml"
8+
9+
doc_files: &doc_files
10+
- "docs/**"
11+
- package.json
12+
- package-lock.json
13+
14+
python_all: &python_all
15+
- "**/*.py"
16+
17+
yaml_all: &yaml_all
18+
- "**/*.{yml,yaml}"
19+
20+
markdown_all: &markdown_all
21+
- "**/*.{md,mdx}"
22+
23+
documentation_all:
24+
- *doc_files
25+
- *markdown_all

Diff for: .github/labeler.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"group/ci":
3+
- changed-files:
4+
- any-glob-to-any-file: [".github/**"]
5+
6+
"type/documentation":
7+
- changed-files:
8+
- any-glob-to-any-file: ["docs/**"]

Diff for: .github/workflows/ci.yml

+147-24
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,115 @@ concurrency:
1313
group: ${{ github.workflow }}-${{ github.ref }}
1414
cancel-in-progress: true
1515

16+
env:
17+
VALE_VERSION: "3.7.1"
18+
1619
jobs:
17-
lint:
20+
files-changed:
21+
name: Detect which file has changed
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 5
24+
outputs:
25+
documentation: ${{ steps.changes.outputs.documentation_all }}
26+
python: ${{ steps.changes.outputs.python_all }}
27+
yaml: ${{ steps.changes.outputs.yaml_all }}
28+
steps:
29+
- name: "Check out repository code"
30+
uses: "actions/checkout@v4"
31+
- name: Check for file changes
32+
uses: opsmill/[email protected]
33+
id: changes
34+
with:
35+
token: ${{ github.token }}
36+
filters: .github/file-filters.yml
37+
38+
python-lint:
39+
if: needs.files-changed.outputs.python == 'true'
40+
needs: ["files-changed"]
1841
runs-on: "ubuntu-latest"
42+
strategy:
43+
matrix:
44+
python-version:
45+
- "3.12"
46+
poetry-version:
47+
- "1.8.5"
1948
timeout-minutes: 5
2049
steps:
2150
- name: "Check out repository code"
22-
uses: "actions/checkout@v3"
23-
- name: "Setup environment"
51+
uses: "actions/checkout@v4"
52+
53+
- name: "Set up Python ${{ matrix.python-version }}"
54+
uses: "actions/setup-python@v5"
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
- name: "Install Poetry ${{ matrix.poetry-version }}"
58+
uses: "snok/install-poetry@v1"
59+
with:
60+
version: ${{ matrix.poetry-version }}
61+
virtualenvs-create: true
62+
virtualenvs-in-project: true
63+
installer-parallel: true
64+
- name: "Setup Python environment"
2465
run: |
25-
pipx install poetry invoke
26-
- name: "Install Linters"
27-
run: "poetry install --only=dev"
28-
- name: "Linting"
29-
run: "poetry run invoke lint"
66+
poetry config virtualenvs.create true --local
67+
poetry env use ${{ matrix.python-version }}
68+
- name: "Install dependencies"
69+
run: "poetry install --no-interaction --no-ansi --with dev"
70+
71+
- name: "Linting: ruff check"
72+
run: "poetry run ruff check ."
73+
- name: "Linting: ruff format"
74+
run: "poetry run ruff format --check --diff ."
75+
- name: "Mypy Tests"
76+
run: "poetry run mypy --show-error-codes nornir_infrahub"
77+
- name: "Pylint Tests"
78+
run: "poetry run pylint nornir_infrahub *.py"
79+
80+
yaml-lint:
81+
if: needs.files-changed.outputs.yaml == 'true'
82+
needs: ["files-changed"]
83+
runs-on: "ubuntu-latest"
84+
timeout-minutes: 5
85+
steps:
86+
- name: "Check out repository code"
87+
uses: "actions/checkout@v4"
88+
with:
89+
submodules: true
90+
- name: "Setup environment"
91+
run: "pip install yamllint==1.35.1"
92+
- name: "Linting: yamllint"
93+
run: "yamllint -s ."
3094

3195
python-tests:
96+
if: needs.files-changed.outputs.python == 'true'
97+
needs: ["files-changed"]
98+
runs-on: "ubuntu-latest"
3299
strategy:
33100
matrix:
34101
python-version: ["3.9", "3.10", "3.11", "3.12"]
35-
if: |
36-
always() && !cancelled() &&
37-
!contains(needs.*.result, 'failure') &&
38-
!contains(needs.*.result, 'cancelled')
39-
needs: ["lint"]
40-
runs-on: "ubuntu-latest"
102+
poetry-version:
103+
- "1.8.5"
41104
timeout-minutes: 30
42105
steps:
43106
- name: "Check out repository code"
44-
uses: "actions/checkout@v3"
45-
- name: Set up Python ${{ matrix.python-version }}
46-
uses: actions/setup-python@v5
47-
id: python
107+
uses: "actions/checkout@v4"
108+
- name: "Set up Python ${{ matrix.python-version }}"
109+
uses: "actions/setup-python@v5"
48110
with:
49111
python-version: ${{ matrix.python-version }}
50-
- name: "Setup environment"
112+
- name: "Install Poetry ${{ matrix.poetry-version }}"
113+
uses: "snok/install-poetry@v1"
114+
with:
115+
version: ${{ matrix.poetry-version }}
116+
virtualenvs-create: true
117+
virtualenvs-in-project: true
118+
installer-parallel: true
119+
- name: "Setup Python environment"
51120
run: |
52-
pipx install poetry
53-
env:
54-
PIPX_DEFAULT_PYTHON: ${{ steps.python.outputs.python-path }}
55-
- name: "Install Nornir Infrahub"
56-
run: "poetry install --with=dev"
121+
poetry config virtualenvs.create true --local
122+
poetry env use ${{ matrix.python-version }}
123+
- name: "Install dependencies"
124+
run: "poetry install --no-interaction --no-ansi --with dev"
57125
- name: "Pytest Tests"
58126
run: "poetry run pytest -v tests/"
59127

@@ -70,3 +138,58 @@ jobs:
70138
# with:
71139
# carryforward: "nornir-unit"
72140
# parallel-finished: true
141+
142+
documentation:
143+
defaults:
144+
run:
145+
working-directory: ./docs
146+
if: |
147+
always() && !cancelled() &&
148+
!contains(needs.*.result, 'failure') &&
149+
!contains(needs.*.result, 'cancelled') &&
150+
needs.files-changed.outputs.documentation == 'true'
151+
needs: ["files-changed", "yaml-lint", "python-lint"]
152+
runs-on: "ubuntu-22.04"
153+
timeout-minutes: 5
154+
steps:
155+
- name: "Check out repository code"
156+
uses: "actions/checkout@v4"
157+
with:
158+
submodules: true
159+
- name: Install NodeJS
160+
uses: actions/setup-node@v4
161+
with:
162+
node-version: 20
163+
cache: 'npm'
164+
cache-dependency-path: docs/package-lock.json
165+
- name: "Install dependencies"
166+
run: npm install
167+
- name: "Setup Python environment"
168+
run: "pip install invoke toml"
169+
- name: "Build docs website"
170+
run: "invoke docs"
171+
172+
validate-documentation-style:
173+
if: |
174+
always() && !cancelled() &&
175+
!contains(needs.*.result, 'failure') &&
176+
!contains(needs.*.result, 'cancelled')
177+
needs: ["files-changed", "yaml-lint", "python-lint"]
178+
runs-on: "ubuntu-22.04"
179+
timeout-minutes: 5
180+
steps:
181+
- name: "Check out repository code"
182+
uses: "actions/checkout@v4"
183+
with:
184+
submodules: true
185+
186+
# The official GitHub Action for Vale doesn't work, installing manually instead:
187+
# https://github.com/errata-ai/vale-action/issues/103
188+
- name: Download Vale
189+
run: |
190+
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
191+
tar -xzf vale.tar.gz
192+
env:
193+
VALE_VERSION: ${{ env.VALE_VERSION }}
194+
- name: "Validate documentation style"
195+
run: ./vale $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \) )

Diff for: .github/workflows/sync-docs.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# yamllint disable rule:truthy rule:truthy rule:line-length
3+
name: Sync Docs Folders
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- 'docs/docs/**'
10+
- 'docs/sidebars.ts'
11+
12+
jobs:
13+
sync:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout source repository
17+
uses: actions/checkout@v4
18+
with:
19+
path: source-repo
20+
21+
- name: Checkout target repository
22+
uses: actions/checkout@v4
23+
with:
24+
repository: opsmill/infrahub-docs
25+
token: ${{ secrets.PAT_TOKEN }}
26+
path: target-repo
27+
28+
- name: Sync folders
29+
run: |
30+
rm -rf target-repo/docs/docs-nornir/*
31+
rm -f target-repo/docs/sidebars-nornir.ts
32+
cp -r source-repo/docs/docs/* target-repo/docs/docs-nornir/
33+
cp source-repo/docs/sidebars.ts target-repo/docs/sidebars-nornir.ts
34+
cd target-repo
35+
git config user.name github-actions
36+
git config user.email [email protected]
37+
git add .
38+
if ! (git diff --quiet && git diff --staged --quiet); then git commit -m "Sync docs from nornir-infrahub repo" && git push; fi

Diff for: .markdownlint.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
default: true
3+
MD007:
4+
indent: 4 # sets indent size to 4 spaces
5+
MD013: false # disables max line-length
6+
MD024: false # disables 'no duplicate headings',
7+
# which we use in tabs for instructions
8+
MD025:
9+
front_matter_title: "" # prevent collisions with h1s
10+
# and frontmatter titles
11+
MD029: false # allows manually creating ordered lists
12+
MD033: false # allows inline html to override markdown styles
13+
MD034: false # no-bare-urls
14+
MD045: false # no alt text around images
15+
MD047: false # single trailing newline
16+
MD014: false # dollar signs used before commands

Diff for: .vale.ini

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
StylesPath = .vale/styles
2+
3+
MinAlertLevel = warning
4+
5+
[formats]
6+
mdx = md
7+
8+
[docs/**/*.md]
9+
BasedOnStyles = Infrahub
10+
;(import.*?\n) to ignore import statement in .mdx
11+
;(```.*?```\n) to ignore code block in .mdx
12+
BlockIgnores = (?s) *((import.*?\n)|(```.*?```\n))
13+
14+
[*]
15+
BasedOnStyles = Infrahub

Diff for: .vale/styles/Infrahub/branded-terms-case-swap.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
extends: substitution
3+
message: Use '%s' instead of '%s'
4+
level: error
5+
ignorecase: false
6+
action:
7+
name: replace
8+
swap:
9+
(?i:[^/]Github): GitHub
10+
(?i:gitpod): GitPod
11+
(?i:[^/]Graphql): GraphQL
12+
infrahub(?:\s|$): Infrahub
13+
(?i:Openconfig): OpenConfig
14+
opsmill(?:\s|$): OpsMill

Diff for: .vale/styles/Infrahub/colon-space.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: substitution
3+
message: "Use a space after a colon, but not before"
4+
level: warning
5+
ignorecase: true
6+
nonword: true
7+
swap:
8+
'(?<=\s):(?=\s+)': ': '

Diff for: .vale/styles/Infrahub/eg-ie.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
extends: substitution
3+
message: "Instead of %s, use ',i.e.,' or 'for example:'."
4+
level: warning
5+
ignorecase: true
6+
nonword: true
7+
action:
8+
name: replace
9+
swap:
10+
- e\.g\.: i.e.
11+
- e\. g\.: i.e.
12+
- i\. e\.: i.e.

Diff for: .vale/styles/Infrahub/oxford-comma.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: existence
3+
message: "Use a comma before the last 'and' or 'or' in a list of items."
4+
level: suggestion
5+
scope: sentence
6+
nonword: true
7+
tokens:
8+
- '(?:[^\s,]+,){1,} \w+ (?:and|or) \w+[.?!]'

0 commit comments

Comments
 (0)