-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (179 loc) · 6.85 KB
/
Copy pathgenerate-vicutils-docs.yml
File metadata and controls
213 lines (179 loc) · 6.85 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Generate VicUtils Docs and Publish
on:
push:
paths:
- 'vicutils/**/*.py'
branches:
- main
permissions:
contents: write
id-token: write # Required for trusted publishing
packages: write # Required for GitHub Packages
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install pdoc3 build twine
# Install project dependencies from requirements.txt if it exists
if [ -f requirements.txt ]; then
echo "Installing dependencies from requirements.txt"
pip install -r requirements.txt
else
echo "No requirements.txt found at root"
fi
echo "pdoc3 version:"
pdoc --version
- name: Increment version
id: version
run: |
if [ ! -f .version ]; then
echo "0.1" > .version
echo "Created .version file with initial version 0.1"
fi
current_version=$(cat .version)
IFS='.' read -r major minor <<< "$current_version"
new_minor=$((minor + 1))
new_version="${major}.${new_minor}"
echo "$new_version" > .version
sed -i "s/version=\"[^\"]*\"/version=\"$new_version\"/" setup.py
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
echo "version=$new_version" >> $GITHUB_OUTPUT
- name: Update setup.py requirements
run: |
if [ -f requirements.txt ]; then
echo "Updating install_requires in setup.py from requirements.txt"
python3 << 'EOF'
import re
# Read requirements
with open('requirements.txt', 'r') as f:
reqs = [line.strip() for line in f if line.strip() and not line.startswith('#')]
# Format as Python list string
reqs_str = '[' + ', '.join(f'"{req}"' for req in reqs) + ']'
# Read setup.py
with open('setup.py', 'r') as f:
content = f.read()
# Replace install_requires
content = re.sub(r'install_requires=\[.*?\]', f'install_requires={reqs_str}', content, flags=re.DOTALL)
# Write back
with open('setup.py', 'w') as f:
f.write(content)
print(f"Updated install_requires: {reqs_str}")
EOF
else
echo "No requirements.txt found, skipping setup.py update"
fi
- name: Generate __init__.py files automatically
run: |
echo "Generating __init__.py files..."
find vicutils -type d | while read dir; do
init_file="$dir/__init__.py"
if [ ! -f "$init_file" ]; then
touch "$init_file"
fi
echo "" > "$init_file"
for py in "$dir"/*.py; do
[ -f "$py" ] || continue
base=$(basename "$py" .py)
if [ "$base" != "__init__" ]; then
echo "from .${base} import *" >> "$init_file"
fi
done
done
- name: Check vicutils directory
run: |
echo "=== Contents of vicutils directory ==="
ls -la vicutils/
echo "=== Python files found ==="
find vicutils/ -name "*.py" -not -name "__init__.py"
- name: Generate documentation
run: |
echo "=== Generating documentation ==="
find vicutils/ -mindepth 2 -name "*.py" -not -name "__init__.py" | while read file; do
dir=$(dirname "$file")
basename=$(basename "$file" .py)
cd "$dir"
python -m pdoc --html --force --output-dir . "$basename"
if [ -d "$basename" ]; then
mv "$basename"/index.html "$basename.html"
rm -rf "$basename"
fi
cd - > /dev/null
done
echo "=== Final vicutils contents ==="
find vicutils/ -type f
- name: Build package
run: |
echo "=== Building package ==="
python -m build
echo "=== Build artifacts ==="
ls -la dist/
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m twine upload dist/* --skip-existing
- name: Publish to GitHub Packages
env:
TWINE_USERNAME: ${{ github.actor }}
TWINE_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure pip for GitHub Packages
cat > ~/.pypirc << EOF
[distutils]
index-servers =
pypi
github
[pypi]
username = __token__
password = ${{ secrets.PYPI_API_TOKEN }}
[github]
repository = https://maven.pkg.github.com/${{ github.repository_owner }}
username = ${{ github.actor }}
password = ${{ secrets.GITHUB_TOKEN }}
EOF
# Upload to GitHub Packages (will show in Packages section)
python -m twine upload --repository github dist/* --skip-existing || echo "GitHub Packages upload skipped or failed"
- name: Commit and push if changes
run: |
git config --local user.name "Vic-Nas"
git config --local user.email "github-actions@github.com"
git add .version setup.py
git add vicutils/**/*.html || echo "No HTML files to add"
git add vicutils/**/*.py || echo "No Python files to add"
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Auto-generate docs and bump version ${{ steps.version.outputs.version }}"
git push
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Release v${{ steps.version.outputs.version }}
body: |
## 📦 vicutils v${{ steps.version.outputs.version }}
Auto-generated release from vicutils code changes.
### Installation
```bash
pip install vicutils==${{ steps.version.outputs.version }}
```
### Documentation
Visit [the documentation](https://vic-nas.github.io/PythonSolutions/#vicutils) for usage examples.
files: dist/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}