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
194 changes: 194 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
name: deploy-pages

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]

permissions:
contents: read

jobs:
deploy-main:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
concurrency:
group: deploy-pages-gh-pages
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: true
fetch-depth: 0
- uses: pnpm/action-setup@v6
with:
version: 11
- uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm test
- run: pnpm build -- --base=/loop-protocol/
- name: Deploy to gh-pages (replace root, preserve pr-*)
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Check if gh-pages branch exists
if git ls-remote --exit-code origin gh-pages; then
git fetch origin gh-pages
git worktree add /tmp/gh-pages origin/gh-pages
else
# Create orphan gh-pages branch
git worktree add --orphan -b gh-pages /tmp/gh-pages
fi

# Sync dist/ to gh-pages root, deleting stale root files but preserving pr-* dirs
rsync -a --delete \
--exclude '.git' \
--exclude 'pr-*' \
dist/ /tmp/gh-pages/

cd /tmp/gh-pages
git add -A
if git diff --cached --quiet; then
echo "No changes to deploy."
else
git commit -m "chore: deploy main to gh-pages"
git push origin HEAD:gh-pages
fi

deploy-pr:
if: >-
github.event_name == 'pull_request' &&
github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository
concurrency:
group: deploy-pages-gh-pages
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: pnpm/action-setup@v6
with:
version: 11
- uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm test
- run: pnpm build -- --base=/loop-protocol/pr-${{ github.event.number }}/
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
keep_files: true
destination_dir: pr-${{ github.event.number }}
- name: Comment preview URL on PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://squne121.github.io/loop-protocol/pr-${prNumber}/`;

// Live check: verify the preview URL is actually reachable (best-effort)
let liveCheckPassed = false;
try {
const { execSync } = require('child_process');
execSync(
`curl -fsSL --retry 5 --retry-delay 10 --max-time 90 -o /dev/null -w "%{http_code}" "${previewUrl}" | grep -q "^200$"`,
{ stdio: 'inherit' }
);
liveCheckPassed = true;
} catch (_) {
// best-effort: live check failed, but do not fail the workflow
}

const marker = '<!-- loop-protocol-pr-preview -->';
const body = liveCheckPassed
? `${marker}\n## Preview URL\n\n✅ verified live: ${previewUrl}\n\n> The preview will be removed when this PR is closed.`
: `${marker}\n## Preview URL\n\n⏳ publish requested(live URL 未検証 / Pages source 設定後に有効化): ${previewUrl}\n\n> Pages source の設定が必要な場合: Settings → Pages → Source → gh-pages (root)\n> The preview will be removed when this PR is closed.`;

// Upsert: update existing bot comment if present, otherwise create
// Use paginate to scan all pages of comments
const allComments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
}
);
const existing = allComments.find(
c => c.user.login === 'github-actions[bot]' && c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}

cleanup-pr:
if: >-
github.event_name == 'pull_request' &&
github.event.action == 'closed'
concurrency:
group: deploy-pages-gh-pages
cancel-in-progress: false
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check if gh-pages branch exists
id: check-branch
run: |
if git ls-remote --exit-code origin gh-pages; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v6
if: steps.check-branch.outputs.exists == 'true'
with:
ref: gh-pages
persist-credentials: true
- name: Remove PR preview directory
if: steps.check-branch.outputs.exists == 'true'
run: |
PR_DIR="pr-${{ github.event.number }}"
if [ -d "$PR_DIR" ]; then
git rm -rf "$PR_DIR"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: remove preview for PR #${{ github.event.number }}"
git push
else
echo "Directory $PR_DIR not found, nothing to clean up."
fi
- name: Skip cleanup (gh-pages branch not found)
if: steps.check-branch.outputs.exists == 'false'
run: echo "gh-pages branch does not exist yet; no-op cleanup."
64 changes: 64 additions & 0 deletions docs/playtest/manual-playtest-runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,70 @@ date: "2026-06-02"

# Manual Playtest Runbook — WSL2/Ubuntu

## Online Playtest URLs (GitHub Pages)

You can run a manual playtest directly from a browser without any local setup.

### Main (shared) URL

After a commit is merged to `main`, the latest build is published to:

```
https://squne121.github.io/loop-protocol/
```

### PR Preview URL

When a pull request is opened or updated, a preview is deployed to:

```
https://squne121.github.io/loop-protocol/pr-<PR番号>/
```

Replace `<PR番号>` with the numeric PR number. For example, PR #123 becomes:
`https://squne121.github.io/loop-protocol/pr-123/`

The preview URL is also posted as a comment on the PR automatically.

> **Note:** The PR preview is automatically removed when the PR is closed.
> After the cleanup workflow completes successfully, the preview URL (`/pr-<PR番号>/`) will return 404.

> **Note:** PR preview is only generated for same-repository PRs. PRs opened from
> forks do not receive a preview deployment.

### Prerequisites (first-time setup by repo maintainer)

GitHub Pages must be configured to serve from the `gh-pages` branch:
`Settings -> Pages -> Source -> Deploy from a branch -> gh-pages (root)`

This is a one-time manual step by the repository owner. After setup, all deploys are automated.

### Stale Artifact Inspection (gh-pages branch maintenance)

The main deploy workflow replaces only the root application files while preserving `pr-*` preview
directories. If stale files accumulate in the `gh-pages` branch root (e.g., from a previous deploy
strategy), clean them up manually:

```bash
# Clone gh-pages branch locally
git clone --branch gh-pages --single-branch https://github.com/squne121/loop-protocol.git gh-pages-work
cd gh-pages-work

# Inspect root contents (should only contain current Vite output + pr-* dirs)
ls -la

# If unexpected files exist (old hashed assets, orphaned HTML files, etc.),
# remove them and push:
git rm <stale-file>
git commit -m "chore: remove stale artifact from gh-pages root"
git push origin gh-pages
```

Automated deploys via the `deploy-main` job use `rsync --delete` semantics for the root,
so future deploys will not re-introduce previously removed files.

---

This runbook guides a human tester through a manual playtest session on WSL2/Ubuntu.
Follow steps in order. If any step fails, refer to the [Troubleshooting](#common-failure-cases-and-remedies) section.

Expand Down
Loading