Publish to GitHub Pages #14
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: Publish to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_run: | |
| workflows: ["Build, Test & Release pg_ask Extension"] | |
| types: | |
| - completed | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish-pages: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download artifacts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const scriptPath = './.github/pages/download-artifacts.js'; | |
| const scriptContent = fs.readFileSync(scriptPath, 'utf8'); | |
| eval(scriptContent); | |
| - name: Extract and organize artifacts | |
| run: | | |
| mkdir -p releases/linux-x86_64 | |
| # Extract artifacts and organize into platform-specific folders | |
| for zip in pg_ask-*.zip; do | |
| [ -f "$zip" ] || continue | |
| echo "Processing artifact: $zip" | |
| # Create temporary extraction directory | |
| temp_dir=$(mktemp -d) | |
| unzip -q "$zip" -d "$temp_dir" | |
| # Copy files to linux-x86_64 folder | |
| find "$temp_dir" -name "*.so" -exec cp {} releases/linux-x86_64/ \; | |
| find "$temp_dir" -name "*.control" -exec cp {} releases/linux-x86_64/ \; | |
| find "$temp_dir" -name "*.sql" -exec cp {} releases/linux-x86_64/ \; | |
| # Cleanup temp directory | |
| rm -rf "$temp_dir" | |
| done | |
| # Show directory structure for debugging | |
| echo "Release structure:" | |
| ls -lR releases/ | |
| - name: Generate GitHub Pages site | |
| env: | |
| REPO: abiji-2020/pg_ask | |
| VERSION: ${{ github.ref_name }} | |
| PAGES_URL: https://abiji-2020.github.io/pg_ask | |
| run: | | |
| # Copy install script from main branch | |
| git show main:scripts/install.sh > install.sh 2>/dev/null || echo "#!/bin/bash" > install.sh | |
| chmod +x install.sh | |
| # Process index.html template | |
| sed "s|{{REPO}}|$REPO|g; s|{{PAGES_URL}}|$PAGES_URL|g" .github/pages/index.html > index.html | |
| # Build manifest.json using the repository helper | |
| python3 .github/pages/generate-manifest.py | |
| - name: Commit and push to gh-pages | |
| run: | | |
| # Configure git | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Store generated files in a safe location | |
| mkdir -p /tmp/gh-pages-content | |
| cp -r releases /tmp/gh-pages-content/ 2>/dev/null || mkdir -p /tmp/gh-pages-content/releases | |
| cp install.sh /tmp/gh-pages-content/ 2>/dev/null || true | |
| cp index.html /tmp/gh-pages-content/ 2>/dev/null || true | |
| cp manifest.json /tmp/gh-pages-content/ 2>/dev/null || true | |
| # Check if gh-pages branch exists on remote | |
| if git ls-remote --heads origin gh-pages | grep gh-pages; then | |
| echo "gh-pages branch exists, checking it out..." | |
| # Remove untracked files that might conflict | |
| git clean -fd | |
| git fetch origin gh-pages | |
| git checkout gh-pages | |
| # Clean all existing content (but preserve .git) | |
| find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name '..' -exec rm -rf {} + 2>/dev/null || true | |
| else | |
| echo "gh-pages branch doesn't exist, creating orphan branch..." | |
| git checkout --orphan gh-pages | |
| git rm -rf . 2>/dev/null || true | |
| # Clean all existing content (but preserve .git) | |
| find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name '..' -exec rm -rf {} + 2>/dev/null || true | |
| fi | |
| # Copy generated site files from safe location | |
| cp -r /tmp/gh-pages-content/* . 2>/dev/null || true | |
| # Show what we're about to commit | |
| echo "Files to commit:" | |
| ls -la | |
| echo "Releases directory:" | |
| ls -R releases/ || echo "No releases found" | |
| # Commit and push | |
| git add -A | |
| if git diff --staged --quiet 2>/dev/null; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "docs: publish artifacts from ${{ github.sha }} to GitHub Pages" | |
| git push origin gh-pages --force | |
| fi |