-
Notifications
You must be signed in to change notification settings - Fork 5
61 lines (58 loc) · 1.99 KB
/
preview.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
name: PR Preview on Cloudflare Pages
on:
workflow_run:
workflows: ["Build"]
types: ["completed"]
permissions:
actions: read
pull-requests: write
jobs:
preview:
name: Preview
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.conclusion == 'success'
steps:
- name: Download dist
uses: actions/github-script@v7
with:
script: |
var artifact = (await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
})).data.artifacts.find(x => x.name == "dist");
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/dist.zip', Buffer.from(download.data));
- name: Extract dist archive
run: |
unzip dist.zip
echo "pr=$(cat .pr)" >> $GITHUB_ENV
- name: Publish preview to Cloudflare Pages
id: publish
uses: cloudflare/pages-action@v1
with:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
projectName: academy-admin-preview
directory: dist
branch: ${{ format('pr-{0}', env.pr) }}
- name: Prepare comment
run: |
url="${{ steps.publish.outputs.url }}"
size=$(du -sh dist | cut -f1)
echo "**Preview deployed to ${url}** (total size: ${size})" > comment
- name: Comment preview url
uses: thollander/actions-comment-pull-request@v2
with:
filePath: comment
pr_number: ${{ env.pr }}
comment_tag: preview
mode: recreate