add Göltzschtalbrücke (#1673) #1809
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: Hugo PR Preview | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] # Creates seed cache on main | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| deploy-preview: | |
| runs-on: ubuntu-22.04 | |
| if: github.event.action != 'closed' | |
| env: | |
| HUGO_CACHEDIR: /tmp/hugo_cache | |
| # Per-PR concurrency - cancels old builds for same PR only | |
| concurrency: | |
| group: "pr-preview-${{ github.event.number }}" | |
| cancel-in-progress: true | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| submodules: true | |
| fetch-depth: 0 | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: '0.147.2' | |
| extended: true | |
| # Cache Hugo modules | |
| - name: Cache Hugo modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.HUGO_CACHEDIR }} | |
| key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-hugomod- | |
| # Cache Hugo resources (where generated images are stored) | |
| - name: Cache Hugo resources | |
| uses: actions/cache@v4 | |
| with: | |
| path: resources | |
| key: hugo-resources-v1-${{ hashFiles('config.*', 'themes/**', 'layouts/**') }} | |
| restore-keys: | | |
| hugo-resources-v1- | |
| hugo-resources- | |
| - name: Build site | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| # PR build with PR-specific URL | |
| PR_NUMBER=${{ github.event.number }} | |
| REPO_NAME=${{ github.event.repository.name }} | |
| GITHUB_USERNAME=${{ github.repository_owner }} | |
| BASE_URL="https://${GITHUB_USERNAME}.github.io/${REPO_NAME}/pr-${PR_NUMBER}/" | |
| echo "Building PR with baseURL: ${BASE_URL}" | |
| else | |
| # Main branch build with production URL | |
| BASE_URL="https://nerdydaytrips.com/" | |
| echo "Building main branch with baseURL: ${BASE_URL}" | |
| fi | |
| hugo --minify --baseURL="${BASE_URL}" | |
| # ALTERNATIVE APPROACH: Deploy with conflict resolution | |
| - name: Deploy to GitHub Pages with retry and conflict resolution | |
| if: github.event_name == 'pull_request' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} | |
| GITHUB_USER: ${{ secrets.BOT_GITHUB_ACCOUNT }} | |
| PR_NUMBER: ${{ github.event.number }} | |
| run: | | |
| # Configure git | |
| git config --global user.email "action@github.com" | |
| git config --global user.name "GitHub Action" | |
| # Clone gh-pages branch | |
| git clone --single-branch --branch gh-pages "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" gh-pages-repo | |
| cd gh-pages-repo | |
| # Create/update PR directory | |
| mkdir -p "pr-${PR_NUMBER}" | |
| rm -rf "pr-${PR_NUMBER}"/* | |
| cp -r ../public/* "pr-${PR_NUMBER}/" | |
| # Add and commit changes | |
| git add . | |
| # Only commit if there are changes | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Deploy preview for PR #${PR_NUMBER}" | |
| # Retry push with conflict resolution | |
| for i in {1..10}; do | |
| if git push origin gh-pages; then | |
| echo "✅ Successfully deployed PR #${PR_NUMBER}" | |
| break | |
| else | |
| echo "⚠️ Push failed (attempt $i/10), resolving conflicts..." | |
| git pull --rebase origin gh-pages | |
| sleep $((i * 2)) # Exponential backoff | |
| fi | |
| if [ $i -eq 10 ]; then | |
| echo "❌ Failed to deploy after 10 attempts" | |
| exit 1 | |
| fi | |
| done | |
| else | |
| echo "ℹ️ No changes detected for PR #${PR_NUMBER}" | |
| fi | |
| - name: Comment PR with preview link | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = context.payload.number; | |
| const repoName = context.repo.repo; | |
| const repoOwner = context.repo.owner; | |
| const previewUrl = `https://${repoOwner}.github.io/${repoName}/pr-${prNumber}/`; | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && comment.body.includes('🚀 Preview deployed') | |
| ); | |
| const commentBody = `🚀 Preview deployed to: ${previewUrl} | |
| This preview will be automatically cleaned up when the PR is closed.`; | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); | |
| } | |
| cleanup-preview: | |
| runs-on: ubuntu-22.04 | |
| if: github.event.action == 'closed' | |
| steps: | |
| - name: Clean up PR preview | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_USER: ${{ secrets.BOT_GITHUB_ACCOUNT }} | |
| PR_NUMBER: ${{ github.event.number }} | |
| run: | | |
| git config --global user.email "action@github.com" | |
| git config --global user.name "GitHub Action" | |
| # Clone gh-pages branch | |
| git clone --single-branch --branch gh-pages "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" gh-pages-repo | |
| cd gh-pages-repo | |
| # Remove PR directory if it exists | |
| if [ -d "pr-${PR_NUMBER}" ]; then | |
| rm -rf "pr-${PR_NUMBER}" | |
| git add . | |
| git commit -m "Remove preview for PR #${PR_NUMBER}" | |
| # Retry push with conflict resolution | |
| for i in {1..5}; do | |
| if git push origin gh-pages; then | |
| echo "✅ Successfully cleaned up PR #${PR_NUMBER}" | |
| break | |
| else | |
| echo "⚠️ Cleanup push failed (attempt $i/5), resolving conflicts..." | |
| git pull --rebase origin gh-pages | |
| sleep $((i * 2)) | |
| fi | |
| done | |
| else | |
| echo "ℹ️ No directory found for PR #${PR_NUMBER}" | |
| fi | |
| - name: Update PR with cleanup message | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const prNumber = context.payload.number; | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && comment.body.includes('🚀 Preview deployed') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: `✅ Preview was deployed and has been cleaned up after PR closure.` | |
| }); | |
| } |