Repository navigation
115 lines (112 loc) · 4.21 KB
/
Copy pathcd.yml
File metadata and controls
115 lines (112 loc) · 4.21 KB
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
name: CD
on:
push:
branches:
- '**'
jobs:
deploy:
name: Deploy to Cloudflare Workers
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: '.node-version'
package-manager-cache: false
- name: Install dependencies
run: npm ci
- name: Build app
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: npm run build
- name: Deploy to Cloudflare Workers
id: deploy
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy
- name: Post commit status
if: always()
env:
DEPLOY_OUTCOME: ${{ steps.deploy.outcome }}
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$DEPLOY_OUTCOME" = "success" ]; then
STATE="success"
DESCRIPTION="Deployed to Cloudflare Workers"
else
STATE="failure"
DESCRIPTION="Cloudflare Workers deployment failed"
fi
PAYLOAD=$(jq -n \
--arg state "$STATE" \
--arg target_url "$DEPLOY_URL" \
--arg description "$DESCRIPTION" \
--arg context "cloudflare-workers/production" \
'{state: $state, target_url: $target_url, description: $description, context: $context}')
curl -sS -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}" \
-d "$PAYLOAD"
preview:
name: Deploy preview to Cloudflare Workers
if: github.ref != 'refs/heads/dev'
runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: '.node-version'
package-manager-cache: false
- name: Install dependencies
run: npm ci
- name: Build app
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: npm run build
- name: Upload preview version to Cloudflare Workers
id: deploy
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: versions upload --message "Preview for ${{ github.ref_name }}"
- name: Post commit status
if: always()
env:
DEPLOY_OUTCOME: ${{ steps.deploy.outcome }}
PREVIEW_URL: ${{ steps.deploy.outputs.deployment-url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$DEPLOY_OUTCOME" = "success" ]; then
STATE="success"
DESCRIPTION="Preview version deployed to Cloudflare Workers"
else
STATE="failure"
DESCRIPTION="Cloudflare Workers preview deployment failed"
fi
PAYLOAD=$(jq -n \
--arg state "$STATE" \
--arg target_url "$PREVIEW_URL" \
--arg description "$DESCRIPTION" \
--arg context "cloudflare-workers/preview" \
'{state: $state, target_url: $target_url, description: $description, context: $context}')
curl -sS -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}" \
-d "$PAYLOAD"