-
Notifications
You must be signed in to change notification settings - Fork 141
97 lines (85 loc) · 3.23 KB
/
preview-site.yml
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
name: Deploy Preview Site
on:
pull_request_target:
types:
- labeled
permissions:
contents: read
pull-requests: write
jobs:
deploy:
name: Deploy to Cloudflare Pages
if: github.event.label.name == 'request-preview-deployment'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }} # Potentially dangerous, shouldn't be used without the label trigger
ref: ${{ github.event.pull_request.head.ref }} # Potentially dangerous, shouldn't be used without the label trigger
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.117.0'
- name: Build site
run: hugo
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: 'public/'
branch: ${{ github.event.pull_request.head.ref }}
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Preview Environment
- name: Create comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
**✅ Preview Environment Ready!**
| Name | Link |
| --- | --- |
| :link: Preview Url | ${{ steps.deploy.outputs.alias }} |
Please verify everything looks as expected.
reactions: rocket
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
**✅ Preview Environment was deployed again!**
| Name | Link |
| --- | --- |
| :link: Preview Url | ${{ steps.deploy.outputs.alias }} |
| :hammer: Latest Commit | ${{ github.event.pull_request.head.sha }} |
| :clock10: Latest Deploy | ${{ github.event.pull_request.updated_at }} |
Please verify everything looks as expected.
reactions: hooray
edit-mode: 'replace'
- name: Remove Label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const labelToRemove = 'request-preview-deployment';
github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
name: labelToRemove
});