diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 219ff27..4c25032 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,14 +192,16 @@ 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}`; } } 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 02c4351..c8527b2 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 @@ -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 e3f5e48..c280ee9 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:-${OWNER}/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