name: Build and Deploy Hugo Site on: # Run on releases release: types: [published] # Run when the release workflow completes workflow_run: workflows: ["Generate a Release from a Tag"] types: - completed # Allow manual trigger workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: write pages: write id-token: write # Allow only one concurrent deployment concurrency: group: "pages" cancel-in-progress: false # Default to bash defaults: run: shell: bash jobs: # Build and deploy job build-and-deploy: runs-on: ubuntu-latest env: HUGO_VERSION: 0.148.2 steps: - name: Install Hugo CLI run: | wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb - name: Checkout source uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 - name: Build with Hugo env: HUGO_ENVIRONMENT: production HUGO_ENV: production run: | hugo \ --gc \ --minify \ --baseURL "https://sbarbett.github.io/reticulating-splines/" - name: Setup Git run: | git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" - name: Deploy to pages branch run: | # Debug: Check what's in the current directory echo "Current directory: $(pwd)" echo "Contents of current directory:" ls -la # Debug: Check if public directory exists echo "Checking for public directory:" ls -la public/ || echo "public directory not found" # Store the built files in a temporary location echo "Storing built files..." mkdir -p /tmp/hugo-built-files cp -r public/* /tmp/hugo-built-files # Create or reset the pages branch if git show-ref --verify --quiet refs/remotes/origin/pages; then git checkout -B pages origin/pages else git checkout --orphan pages fi # Remove all files except .git git rm -rf . || true echo "public/*" > .gitignore # Copy built files from temporary location echo "Copying built files to pages branch..." cp -r /tmp/hugo-built-files/* . # Add CNAME file for custom domain echo "blog.barbetta.me" > CNAME # Add all files git add . # Commit if there are changes if git diff --staged --quiet; then echo "No changes to commit" else git commit -m "Deploy Hugo site - $(date)" git push origin pages --force fi