-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (116 loc) · 4.17 KB
/
deploy.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: "Deploy"
on:
workflow_run:
workflows: ["Build"]
types:
- completed
jobs:
production:
runs-on: ubuntu-latest
permissions:
deployments: write
if: >
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master'
steps:
- name: Download artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data));
- name: Extract artifact
run: |
mkdir result
unzip artifact.zip -d result
- name: Deploy to nix.dev
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
directory: ./result
branch: main
preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifact
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data));
- name: Extract artifact
run: unzip artifact.zip
- name: Retrieve PR number
id: pr
run: echo "id=$(cat .github/pr)" >> $GITHUB_OUTPUT
- name: Deploy preview
id: deploy
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: ./result
branch: pr-${{ steps.pr.outputs.id }}
- name: Create comment on PR
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ steps.pr.outputs.id }}
edit-mode: replace
body: |
<!-- Deploy Preview Comment -->
# Deploy Preview
<table>
<tr>
<th>Name</th>
<th>Result</th>
</tr>
<tr>
<td><b>Last commit:</b></td>
<td>
<a href='https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}'>
<code>${{ github.event.workflow_run.head_sha }}</code>
</a>
</td>
<tr>
<tr>
<td><b>Preview URL:</b></td>
<td><a href='${{ steps.deploy.outputs.url }}'>${{ steps.deploy.outputs.url }}</td>
</table>