Skip to content

Commit 17b47ea

Browse files
authored
PRごとにPreview環境を作成する (#235)
* PRごとにPreview環境を作成する * test * 1つのコメントを編集する * test * Revert "test" This reverts commit cb7bb5f. * Revert "test" This reverts commit 577ea06. * concurrencyの設定
1 parent 5c3ce40 commit 17b47ea

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: cleanup-preview
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
cleanup-preview:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
ref: gh-pages
14+
15+
- name: Remove preview directory
16+
run: |
17+
if [ -d "pr-${{ github.event.pull_request.number }}" ]; then
18+
git config user.name github-actions[bot]
19+
git config user.email github-actions[bot]@users.noreply.github.com
20+
git rm -rf pr-${{ github.event.pull_request.number }}
21+
git commit -m "Remove preview for PR #${{ github.event.pull_request.number }}"
22+
git push
23+
else
24+
echo "Preview directory not found, skipping cleanup"
25+
fi

.github/workflows/preview.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: deploy-preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
concurrency:
8+
group: preview-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
deploy-preview:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: true
18+
fetch-depth: 0
19+
20+
- name: Setup Hugo
21+
uses: peaceiris/actions-hugo@v3
22+
with:
23+
hugo-version: "0.115.1"
24+
extended: true
25+
26+
- name: Build
27+
run: hugo --baseURL https://blog.kyu08.com/pr-${{ github.event.pull_request.number }}/
28+
29+
- name: Deploy to GitHub Pages
30+
uses: peaceiris/actions-gh-pages@v4
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
publish_dir: ./public
34+
destination_dir: pr-${{ github.event.pull_request.number }}
35+
keep_files: true
36+
cname: blog.kyu08.com
37+
38+
- name: Find Comment
39+
uses: peter-evans/find-comment@v3
40+
id: fc
41+
with:
42+
issue-number: ${{ github.event.pull_request.number }}
43+
comment-author: 'github-actions[bot]'
44+
body-includes: プレビュー環境
45+
46+
- name: Create or update comment
47+
uses: peter-evans/create-or-update-comment@v3
48+
with:
49+
comment-id: ${{ steps.fc.outputs.comment-id }}
50+
issue-number: ${{ github.event.pull_request.number }}
51+
body: |
52+
## プレビュー環境
53+
54+
プレビュー環境が更新されました。
55+
56+
**URL:** https://blog.kyu08.com/pr-${{ github.event.pull_request.number }}/
57+
58+
**Commit:** [`${{ github.event.pull_request.head.sha }}`](${{ github.event.repository.html_url }}/commit/${{ github.event.pull_request.head.sha }})
59+
60+
※ デプロイ完了まで数分かかる場合があります。
61+
edit-mode: replace

0 commit comments

Comments
 (0)