-
Notifications
You must be signed in to change notification settings - Fork 32
75 lines (64 loc) · 2.28 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
70
71
72
73
74
75
name: Publish preview on CF Pages
on:
pull_request_target:
permissions:
contents: read
pages: write
id-token: write
issues: write
pull-requests: write
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Deno environment
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Build site
run: deno task build
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
- name: Deploy to CF Pages
id: deploy-preview
uses: cloudflare/wrangler-action@v3
env:
API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
with:
apiToken: ${{ env.API_TOKEN }}
accountId: ${{ env.ACCOUNT_ID }}
command: pages deploy 'target' --project-name=${{ github.event.repository.name }} --branch=${{ BRANCH_NAME }}
- name: Report preview environment in PR
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_PAT }}
script: |
let comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
let previousComment = comments.data.find((i) => i.user.login === "probe-rs-bot");
if(!previousComment) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})'
})
} else {
await github.rest.issues.updateComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previousComment.id,
body: '# [Preview](${{ steps.deploy-preview.outputs.alias }})'
})
}