From fac58801f9cc77214ae4ee3c8e29a14e29b7d66b Mon Sep 17 00:00:00 2001 From: nschimme <5505185+nschimme@users.noreply.github.com> Date: Tue, 5 May 2026 14:12:14 +0000 Subject: [PATCH 1/2] fix: prevent forks from using docs.mume.org domain for deployments Modified GitHub workflows and environment scripts to conditionally use the root CNAME file only when the repository owner is 'mume'. This ensures that forked repositories correctly generate deployment links pointing to their own GitHub Pages domain (.github.io/) rather than the official MUME domain. Specifically: - Updated .github/workflows/pr-preview.yml to use owner-aware host detection. - Updated .github/workflows/deploy.yml to conditionally copy CNAME and set deployment URLs. - Updated scripts/ci-env.sh to dynamically resolve VITE_HOSTNAME based on repo ownership. --- .github/workflows/deploy.yml | 4 ++-- .github/workflows/pr-preview.yml | 2 +- scripts/ci-env.sh | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 219ff27..1b8e872 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,7 +51,7 @@ jobs: - name: Build run: | npm run build - if [ -f CNAME ]; then cp CNAME dist/CNAME; fi + if [ -f CNAME ] && [ "${{ github.repository_owner }}" = "mume" ]; then cp CNAME dist/CNAME; fi env: VITE_BASE: ${{ steps.pages.outputs.base_path }}/ @@ -192,7 +192,7 @@ jobs: let base = `https://${owner}.github.io`; const cnamePath = 'CNAME'; - if (fs.existsSync(cnamePath)) { + if (fs.existsSync(cnamePath) && owner === 'mume') { const domain = fs.readFileSync(cnamePath, 'utf8').trim(); if (domain) { base = `https://${domain}`; diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 02c4351..af1fc52 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -29,7 +29,7 @@ jobs: - name: Determine Base URL Prefix id: base_url run: | - if [ -f CNAME ]; then + if [ -f CNAME ] && [ "${{ github.repository_owner }}" = "mume" ]; then echo "prefix=/" >> $GITHUB_OUTPUT echo "host=$(cat CNAME)" >> $GITHUB_OUTPUT elif [ "${{ github.event.repository.name }}" = "${{ github.repository_owner }}.github.io" ]; then diff --git a/scripts/ci-env.sh b/scripts/ci-env.sh index e3f5e48..a0d3a06 100755 --- a/scripts/ci-env.sh +++ b/scripts/ci-env.sh @@ -5,14 +5,23 @@ export VITE_LAST_UPDATED=$(git log -1 --format=%cd --date=format:'%B %Y') echo "VITE_LAST_UPDATED=$VITE_LAST_UPDATED" >> $GITHUB_ENV # Set VITE_HOSTNAME from CNAME file if it exists -if [ -f CNAME ]; then +if [ -f CNAME ] && [ "$GITHUB_REPOSITORY_OWNER" = "mume" ]; then export VITE_HOSTNAME="https://$(cat CNAME)" else # Fallback for PR previews if host/prefix are provided via env if [ -n "$PREVIEW_HOST" ]; then export VITE_HOSTNAME="https://${PREVIEW_HOST}${PREVIEW_PREFIX}" else - export VITE_HOSTNAME="https://docs.mume.org" + # Fallback for forks or main repo without CNAME + OWNER="${GITHUB_REPOSITORY_OWNER:-mume}" + REPO=$(echo "${GITHUB_REPOSITORY:-mume/docs}" | cut -d'/' -f2) + if [ "$OWNER" = "mume" ] && [ "$REPO" = "docs" ]; then + export VITE_HOSTNAME="https://docs.mume.org" + elif [ "$REPO" = "$OWNER.github.io" ]; then + export VITE_HOSTNAME="https://$OWNER.github.io" + else + export VITE_HOSTNAME="https://$OWNER.github.io/$REPO" + fi fi fi echo "VITE_HOSTNAME=$VITE_HOSTNAME" >> $GITHUB_ENV From c00a9406245192f20a7a459b5b8ff008beaae163 Mon Sep 17 00:00:00 2001 From: nschimme <5505185+nschimme@users.noreply.github.com> Date: Tue, 5 May 2026 14:18:18 +0000 Subject: [PATCH 2/2] fix: correct deployment links for forked repositories and remove redundant PR comments This commit ensures that forked repositories correctly use their GitHub Pages URL (.github.io/) for deployments and PR previews, rather than the official MUME domain. Key changes: - Updated `.github/workflows/pr-preview.yml` and `.github/workflows/deploy.yml` to only use the `CNAME` file and the `docs.mume.org` domain if the repository owner is 'mume'. - Aligned URL construction logic across workflows and `scripts/ci-env.sh` for consistency. - Removed the redundant "Build ready" bot comment from PRs in favor of the native GitHub deployment status button. - Improved environment variable defaulting in `scripts/ci-env.sh` for better robustness. --- .github/workflows/deploy.yml | 6 ++++-- .github/workflows/pr-preview.yml | 24 ------------------------ scripts/ci-env.sh | 2 +- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1b8e872..4c25032 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -198,8 +198,10 @@ jobs: base = `https://${domain}`; } } else { - const normalizedPath = baseUrlPath.startsWith('/') ? baseUrlPath : `/${baseUrlPath}`; - base = `${base}${normalizedPath}`.replace(/\/$/, ''); + const repo = context.repo.repo; + if (repo !== `${owner}.github.io`) { + base = `${base}/${repo}`; + } } const url = `${base}/pr-${pr.number}/`; diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index af1fc52..c8527b2 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -62,27 +62,3 @@ jobs: name: pr-${{ github.event.number }} path: pr-${{ github.event.number }}.zip retention-days: 30 - - - name: Comment build status - uses: actions/github-script@v9 - env: - PREVIEW_URL: https://${{ steps.base_url.outputs.host }}${{ steps.base_url.outputs.prefix }}pr-${{ github.event.number }}/ - with: - script: | - const pr = context.payload.number - const owner = context.repo.owner - const repo = context.repo.repo - const url = process.env.PREVIEW_URL - const body = `### Build ready\n\nThe build for this PR has been completed successfully. A live preview will be available at: ${url}` - - const { data: comments } = await github.rest.issues.listComments({ - owner, repo, issue_number: pr, - }) - const existing = comments.find(c => - c.user.login === 'github-actions[bot]' && c.body.includes('Build ready') - ) - if (existing) { - await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }) - } else { - await github.rest.issues.createComment({ owner, repo, issue_number: pr, body }) - } diff --git a/scripts/ci-env.sh b/scripts/ci-env.sh index a0d3a06..c280ee9 100755 --- a/scripts/ci-env.sh +++ b/scripts/ci-env.sh @@ -14,7 +14,7 @@ else else # Fallback for forks or main repo without CNAME OWNER="${GITHUB_REPOSITORY_OWNER:-mume}" - REPO=$(echo "${GITHUB_REPOSITORY:-mume/docs}" | cut -d'/' -f2) + REPO=$(echo "${GITHUB_REPOSITORY:-${OWNER}/docs}" | cut -d'/' -f2) if [ "$OWNER" = "mume" ] && [ "$REPO" = "docs" ]; then export VITE_HOSTNAME="https://docs.mume.org" elif [ "$REPO" = "$OWNER.github.io" ]; then