Astro로 블로그 다시 만들기 2: GitHub Pages 배포

1편에서 콘텐츠 모델을 정했다. 이번에는 main 브랜치에 푸시하는 것만으로 사이트가 배포되도록 파이프라인을 만든다.

Pages 소스 전환

GitHub Pages는 브랜치(legacy) 또는 GitHub Actions를 소스로 쓸 수 있다. actions/deploy-pages는 소스가 GitHub Actions일 때만 동작하므로 먼저 전환한다.

gh api -X PUT repos/thilllon/thilllon.github.io/pages -f build_type=workflow

배포 워크플로

공식 withastro/action이 lockfile을 보고 패키지 매니저를 고르고, build 스크립트를 실행한 뒤 Pages artifact를 올린다.

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

빌드 스크립트

검색 인덱스는 빌드 직후 만든다. 로컬, CI, 배포가 모두 같은 명령을 쓴다.

{
	"scripts": {
		"build": "astro build && pagefind --site dist"
	}
}

배포 확인

배포가 끝나면 홈, 글 페이지, /rss.xml, /sitemap-index.xml이 열리는지 확인한다.