Skip to content

Commit 55037f0

Browse files
authored
Merge pull request #168 from pkalita-lbl/versioned-docs
Use versioned documentation deployment
2 parents 9050fe6 + 9747897 commit 55037f0

File tree

418 files changed

+409
-289969
lines changed

Some content is hidden

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

418 files changed

+409
-289969
lines changed

.github/workflows/build-publish-documentation.yaml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ on:
55
push:
66
branches:
77
- main
8-
paths:
9-
- "mkdocs.yml"
10-
- "linkml_model/model/schema/*.yaml"
11-
- "linkml_model/model/docs/*"
128

139
jobs:
1410
github-pages:
1511
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
1615

1716
steps:
1817
#----------------------------------------------
1918
# check-out repo and set-up python
2019
#----------------------------------------------
2120
- name: Check out repository
22-
uses: actions/checkout@v2
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0 # fetch all commits/branches so that mike works
2324

2425
- name: Setup Python 3.9
25-
uses: actions/setup-python@v2
26+
uses: actions/setup-python@v4
2627
with:
2728
python-version: 3.9
2829

@@ -40,7 +41,7 @@ jobs:
4041
#----------------------------------------------
4142
- name: Load cached venv
4243
id: cached-poetry-dependencies
43-
uses: actions/cache@v2
44+
uses: actions/cache@v3
4445
with:
4546
path: .venv
4647
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
@@ -50,15 +51,31 @@ jobs:
5051
#----------------------------------------------
5152
- name: Install dependencies
5253
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
53-
run: poetry install --no-interaction --no-root
54-
54+
run: poetry install --no-interaction --no-root
55+
56+
- name: Configure git user
57+
run: |
58+
git config user.name "${GITHUB_ACTOR}"
59+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
60+
5561
#----------------------------------------------
5662
# generate markdown files
5763
#----------------------------------------------
58-
- run: make gendoc
64+
- name: Generate markdown docs from schema
65+
run: make gen-doc
5966

6067
#----------------------------------------------
6168
# deploy documentation
6269
#----------------------------------------------
63-
- run: make deploy
64-
70+
- name: Deploy generated docs
71+
run: |
72+
# generate HTML from markdown and put into dev version
73+
poetry run mike deploy dev
74+
75+
# switch to gh-pages branch, copy over the latest 404.html from main
76+
git checkout --force gh-pages
77+
git checkout --force main -- 404.html
78+
git commit -m "Add 404.html to root" || echo "No changes to 404.html to commit"
79+
80+
# push changes to gh-page branch
81+
git push origin gh-pages

.github/workflows/codespell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ jobs:
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v3
20+
2021
- name: Codespell
2122
uses: codespell-project/actions-codespell@v2

.github/workflows/main.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
# check-out repo and set-up python
2424
#----------------------------------------------
2525
- name: Check out repository
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v3
2727

2828
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v2
29+
uses: actions/setup-python@v4
3030
with:
3131
python-version: ${{ matrix.python-version }}
3232

@@ -44,7 +44,7 @@ jobs:
4444
#----------------------------------------------
4545
- name: Load cached venv
4646
id: cached-poetry-dependencies
47-
uses: actions/cache@v2
47+
uses: actions/cache@v3
4848
with:
4949
path: .venv
5050
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

