-
Notifications
You must be signed in to change notification settings - Fork 7
69 lines (65 loc) · 2.37 KB
/
deploy-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
62
63
64
65
66
67
68
69
# Deploy preview to Cloudflare Pages
name: Deploy preview
on:
workflow_run:
workflows: ["Build preview"]
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
permissions: write-all
steps:
- name: Download artifact
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data));
- run: unzip build.zip -d build
- name: Deploy preview to Cloudflare Pages
id: deploy
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: wiki
directory: build
gitHubToken: ${{ secrets.GITHUB_TOKEN }} # GitHub Deployments
wranglerVersion: "3"
- name: Find PR number
id: find_pr_number
run: |
echo "pr_number=$(cat ./build/PR_NR)" >> $GITHUB_OUTPUT
- name: Find comment
uses: peter-evans/find-comment@v2
id: find_comment
with:
issue-number: ${{ steps.find_pr_number.outputs.pr_number }}
comment-author: "github-actions[bot]"
body-includes: "Preview URL:"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ steps.find_pr_number.outputs.pr_number }}
body: |
Preview URL: ${{ steps.deploy.outputs.alias }} :rocket:
edit-mode: replace