Skip to content

Version test

Version test #38

name: Generate VicUtils Docs and Publish
on:
push:
paths:
- 'vicutils/**/*.py'
branches:
- main
permissions:
contents: write
id-token: write # Required for trusted publishing
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
echo "pdoc3 version:"
pdoc --version
- name: Increment version
run: |
# Create .version file if it doesn't exist
if [ ! -f .version ]; then
echo "0.1" > .version
echo "Created .version file with initial version 0.1"
fi
# Read current version
current_version=$(cat .version)
echo "Current version: $current_version"
# Increment version (major.minor format)
IFS='.' read -r major minor <<< "$current_version"
new_minor=$((minor + 1))
new_version="${major}.${new_minor}"
echo "New version: $new_version"
# Save new version
echo "$new_version" > .version
# Update setup.py
sed -i "s/version=\"[^\"]*\"/version=\"$new_version\"/" setup.py
echo "=== Updated files ==="
echo "Version file:"
cat .version
echo "setup.py:"
grep 'version=' setup.py
# Export for later steps
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- 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 all Python files in vicutils subdirectories (not root)
find vicutils/ -mindepth 2 -name "*.py" -not -name "__init__.py" | while read file; do
echo "Processing: $file"
dir=$(dirname "$file")
basename=$(basename "$file" .py)
cd "$dir"
python -m pdoc --html --force --output-dir . "$basename"
echo "Contents after pdoc:"
ls -la
# Move generated HTML
if [ -d "$basename" ]; then
echo "Moving $basename/index.html to $basename.html"
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: Commit and push if changes
run: |
git config --local user.name "Vic-Nas"
git config --local user.email "github-actions@github.com"
# Add all changes
git add .version setup.py
git add vicutils/**/*.html || echo "No HTML files to add"
if git diff --staged --quiet; then
echo "No changes to commit"
else
echo "Committing changes for version $NEW_VERSION"
git commit -m "Auto-generate docs and bump version to $NEW_VERSION"
git push
fi