.github/workflows/pypi-publish.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Docs & PyPI Package
2+
3+
on:
4+
release:
5+
types: [ created ]
6+
7+
jobs:
8+
release:
9+
name: Create release artifacts
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: write
14+
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0 # fetch all commits/branches so that mike works
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: 3.9
25+
26+
- name: Install Poetry
27+
uses: snok/install-poetry@v1.3
28+
with:
29+
virtualenvs-create: true
30+
virtualenvs-in-project: true
31+
32+
- name: Install dependencies
33+
run: poetry install --no-interaction
34+
35+
- name: Build source and wheel archives
36+
run: |
37+
poetry version $(git describe --tags --abbrev=0)
38+
poetry build
39+
40+
- name: Publish distribution to PyPI
41+
if: github.repository == 'linkml/linkml'
42+
uses: pypa/gh-action-pypi-publish@v1.2.2
43+
with:
44+
user: __token__
45+
password: ${{ secrets.pypi_password }}
46+
47+
- name: Parse version from tag
48+
id: version
49+
uses: release-kit/semver@v2
50+
51+
- name: Configure git user
52+
run: |
53+
git config user.name "${GITHUB_ACTOR}"
54+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
55+
56+
- name: Generate markdown docs from schema
57+
run: make gen-doc
58+
59+
- name: Deploy docs
60+
if: github.event.release.prerelease == false
61+
run: |
62+
# generate HTML from markdown and put into MAJOR.MINOR version, update "latest" alias
63+
poetry run mike deploy --update-aliases ${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.x latest
64+
65+
# copy the latest linkml_model files up to the root
66+
git checkout --force gh-pages
67+
rm -rf linkml_model
68+
cp -r latest/linkml_model .
69+
git add -A linkml_model
70+
git commit -m "Copy latest linkml_model to root level" || echo "No changes to linkml_model to commit"
71+
72+
# copy over the latest 404.html from the tag
73+
git checkout --force ${{github.event.release.tag_name}} -- 404.html
74+
git commit -m "Add 404.html to root" || echo "No changes to 404.html to commit"
75+
76+
# push changes to gh-page branch
77+
git push origin gh-pages

.github/workflows/validate-yaml-syntax.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
validate-yaml:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- name: Check out repository
14+
uses: actions/checkout@v3
15+
1416
- name: Validate YAML file
1517
run: yamllint -c .yamllint-config linkml_model/model/schema/*.yaml

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Elements that are built using Make
22
.venv/
33
target/
4+
staging/
5+
/docs/
46
/make-venv/
57

68
# Ignore all of linkml_model except the model directory

404.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--This file is copied into the root of the documentation branch (gh-pages) after the mkdocs-generated-->
2+
<!--docs are in place. This file helps redirect paths like:-->
3+
<!-- * / => /latest-->
4+
<!-- * /docs/pattern => /latest/docs/pattern-->
5+
<!-- * /does-not-exist => /latest/404-->
6+
<!-- * /1.5.x/does-not-exist => /1.5.x/404-->
7+
8+
<script>
9+
// Check if the current path is versioned, if not, redirect to the default versioned path
10+
const defaultVersion = "latest"
11+
const basePath = "/linkml-model"
12+
const targetRedirectPath = "404" // path to redirect to, relative to basePath
13+
14+
const match = window.location.pathname.match(`^${basePath}/(v[0-9.]+|dev|latest)/`)
15+
if (match) {
16+
// if path starts with version, redirect to versioned 404
17+
const versionedPath = `${basePath}/${match[1]}`;
18+
window.location.href = `${versionedPath}/${targetRedirectPath}`
19+
} else {
20+
// if path doesn't start with any version, redirect to defaultVersion
21+
window.location.href = window.location.href.replace(basePath, `${basePath}/${defaultVersion}`)
22+
}
23+
</script>

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The [docs](docs) folder houses the built schema index.
2323
To build the docs:
2424

2525
```
26-
make gendoc
26+
make gen-doc
2727
```
2828

2929
This stages the documentation in target/docs

Makefile

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ RUN = poetry run
1111
SCHEMA_NAME = linkml_model
1212
SOURCE_SCHEMA_PATH = $(shell sh ./utils/get-value.sh source_schema_path)
1313
SRC = .
14-
DEST = target
15-
PYMODEL = linkml_model/
16-
DOCDIR = $(DEST)/docs
14+
DEST = staging
15+
PYMODEL = linkml_model
16+
DOCDIR = docs/source
17+
18+
$(PYMODEL):
19+
mkdir -p $@
20+
21+
$(DEST):
22+
mkdir -p $@
1723

1824
# basename of a YAML file in model/
1925
.PHONY: all clean
@@ -34,22 +40,39 @@ status: check-config
3440
@echo "Project: $(SCHEMA_NAME)"
3541
@echo "Source: $(SOURCE_SCHEMA_PATH)"
3642

37-
setup: install gen-project gendoc git-init-add
43+
setup: install gen-project gen-doc git-init-add
3844

3945
install:
4046
poetry install
4147
.PHONY: install
4248

43-
all: gen-project gendoc
49+
all: gen-project gen-doc
4450
%.yaml: gen-project
45-
deploy: gendoc mkd-gh-deploy
51+
deploy: gen-doc mkd-gh-deploy
4652

4753
# generates all project files
4854
# and updates the artifacts in linkml-model
49-
gen-project: $(PYMODEL)
50-
$(RUN) gen-project -d $(DEST) --config-file gen_project_config.yaml $(SOURCE_SCHEMA_PATH) && mv $(DEST)/*.py $(PYMODEL)
55+
gen-project: $(PYMODEL) gen-py
56+
$(RUN) gen-project -d $(DEST) --config-file gen_project_config.yaml $(SOURCE_SCHEMA_PATH)
5157
cp -r $(DEST)/* $(PYMODEL)
52-
rm -r $(PYMODEL)/docs
58+
59+
gen-py: $(DEST)
60+
# for all the files in the schema folder, run the gen-python command and output the result to the top
61+
# level of the project. In other repos, we'd include mergeimports=True, but we don't do that with
62+
# linkml-model.
63+
@for file in $(wildcard $(PYMODEL)/model/schema/*.yaml); do \
64+
base=$$(basename $$file); \
65+
filename_without_suffix=$${base%.*}; \
66+
$(RUN) gen-python --genmeta $$file > $(DEST)/$$filename_without_suffix.py; \
67+
done
68+
cp $(DEST)/*.py $(PYMODEL)
69+
70+
gen-doc:
71+
$(RUN) gen-doc --genmeta --sort-by rank -d $(DOCDIR)/docs $(SOURCE_SCHEMA_PATH)
72+
cp -r linkml_model/model/docs/* $(DOCDIR)/docs
73+
cp -r $(PYMODEL) $(DOCDIR)/$(PYMODEL)
74+
rm -rf $(DOCDIR)/$(PYMODEL)/model/docs
75+
cp README.md $(DOCDIR)
5376

5477
test: test-schema test-python test-validate-schema
5578
test-schema:
@@ -85,19 +108,7 @@ upgrade:
85108
# Test documentation locally
86109
serve: mkd-serve
87110

88-
# Python datamodel
89-
$(PYMODEL):
90-
mkdir -p $@
91-
92-
93-
$(DOCDIR):
94-
mkdir -p $@
95-
96-
gendoc: $(DOCDIR)
97-
cp -pr linkml_model/model/docs/ $(DOCDIR) ; \
98-
$(RUN) gen-doc --genmeta --sort-by rank -d $(DOCDIR) $(SOURCE_SCHEMA_PATH)
99-
100-
testdoc: gendoc serve
111+
testdoc: gen-doc serve
101112

102113
builddoc:
103114
$(RUN) mkdocs build
@@ -120,18 +131,9 @@ git-status:
120131

121132
clean:
122133
rm -rf $(DEST)
134+
rm -rf docs
123135
rm -rf tmp
124136

125-
generate_python_models:
126-
# for all the files in the schema folder, run the gen-python command and output the result to the top
127-
# level of the project. In other repos, we'd include mergeimports=True, but we don't do that with
128-
# linkml-model.
129-
@for file in $(wildcard $(PYMODEL)/model/schema/*.yaml); do \
130-
base=$$(basename $$file); \
131-
filename_without_suffix=$${base%.*}; \
132-
poetry run gen-python --genmeta $$file > $(PYMODEL)/$$filename_without_suffix.py; \
133-
done
134-
135137
spell:
136138
poetry run codespell
137139

0 commit comments

Comments
 (0)