-
-
Notifications
You must be signed in to change notification settings - Fork 50
155 lines (135 loc) · 5.38 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
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
148
149
150
151
152
153
154
155
name: Deploy
on:
push:
workflow_dispatch:
repository_dispatch:
jobs:
infra:
runs-on: ubuntu-latest
name: Infrastructure
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js LTS
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- name: Use Terraform
uses: hashicorp/setup-terraform@v3
- name: Retrieve Terraform State
uses: cloudflare/[email protected]
with:
command: --version
preCommands: npx wrangler kv:namespace list | jq -r '.[] | select( .title == "dispoflare-terraform-state" ) | .id' | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Init Terraform
run: terraform init
working-directory: ./.terraform
- name: Download Terraform State
uses: cloudflare/[email protected]
with:
command: --version
preCommands: npx wrangler kv:key get --namespace-id=${{ env.tfstate_kv }} terraform.tfstate > ./.terraform/terraform.tfstate
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
postCommands: chmod 777 ./.terraform/terraform.tfstate
if: ${{ env.tfstate_kv != '' }}
- name: Configure
run: terraform plan && terraform apply -auto-approve
working-directory: ./.terraform
env:
TF_VAR_cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
TF_VAR_cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_VAR_sentry_dsn: ${{ secrets.SENTRY_DSN || '' }}
- name: Init Terraform State
uses: cloudflare/[email protected]
if: ${{ env.tfstate_kv == '' }}
with:
command: --version
preCommands: npx wrangler kv:namespace list | jq -r '.[] | select( .title == "dispoflare-terraform-state" ) | .id' | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Store Terraform State
uses: cloudflare/[email protected]
with:
command: kv:key put --namespace-id=${{ env.tfstate_kv }} terraform.tfstate --path=./.terraform/terraform.tfstate
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
app:
runs-on: ubuntu-latest
name: Application
needs: infra
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js LTS
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- name: Install NPM packages
run: npm ci
- name: Build Pages
run: npm run build
- name: Publish to Cloudflare Pages
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy build/client --branch=${{ github.head_ref || github.ref_name }} --project-name=dispoflare
- name: Check for Sentry availability
id: sentry-check
shell: bash
run: |
if [ "${{ secrets.SENTRY_DSN }}" != '' ]; then
echo "sentry=true" >> $GITHUB_OUTPUT;
else
echo "sentry=false" >> $GITHUB_OUTPUT;
fi
# - name: Setup Sentry
# if: ${{ steps.sentry-check.outputs.sentry == 'true' }}
# uses: cloudflare/[email protected]
# with:
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# command: --version
# secrets: |
# SENTRY_DSN
# env:
# SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Publish to Cloudflare Workers
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# secrets: |
# CLOUDFLARE_API_TOKEN
# CLOUDFLARE_ACCOUNT_ID
# env:
# CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Setup Cloudflare Workers
run: |
echo "$CLOUDFLARE_API_TOKEN" | npx wrangler secret put CLOUDFLARE_API_TOKEN
echo "$CLOUDFLARE_ACCOUNT_ID" | npx wrangler secret put CLOUDFLARE_ACCOUNT_ID
if [ "${{ secrets.SENTRY_DSN }}" != '' ]; then
echo "$SENTRY_DSN" | npx wrangler secret put SENTRY_DSN
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Create a Sentry release
uses: getsentry/action-release@v1
continue-on-error: true
if: ${{ steps.sentry-check.outputs.sentry == 'true' }}
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
with:
environment: production
sourcemaps: ./functions ./build
set_commits: skip