Merge pull request #10 from Kanguros/fix/html_report #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: π Documentation | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| paths: | |
| - 'docs/**' | |
| - 'policy_inspector/**' | |
| - 'pyproject.toml' | |
| - '.github/workflows/docs.yml' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'docs/**' | |
| - 'policy_inspector/**' | |
| - 'pyproject.toml' | |
| workflow_dispatch: # Allow manual triggering | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| # Build documentation | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| build_status: ${{ steps.build-docs.outputs.build_status }} | |
| html_files: ${{ steps.build-docs.outputs.html_files }} | |
| asset_files: ${{ steps.build-docs.outputs.asset_files }} | |
| image_files: ${{ steps.build-docs.outputs.image_files }} | |
| warning_count: ${{ steps.build-docs.outputs.warning_count }} | |
| steps: | |
| - name: π Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Full history for version info | |
| - name: π Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: π¦ Install Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: latest | |
| virtualenvs-create: true | |
| virtualenvs-in-project: true | |
| - name: π Load cached venv | |
| id: cached-poetry-dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: .venv | |
| key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | |
| - name: π Install dependencies | |
| if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
| run: | | |
| poetry install --with docs | |
| - name: π§ Configure Sphinx | |
| run: | | |
| echo "Building documentation for commit: ${{ github.sha }}" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "## π Documentation Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "π **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "πΏ **Branch**: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "π **Python Version**: $(python --version)" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| - name: ποΈ Build documentation | |
| id: build-docs | |
| run: | | |
| cd docs | |
| # Start build section in summary | |
| echo "## π Documentation Build" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Build with detailed output and capture both stdout and stderr | |
| if poetry run sphinx-build -b html source build/html 2>&1 | tee build.log; then | |
| echo "β **Build Status**: Success" >> $GITHUB_STEP_SUMMARY | |
| echo "build_status=success" >> $GITHUB_OUTPUT | |
| else | |
| echo "β **Build Status**: Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "build_status=failed" >> $GITHUB_OUTPUT | |
| # Add error details to summary | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### β Build Errors" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| tail -20 build.log >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| # Add .nojekyll file to prevent GitHub Pages from processing with Jekyll | |
| touch build/html/.nojekyll | |
| # Generate build statistics | |
| file_count=$(find build/html -name "*.html" | wc -l) | |
| asset_count=$(find build/html -name "*.css" -o -name "*.js" | wc -l) | |
| image_count=$(find build/html -name "*.png" -o -name "*.jpg" -o -name "*.svg" | wc -l) | |
| total_size=$(du -sh build/html | cut -f1) | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π Build Statistics" >> $GITHUB_STEP_SUMMARY | |
| echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY | |
| echo "|--------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| π HTML files | $file_count |" >> $GITHUB_STEP_SUMMARY | |
| echo "| π¨ CSS/JS assets | $asset_count |" >> $GITHUB_STEP_SUMMARY | |
| echo "| πΌοΈ Images | $image_count |" >> $GITHUB_STEP_SUMMARY | |
| echo "| π¦ Total size | $total_size |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Save statistics as outputs | |
| echo "html_files=$file_count" >> $GITHUB_OUTPUT | |
| echo "asset_files=$asset_count" >> $GITHUB_OUTPUT | |
| echo "image_files=$image_count" >> $GITHUB_OUTPUT | |
| # Check for warnings (but don't fail on them) | |
| if grep -i "warning" build.log > /dev/null; then | |
| warning_count=$(grep -c -i "warning" build.log) | |
| echo "β οΈ **Warnings**: $warning_count found" >> $GITHUB_STEP_SUMMARY | |
| echo "warning_count=$warning_count" >> $GITHUB_OUTPUT | |
| else | |
| echo "β **Warnings**: None" >> $GITHUB_STEP_SUMMARY | |
| echo "warning_count=0" >> $GITHUB_OUTPUT | |
| fi | |
| - name: οΏ½ Setup Pages | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: actions/configure-pages@v4 | |
| - name: π€ Upload documentation artifact | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: docs/build/html | |
| - name: π Upload build artifacts for review | |
| if: github.event_name == 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: documentation-preview | |
| path: docs/build/html | |
| retention-days: 7 | |
| - name: π Generate final summary | |
| run: | | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "## π― Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| # Summary table | |
| echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| ποΈ Build | ${{ steps.build-docs.outputs.build_status == 'success' && 'β Success' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ github.ref }}" == "refs/heads/main" ] && [ "${{ github.event_name }}" == "push" ]; then | |
| echo "π **Next Step**: Documentation will be deployed to GitHub Pages" >> $GITHUB_STEP_SUMMARY | |
| elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
| echo "π **Next Step**: Download preview artifact to review changes" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Deploy to GitHub Pages | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: π Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| - name: π’ Deployment summary | |
| run: | | |
| echo "## π Deployment Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "β **Deployment Status**: Success" >> $GITHUB_STEP_SUMMARY | |
| echo "π **Live URL**: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### π Build Results" >> $GITHUB_STEP_SUMMARY | |
| echo "- π HTML files generated: ${{ needs.build.outputs.html_files }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- π¨ Assets: ${{ needs.build.outputs.asset_files }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- πΌοΈ Images: ${{ needs.build.outputs.image_files }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- β οΈ Warnings: ${{ needs.build.outputs.warning_count }}" >> $GITHUB_STEP_SUMMARY |