Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}/

Expand Down Expand Up @@ -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}/`;
Expand Down
26 changes: 1 addition & 25 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
}
13 changes: 11 additions & 2 deletions scripts/ci-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading