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

on:
workflow_dispatch:

permissions:
contents: write

jobs:
bootstrap:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create gh-pages branch if missing
shell: bash
run: |
set -euo pipefail
git fetch --all

if git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
echo "gh-pages branch already exists; nothing to do."
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git checkout --orphan gh-pages
git rm -rf . >/dev/null 2>&1 || true

cat > index.html <<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Marcus Astro Pages Bootstrap</title>
</head>
<body>
<p>GitHub Pages bootstrap branch created. Deploy workflows will replace this content.</p>
</body>
</html>
HTML

touch .nojekyll
git add index.html .nojekyll
git commit -m "Bootstrap gh-pages branch"
git push origin gh-pages
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
pull_request:
push:
branches: [main, master, dev, work]

permissions:
contents: read

jobs:
quality:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Astro
uses: withastro/action@v3
with:
path: .
node-version: 20
package-manager: npm

- name: Type/content check
run: npm run check

- name: Build site
run: npm run build
54 changes: 54 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy development site

on:
push:
branches: [dev]
workflow_dispatch:
inputs:
ref:
description: 'Branch/tag/SHA to deploy as preview'
required: false
default: 'dev'

permissions:
contents: write

env:
PAGES_BRANCH: gh-pages

concurrency:
group: deploy-dev
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: dev

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref || 'dev' }}

- name: Setup Astro
uses: withastro/action@v3
with:
path: .
node-version: 20
package-manager: npm

- name: Build development preview site
run: npm run build

- name: Add .nojekyll for GitHub Pages
run: touch dist/.nojekyll

- name: Deploy to pages branch /preview
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ${{ env.PAGES_BRANCH }}
folder: dist
target-folder: preview
clean: true
47 changes: 47 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy production site

on:
push:
branches: [main, master]
workflow_dispatch:

permissions:
contents: write

env:
PAGES_BRANCH: gh-pages

concurrency:
group: deploy-prod
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: prod

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Astro
uses: withastro/action@v3
with:
path: .
node-version: 20
package-manager: npm

- name: Build production site
run: npm run build

- name: Add .nojekyll for GitHub Pages
run: touch dist/.nojekyll

- name: Deploy to pages branch root
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ${{ env.PAGES_BRANCH }}
folder: dist
clean: true
clean-exclude: preview
129 changes: 129 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Preview on Pull Request

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write
pull-requests: write

concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
PAGES_BRANCH: gh-pages

jobs:
preview-deploy:
runs-on: ubuntu-latest
env:
DEPLOY_TARGET: pr
DEPLOY_PREVIEW_PATH: pr-${{ github.event.pull_request.number }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Ensure gh-pages branch exists
shell: bash
run: |
set -euo pipefail
git fetch --all
if git ls-remote --exit-code --heads origin "$PAGES_BRANCH" >/dev/null 2>&1; then
echo "Branch $PAGES_BRANCH exists"
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout --orphan "$PAGES_BRANCH"
git rm -rf . >/dev/null 2>&1 || true
printf '<!doctype html><title>Bootstrap</title><p>Preview bootstrap.</p>' > index.html
touch .nojekyll
git add index.html .nojekyll
git commit -m "Bootstrap gh-pages for previews"
git push origin "$PAGES_BRANCH"

- name: Setup Astro
uses: withastro/action@v3
with:
path: .
node-version: 20
package-manager: npm

- name: Build site
run: npm run build

- name: Add .nojekyll for GitHub Pages
run: touch dist/.nojekyll

- name: Deploy PR preview to gh-pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ${{ env.PAGES_BRANCH }}
folder: dist
target-folder: preview/pr-${{ github.event.pull_request.number }}
clean: true

- name: Verify preview URL is reachable
shell: bash
env:
PREVIEW_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/preview/pr-${{ github.event.pull_request.number }}/
run: |
set -euo pipefail
echo "Checking $PREVIEW_URL"
for i in $(seq 1 20); do
code=$(curl -s -o /dev/null -w "%{http_code}" "$PREVIEW_URL" || true)
if [ "$code" = "200" ]; then
echo "Preview is live"
exit 0
fi
echo "Attempt $i/20: HTTP $code, retrying in 15s..."
sleep 15
done
echo "Preview did not become reachable in time"
exit 1

- name: Comment preview URL on PR
if: success()
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request.number;
const url = `https://${context.repo.owner}.github.io/${context.repo.repo}/preview/pr-${pr}/`;
const body = [
'🔍 PR preview is ready.',
'',
`**Open preview:** ${url}`
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body
});

- name: Comment failure help on PR
if: failure()
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request.number;
const body = [
'❌ PR preview deployment finished but URL was not reachable in time.',
'',
'Please check **Settings → Pages**:',
'- Source: `Deploy from a branch`',
'- Branch: `gh-pages`',
'- Folder: `/(root)`',
'',
'Then re-run the `Preview on Pull Request` workflow.'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body
});
1 change: 1 addition & 0 deletions .nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# presence of this file disables Jekyll processing on GitHub Pages
Loading