-
Notifications
You must be signed in to change notification settings - Fork 357
89 lines (79 loc) · 2.93 KB
/
docs-preview.yml
File metadata and controls
89 lines (79 loc) · 2.93 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
name: Docs Preview
on:
pull_request:
paths:
- "docs/**"
types: [opened, synchronize, reopened, closed]
concurrency:
group: docs-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
build-and-deploy:
if: >-
github.event.pull_request.head.repo.full_name == github.repository
&& github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
environment:
name: github-pages
url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Ruby
uses: ruby/setup-ruby@e5517072e87f198d9533967ae13d97c11b604005 # v1.99.0
with:
ruby-version: "3.3"
working-directory: docs
- name: Install dependencies
run: bundle install
working-directory: docs
- name: Build Jekyll site
run: bundle exec jekyll build --baseurl "/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}"
working-directory: docs
env:
JEKYLL_ENV: production
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_site
destination_dir: pr-${{ github.event.pull_request.number }}
comment:
needs: build-and-deploy
if: >-
github.event.pull_request.head.repo.full_name == github.repository
&& github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Comment preview URL
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
header: docs-preview
message: |
📖 **Docs preview**: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.pull_request.number }}/
cleanup:
if: >-
github.event.pull_request.head.repo.full_name == github.repository
&& github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
- name: Remove preview directory
run: |
PR_DIR="pr-${{ github.event.pull_request.number }}"
if [ -d "$PR_DIR" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git rm -rf "$PR_DIR"
git commit -m "chore: remove docs preview for PR #${{ github.event.pull_request.number }}"
git push
fi