-
Notifications
You must be signed in to change notification settings - Fork 2
103 lines (84 loc) · 3.23 KB
/
docs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Deploy Documentation
on:
push:
branches:
- main
paths:
- 'docs/**' # Documentation content
- 'mkdocs.yml' # MkDocs configuration
- '.github/workflows/docs.yml' # This workflow file
- 'pyproject.toml' # For doc dependencies
# Add any Python files that generate docs
- 'prompt_templates/**/*.py' # Source files (for docstrings)
# Optional: Allow manual triggers
workflow_dispatch:
permissions:
contents: write
jobs:
check_changes:
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.check.outputs.should_deploy }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for checking changes
- name: Check for documentation changes
id: check
run: |
# Check if this is a manual trigger
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
exit 0
fi
# For push events, check if this is the first push
if [ -z "${{ github.event.before }}" ]; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
exit 0
fi
# Check for changes in relevant files
git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt
# Debug output
echo "Changed files:"
cat changed_files.txt
# Look for changes in docs, mkdocs.yml, or Python files
if grep -q -E '^docs/|^mkdocs\.yml|\.py$' changed_files.txt; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
else
echo "should_deploy=false" >> $GITHUB_OUTPUT
fi
deploy:
if: >
github.event_name == 'workflow_dispatch' ||
(needs.check_changes.outputs.should_deploy == 'true' && github.event_name == 'push')
runs-on: ubuntu-latest
needs: check_changes # Still need this for push events
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
# Debug: Show poetry version
poetry --version
# Install with verbose output
poetry install --only docs -v
# List all installed packages
poetry run pip list
# Show poetry environment info
poetry env info
- name: Build and deploy documentation
run: |
# Configure git to use the new repository URL
git remote set-url origin https://github.com/MoritzLaurer/prompt_templates.git
poetry run mkdocs gh-deploy --force