Repository navigation
172 lines (153 loc) · 5.83 KB
/
Copy pathdeploy.yml
File metadata and controls
172 lines (153 loc) · 5.83 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Deploy the web app Worker (`stackwallet`, workers.dev) on every push to main.
#
# Deploys through wrangler-action when CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID
# are available to this job. Missing credentials fail before building; success
# notifications are written only after the published assets match this build.
name: Deploy Worker
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-stackwallet
cancel-in-progress: false
permissions:
contents: read
deployments: write
issues: write
jobs:
ship:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
SITE_NAME: StackWallet
SITE_URL: https://stackwallet.civetadeicollegium.workers.dev
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate Cloudflare credentials
id: cf
env:
TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
if [ -z "$TOKEN" ]; then
echo "::error::CLOUDFLARE_API_TOKEN is unavailable to this job. Add it as a repository Actions secret, or declare the environment containing it."
exit 1
fi
if [ -z "$ACCOUNT_ID" ]; then
echo "::error::CLOUDFLARE_ACCOUNT_ID is unavailable to this job. Add it as a repository Actions secret, or declare the environment containing it."
exit 1
fi
echo "has_token=true" >> "$GITHUB_OUTPUT"
- name: Setup Rust (wasm core)
if: steps.cf.outputs.has_token == 'true'
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Rust cache
if: steps.cf.outputs.has_token == 'true'
uses: Swatinem/rust-cache@v2
- name: Install wasm-pack
if: steps.cf.outputs.has_token == 'true'
uses: taiki-e/install-action@v2
with:
tool: wasm-pack@0.15.0
- name: Setup pnpm
if: steps.cf.outputs.has_token == 'true'
uses: pnpm/action-setup@v4
- name: Setup Node
if: steps.cf.outputs.has_token == 'true'
uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- name: Install
if: steps.cf.outputs.has_token == 'true'
run: pnpm install --frozen-lockfile
- name: Build web
if: steps.cf.outputs.has_token == 'true'
run: pnpm --filter @stackwallet/web build
- name: Deploy
if: steps.cf.outputs.has_token == 'true'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: apps/web
command: deploy
packageManager: pnpm
- name: Verify live
if: steps.cf.outputs.has_token == 'true'
run: node --experimental-strip-types scripts/verify-deployment.ts
- name: Notify GitHub
if: success()
uses: actions/github-script@v7
with:
script: |
const site = process.env.SITE_NAME;
const url = process.env.SITE_URL;
const via = 'github-actions';
const sha = context.sha.slice(0, 7);
const msg = (context.payload.head_commit?.message || context.sha).split('\n')[0].slice(0, 72);
const title = `Deployed ${site} @ ${sha} - ${msg}`;
const body = [
`**${site}** production deploy`,
``,
`- Site: ${url}`,
`- Commit: \`${context.sha}\``,
`- Actor: @${context.actor}`,
`- Path: \`${via}\``,
`- Run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
].join('\n');
try {
await github.rest.issues.getLabel({ owner: context.repo.owner, repo: context.repo.repo, name: 'deployment' });
} catch {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'deployment',
color: '0E8A16',
description: 'Production deploy notifications',
});
}
// Fresh issue + assign + close = a real GitHub notification per ship.
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['deployment'],
assignees: [context.repo.owner],
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.data.number,
state: 'closed',
});
try {
const deployment = await github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha,
environment: 'production',
auto_merge: false,
required_contexts: [],
description: title,
production_environment: true,
});
if (deployment.data?.id) {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.data.id,
state: 'success',
environment_url: url,
log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Live via github-actions',
});
}
} catch (e) {
core.warning(`deployment record skipped: ${e.message}`);
}