-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (89 loc) · 3.51 KB
/
Copy pathdeploy.yml
File metadata and controls
103 lines (89 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Deploy
on:
push:
branches: [main]
# 사이트에 적힌 수집량은 백엔드가 매주 새로 받아 온다. 다시 빌드해야 반영된다.
schedule:
- cron: '0 20 * * 1' # 매주 화요일 05:00 KST (어린이집·유치원 동기화 이후)
workflow_dispatch:
# 배포는 한 번에 하나만. 뒤에 들어온 것이 이기게 두면 낡은 빌드가 최종본이 될 수 있다.
concurrency:
group: pages
cancel-in-progress: false
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
name: 정적 파일 생성
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: 의존성 설치
run: npm ci
- uses: actions/configure-pages@v5
id: pages
- name: 빌드
# 프로젝트 페이지는 /<저장소명> 아래에 붙는다. basePath 가 없으면 CSS·JS 가 전부 404 다.
env:
NEXT_PUBLIC_BASE_PATH: ${{ steps.pages.outputs.base_path }}
NEXT_PUBLIC_SITE_URL: ${{ steps.pages.outputs.base_url }}
run: npm run build
- uses: actions/upload-pages-artifact@v3
with:
path: out
deploy:
name: Pages 배포
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/deploy-pages@v4
id: deployment
smoke:
name: 배포 후 확인
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# 배포가 성공했다는 것과 사이트가 실제로 뜬다는 것은 다르다.
# 파일이 올라갔는데 basePath 가 어긋나 CSS 가 404 인 경우가 대표적이다.
- name: 페이지 응답 확인
env:
SITE: ${{ needs.deploy.outputs.page_url || format('https://{0}.github.io/{1}/', github.repository_owner, github.event.repository.name) }}
run: |
base="${SITE%/}"
fail=0
for path in "/" "/benefits/" "/facilities/" "/data/" "/trust/" "/sitemap.xml" "/robots.txt"; do
code=$(curl -sS -o /dev/null -w '%{http_code}' --retry 5 --retry-delay 5 --retry-all-errors "$base$path")
printf ' %-16s %s\n' "$path" "$code"
[ "$code" = "200" ] || fail=1
done
# 스타일이 붙었는지까지 봐야 의미가 있다. basePath 가 어긋나면 여기서 걸린다.
#
# href 는 "/CareCode_Landing/_next/..." 처럼 basePath 를 이미 포함한 루트 절대경로다.
# base 에 그대로 붙이면 basePath 가 두 번 들어가 멀쩡한 사이트도 404 로 보인다.
# 검사가 오탐을 내면 사람이 검사를 무시하게 되므로 도메인 원점에 붙인다.
origin=$(printf '%s' "$base" | sed -E 's#^(https?://[^/]+).*#\1#')
css=$(curl -sS "$base/" | grep -oE 'href="[^"]+\.css"' | head -1 | sed -E 's/href="([^"]+)"/\1/')
if [ -n "$css" ]; then
case "$css" in
http*) css_url="$css" ;;
/*) css_url="$origin$css" ;;
*) css_url="$base/$css" ;;
esac
code=$(curl -sS -o /dev/null -w '%{http_code}' "$css_url")
printf ' %-16s %s\n' "css" "$code"
[ "$code" = "200" ] || { echo " $css_url"; fail=1; }
else
echo " css 링크를 찾지 못했습니다"
fail=1
fi
exit $fail