Skip to content

fix: use github.io base path for PR preview deployment URLs#18

Merged
nschimme merged 1 commit into
MUME:masterfrom
nschimme:fix-pr-preview
May 10, 2026
Merged

fix: use github.io base path for PR preview deployment URLs#18
nschimme merged 1 commit into
MUME:masterfrom
nschimme:fix-pr-preview

Conversation

@nschimme
Copy link
Copy Markdown
Contributor

@nschimme nschimme commented May 10, 2026

Replace CNAME-reading logic with configure-pages base_path so PR preview "View Deployment" links correctly point to /pr-N/ for both the main org (which GitHub auto-redirects to the custom domain) and forked repos.

Summary by Sourcery

Update PR preview workflows to construct deployment URLs using the GitHub Pages base path instead of CNAME detection.

Bug Fixes:

  • Ensure PR preview deployment links consistently point to the correct /pr-N/ path for both main and forked repositories.

CI:

  • Simplify and standardize base URL and host resolution in deploy and pr-preview workflows to always use the github.io domain and configured base path.

Replace CNAME-reading logic with configure-pages base_path so PR preview
"View Deployment" links correctly point to /pr-N/ for both the main org
(which GitHub auto-redirects to the custom domain) and forked repos.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates GitHub Actions workflows to always construct PR preview deployment URLs using the GitHub Pages github.io base (and the configured BASE_URL_PATH/prefix) instead of inspecting a CNAME file, ensuring correct /pr-N/ links for both org and forked repositories.

Flow diagram for updated base URL and host computation in workflows

flowchart TD
  subgraph PRPreviewWorkflow["pr-preview.yml Determine Base URL Prefix"]
    A["Start"] --> B["Read github.event.repository.name as repoName"]
    B --> C["Read github.repository_owner as owner"]
    C --> D{repoName == owner.github.io?}
    D -->|Yes| E["Set prefix = /"]
    D -->|No| F["Set prefix = /repoName/"]
    E --> G["Set host = owner.github.io"]
    F --> G
    G --> H["Write prefix and host to GITHUB_OUTPUT"]
    H --> I["End"]
  end

  subgraph DeployWorkflow["deploy.yml Construct Deployment URL"]
    J["Start"] --> K["Read owner and repo from context.repo"]
    K --> L["Read BASE_URL_PATH from env as baseUrlPath"]
    L --> M["Set base = https://owner.github.io"]
    M --> N{baseUrlPath starts with /?}
    N -->|Yes| O["normalizedPath = baseUrlPath"]
    N -->|No| P["normalizedPath = / + baseUrlPath"]
    O --> Q["base = base + normalizedPath"]
    P --> Q
    Q --> R["Remove trailing / from base if present"]
    R --> S["Read PR number as prNumber"]
    S --> T["url = base + /pr-prNumber/"]
    T --> U["Log deployment URL"]
    U --> V["End"]
  end
Loading

File-Level Changes

Change Details Files
Simplify construction of deployment URLs in deploy workflow to always use the github.io host plus the configured base path.
  • Stop mutating the base URL based on a local CNAME file or repo name and instead always start from https://.github.io
  • Treat BASE_URL_PATH as required, normalize it to always be a single leading-slash path, and strip any trailing slash when composing the base URL
  • Build the final PR preview URL as /pr-/ and log it for visibility
.github/workflows/deploy.yml
Align PR preview workflow base URL and host calculation with github.io-based hosting, removing CNAME dependence.
  • Change base URL prefix logic to special-case only owner.github.io repositories, otherwise prefix with //
  • Remove reading of the CNAME file and any branching based on a custom domain
  • Always set the host output to .github.io regardless of CNAME or repository type
.github/workflows/pr-preview.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In deploy.yml, baseUrlPath is read directly from process.env.BASE_URL_PATH and then startsWith is called on it; consider defaulting to an empty string or validating it first to avoid a runtime error when the env var is unset.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In deploy.yml, `baseUrlPath` is read directly from `process.env.BASE_URL_PATH` and then `startsWith` is called on it; consider defaulting to an empty string or validating it first to avoid a runtime error when the env var is unset.

## Individual Comments

### Comment 1
<location path=".github/workflows/deploy.yml" line_range="190-194" />
<code_context>
+                const baseUrlPath = process.env.BASE_URL_PATH;
</code_context>
<issue_to_address>
**issue (bug_risk):** BASE_URL_PATH being undefined will throw at `startsWith`, consider a safe default or guard.

Since `process.env.BASE_URL_PATH` can be `undefined`, `baseUrlPath.startsWith('/')` will throw before the URL is built. Please add a safe default or guard, e.g. `const baseUrlPath = process.env.BASE_URL_PATH || '';`, and adjust the normalization so deployments without this env var still work.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +190 to +194
const baseUrlPath = process.env.BASE_URL_PATH;

let base = `https://${owner}.github.io`;

const cnamePath = 'CNAME';
if (fs.existsSync(cnamePath) && owner === 'mume') {
const domain = fs.readFileSync(cnamePath, 'utf8').trim();
if (domain) {
base = `https://${domain}`;
}
} else {
const repo = context.repo.repo;
if (repo !== `${owner}.github.io`) {
base = `${base}/${repo}`;
}
}
const normalizedPath = baseUrlPath.startsWith('/') ? baseUrlPath : `/${baseUrlPath}`;
base = `${base}${normalizedPath}`.replace(/\/$/, '');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): BASE_URL_PATH being undefined will throw at startsWith, consider a safe default or guard.

Since process.env.BASE_URL_PATH can be undefined, baseUrlPath.startsWith('/') will throw before the URL is built. Please add a safe default or guard, e.g. const baseUrlPath = process.env.BASE_URL_PATH || '';, and adjust the normalization so deployments without this env var still work.

@nschimme nschimme merged commit 3641f02 into MUME:master May 10, 2026
3 checks passed
@nschimme nschimme deleted the fix-pr-preview branch May 10, 2026 02:53
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.

1 participant