-
Notifications
You must be signed in to change notification settings - Fork 84
147 lines (138 loc) · 5.05 KB
/
deploy-test-app.yaml
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
on:
pull_request:
types:
- labeled
- opened
- reopened
- synchronize
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
deploy-test:
if: github.event.pull_request.merged == false && (contains(github.event.label.name, 'testing') || contains(github.event.pull_request.labels.*.name, 'testing'))
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/yarn-install
- name: Build project
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn build
- name: Set Project Name
run: |
export NAME=$(echo ${{ env.BRANCH_NAME }} | tr -d -c '[:alnum:]' | tr '[:upper:]' '[:lower:]')
echo "PROJECT_NAME=widget-${NAME:0:10}" >> $GITHUB_ENV
- name: Create project if not present
uses: actions/github-script@v7
with:
script: |
fetch('https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects/${{ env.PROJECT_NAME }}', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${{ secrets.CF_PAGES_API_TOKEN }}'
},
})
.then(r => r.json())
.then(r => {
if (r.success) {
// project already created
return
} else if (r.error) {
console.log(r)
process.exit(1)
}
fetch('https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${{ secrets.CF_PAGES_API_TOKEN }}'
},
body: JSON.stringify({
build_config: {
build_command: "yarn run build",
destination_dir: "packages/widget-playground-vite/dist/",
root_dir: "/",
},
canonical_deployment: null,
deployment_configs: {
preview: {
analytics_engine_datasets: {
ANALYTICS_ENGINE_BINDING: {
dataset: "api_analytics"
}
},
compatibility_date: "2022-01-01",
compatibility_flags: [
"url_standard"
],
placement: {
mode: "smart"
},
},
production: {
analytics_engine_datasets: {
ANALYTICS_ENGINE_BINDING: {
dataset: "api_analytics"
}
},
compatibility_date: "2022-01-01",
compatibility_flags: [
"url_standard"
],
placement: {
mode: "smart"
},
}
},
latest_deployment: null,
name: "${{ env.PROJECT_NAME }}",
production_branch: "${{ env.BRANCH_NAME }}"
})
})
.then(r => r.json())
.then(r => {
if (!r?.success) {
console.log(r)
process.exit(1)
}
})
})
- name: Deploy Page
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_PAGES_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: |
pages deploy ./packages/widget-playground-vite/dist/ --project-name ${{ env.PROJECT_NAME }} --branch ${{ env.BRANCH_NAME }}
- name: Comment Test Endpoint
uses: actions/github-script@v7
with:
script: |
fetch("https://api.cloudflare.com/client/v4/accounts/${{ secrets.CF_ACCOUNT_ID }}/pages/projects/${{ env.PROJECT_NAME }}/deployments", {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${{ secrets.CF_PAGES_API_TOKEN }}'
}
})
.then((r) => r.json())
.then((r) => {
if (!r.success) {
console.log(r)
process.exit(1)
}
const obj = r.result[0]
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Hey! This is your new endopint: [${obj.url}](${obj.url})`
})
})