Skip to content

Add PR preview deployments via GitHub Actions#56

Merged
ProLoser merged 12 commits intogh-pagesfrom
copilot/add-preview-urls-to-pull-requests
Mar 1, 2026
Merged

Add PR preview deployments via GitHub Actions#56
ProLoser merged 12 commits intogh-pagesfrom
copilot/add-preview-urls-to-pull-requests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 1, 2026

  • Create .github/workflows/pr-preview.yml workflow that:
    • Triggers on pull_request events (opened, reopened, synchronize, closed)
    • Injects API tokens for non-closed events
    • Stages only map.js, .html, .json, and .css files (excludes favicons, crawler, docs, screenshots, etc.)
    • Deploys preview to preview/pr-{number} subdirectory on gh-pages branch using rossjrw/pr-preview-action@v1
    • Posts PR comment with preview URL (e.g. https://funcheapsfmap.com/preview/pr-1/)
    • Split into two jobs: preview (pushes files, dispatches deploy.yml via workflow_dispatch) and wait (uses gh run watch to block until the dispatched deploy.yml run completes, ensuring Pages is live before the workflow finishes)
    • Cleans up preview on PR close

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copilot AI changed the title [WIP] Add preview URLs generation for pull requests Add PR preview deployments via GitHub Actions Mar 1, 2026
@ProLoser ProLoser marked this pull request as ready for review March 1, 2026 01:49
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 1, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-01 02:52 UTC

@ProLoser
Copy link
Copy Markdown
Owner

ProLoser commented Mar 1, 2026

@copilot only publish map.js files and html and json, i don't think you should publish anything else

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot only publish map.js files and html and json, i don't think you should publish anything else

Done in 71ae8b0. Added a "Stage preview files" step that copies only index.html, map.js, categories.json, 19hz/index.html, 19hz/map.js, and 19hz/venues.json to a temp directory — everything else (CSS, favicon, crawler, docs, screenshots, etc.) is excluded from the preview deployment.

@ProLoser
Copy link
Copy Markdown
Owner

ProLoser commented Mar 1, 2026

@copilot also css and i think this is not trigger gh-pages to be deployed

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot also css and i think this is not trigger gh-pages to be deployed

Done in a162b58. Two changes:

  1. Added style.css to the staged files alongside the html/js/json files.
  2. Added a "Trigger Pages deploy" step that runs gh workflow run deploy.yml --ref gh-pages after the preview push — this is needed because GITHUB_TOKEN pushes don't automatically trigger other workflows, so deploy.yml wouldn't otherwise fire to serve the preview files.

Change umbrella directory from 'pr-preview' to 'preview' and add new options for QR code and deployment wait.
@ProLoser
Copy link
Copy Markdown
Owner

ProLoser commented Mar 1, 2026

@copilot getting stuck

Checking configuration and starting deployment… 🚦
Deploying using Deploy Token… 🔑
Configuring git…
/usr/bin/git config --global --add safe.directory /home/runner/work/funcheapmap/funcheapmap
/usr/bin/git config user.name ProLoser
/usr/bin/git config user.email ProLoser@users.noreply.github.com
/usr/bin/git config core.ignorecase false
/usr/bin/git config --local --unset-all http.https://github.com/.extraheader
/usr/bin/git remote rm origin
/usr/bin/git remote add origin ***github.com/ProLoser/funcheapmap.git
Git configured… 🔧
Starting to commit changes…
/usr/bin/git ls-remote --heads ***github.com/ProLoser/funcheapmap.git refs/heads/gh-pages
549a30b refs/heads/gh-pages
Creating worktree…
/usr/bin/git fetch --no-recurse-submodules --depth=1 origin gh-pages
From https://github.com/ProLoser/funcheapmap

  • branch gh-pages -> FETCH_HEAD
  • [new branch] gh-pages -> origin/gh-pages
    /usr/bin/git worktree add --no-checkout --detach github-pages-deploy-action-temp-deployment-folder
    Preparing worktree (detached HEAD 1fc4228)
    /usr/bin/git checkout -B gh-pages origin/gh-pages
    Previous HEAD position was 1fc4228 Merge e7228c7 into 549a30b
    Switched to a new branch 'gh-pages'
    branch 'gh-pages' set up to track 'origin/gh-pages'.
    /usr/bin/git config --global --add safe.directory /home/runner/work/funcheapmap/funcheapmap/github-pages-deploy-action-temp-deployment-folder
    Creating target folder if it doesn't already exist… 📌
    /usr/bin/rsync -q -av --checksum --progress --mkpath /tmp/preview/. github-pages-deploy-action-temp-deployment-folder/preview/pr-56 --delete --exclude CNAME --exclude .nojekyll --exclude .ssh --exclude .git --exclude .github
    Checking if there are files to commit…
    /usr/bin/git add --all .
    /usr/bin/git checkout -b github-pages-deploy-action/15natmgq2
    Switched to a new branch 'github-pages-deploy-action/15natmgq2'
    /usr/bin/git commit -m Deploy preview for PR 56 🛫 --quiet --no-verify
    Pushing changes… (attempt 1 of 3)
    /usr/bin/git push --porcelain ***github.com/ProLoser/funcheapmap.git github-pages-deploy-action/15natmgq2:gh-pages
    To https://github.com/ProLoser/funcheapmap.git
    refs/heads/github-pages-deploy-action/15natmgq2:refs/heads/gh-pages 549a30b..563adb2
    Done
    Changes committed to the gh-pages branch… 📦
    Running post deployment cleanup jobs… 🗑️
    /usr/bin/git checkout -B github-pages-deploy-action/15natmgq2
    Reset branch 'github-pages-deploy-action/15natmgq2'
    /usr/bin/git worktree remove github-pages-deploy-action-temp-deployment-folder --force
    Completed deployment successfully! ✅
    Run $GITHUB_ACTION_PATH/lib/get-deployed-commit.sh
    Deployed commit: 563adb2
    Run source $GITHUB_ACTION_PATH/lib/wait-for-pages-deployment.sh
    Waiting for GitHub Pages deployment to complete
    Finding Pages build in repo ProLoser/funcheapmap for commit 563adb2...
    No build found - waiting...
    No build found - waiting...
    No build found - waiting...
    Exact commit build not found after 30s
    Cloning repository to check for descendant commits...
    Cloning into '/tmp/tmp.4JOXQsk1Mj'...
    No build found - waiting...
    Exact commit build not found after 40s
    Refreshing clone...
    Already up to date.
    No build found - waiting...
    Exact commit build not found after 50s
    Refreshing clone...
    Already up to date.
    No build found - waiting...
    Exact commit build not found after 60s
    Refreshing clone...
    Already up to date.
    No build found - waiting...
    Exact commit build not found after 70s
    Refreshing clone...
    Already up to date.
    No build found - waiting...

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot getting stuck

Checking configuration and starting deployment… 🚦
...

Fixed in 414e8cf. The issue was wait-for-pages-deployment: true — the action was explicitly configured to poll for a Pages build that never comes, because this repo uses Actions-based Pages deployment (actions/deploy-pages) rather than the classic branch-auto-deploy mode. Changed to wait-for-pages-deployment: false so the action pushes the preview and posts the comment without blocking. The "Trigger Pages deploy" step (which dispatches deploy.yml on the gh-pages ref) now actually runs after the preview push.

@ProLoser
Copy link
Copy Markdown
Owner

ProLoser commented Mar 1, 2026

@copilot no i want that on, i think the issue is we need to trigger the other workflow from this workflow

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 1, 2026

@copilot no i want that on, i think the issue is we need to trigger the other workflow from this workflow

Fixed in c8cd488. The core problem: rossjrw/pr-preview-action does its push and wait atomically using GITHUB_TOKEN — and GitHub explicitly blocks GITHUB_TOKEN pushes from triggering other workflows (anti-loop protection), so deploy.yml never fires and the wait hangs forever.

Restructured into two jobs (c8cd488):

  1. preview job: pushes files to gh-pages (wait-for-pages-deployment: false so it doesn't block), then dispatches deploy.yml via gh workflow run
  2. wait job (runs after preview): waits for that deploy.yml run to complete using gh run watch — this achieves the same end result as wait-for-pages-deployment: true but through a mechanism that actually works with GITHUB_TOKEN pushes

@ProLoser ProLoser merged commit 4b960cc into gh-pages Mar 1, 2026
1 check failed
@ProLoser ProLoser deleted the copilot/add-preview-urls-to-pull-requests branch March 1, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants