Skip to content

Commit 6e6a88c

Browse files
committed
Added: Support for requirements.txt to have locked version inputs.
1 parent 61c188c commit 6e6a88c

2 files changed

Lines changed: 82 additions & 6 deletions

File tree

README.MD

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,70 @@ Find more examples in [the tests](./.github/workflows/test-mkdocs-workflow.yml).
120120
output-directory: custom_site_dir
121121
```
122122

123+
### Locked Requirements for Reproducible Builds
124+
125+
To guarantee your documentation builds consistently over time and avoid plugin version incompatibilities,
126+
lock your dependencies using `pip-tools`.
127+
128+
Assuming you have a local Python installation:
129+
130+
Create a `docs/requirements.in` with MkDocs Material and your plugins:
131+
132+
```txt
133+
mkdocs-material==9.5.24
134+
mkdocs-git-revision-date-localized-plugin
135+
mkdocs-awesome-pages-plugin
136+
mkdocs-minify-plugin
137+
```
138+
139+
Generate locked `docs/requirements.txt`:
140+
141+
```bash
142+
pip install pip-tools
143+
pip-compile docs/requirements.in -o docs/requirements.txt
144+
```
145+
146+
Use in workflow:
147+
148+
```yaml
149+
- name: Deploy MkDocs
150+
uses: Reloaded-Project/devops-mkdocs@v1
151+
with:
152+
requirements: ./docs/requirements.txt
153+
```
154+
155+
**Note:** If `mkdocs-material` is present in your `requirements.txt`, the action will install only
156+
from the requirements file (ignoring the `mkdocs-version` input). If `mkdocs-material` is not in
157+
your requirements, the action will install it from the `mkdocs-version` input alongside your
158+
requirements, letting pip resolve compatible versions.
159+
160+
To update dependencies, edit `docs/requirements.in` and regenerate:
161+
162+
```bash
163+
pip-compile --upgrade docs/requirements.in -o docs/requirements.txt
164+
```
165+
166+
#### Testing Locally
167+
168+
Test locked requirements in a clean environment:
169+
170+
```bash
171+
# Create and activate virtual environment
172+
python -m venv .venv
173+
source .venv/bin/activate # Windows: .venv\Scripts\activate
174+
175+
# Install pip-tools and generate locked requirements
176+
pip install pip-tools
177+
pip-compile docs/requirements.in -o docs/requirements.txt
178+
179+
# Install and test
180+
pip install -r docs/requirements.txt
181+
mkdocs build
182+
183+
# Deactivate when done
184+
deactivate
185+
```
186+
123187
## Viewing the Generated Docs
124188

125189
After a successful run, the generated static site will be available on the GitHub Pages site for

action.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,25 @@ runs:
5555
shell: bash
5656
run: |
5757
python -m pip install --upgrade pip
58-
if [ "${{ inputs.mkdocs-version }}" = "latest" ]; then
59-
pip install mkdocs-material
60-
else
61-
pip install mkdocs-material==${{ inputs.mkdocs-version }}
62-
fi
58+
# If requirements.txt exists and contains mkdocs-material, install only from requirements
59+
# (user has locked their mkdocs version). Otherwise, install mkdocs-material from
60+
# mkdocs-version input alongside requirements to let pip resolve compatible versions.
6361
if [ -f "${{ inputs.requirements }}" ]; then
64-
pip install -r "${{ inputs.requirements }}"
62+
if grep -q "mkdocs-material" "${{ inputs.requirements }}"; then
63+
pip install -r "${{ inputs.requirements }}"
64+
else
65+
if [ "${{ inputs.mkdocs-version }}" = "latest" ]; then
66+
pip install mkdocs-material -r "${{ inputs.requirements }}"
67+
else
68+
pip install mkdocs-material==${{ inputs.mkdocs-version }} -r "${{ inputs.requirements }}"
69+
fi
70+
fi
71+
else
72+
if [ "${{ inputs.mkdocs-version }}" = "latest" ]; then
73+
pip install mkdocs-material
74+
else
75+
pip install mkdocs-material==${{ inputs.mkdocs-version }}
76+
fi
6577
fi
6678
6779
- name: Run Pre-build Command

0 commit comments

Comments
 (0)