Skip to content

Commit 74e29f9

Browse files
committed
add deployment status - part 1
1 parent 95f71be commit 74e29f9

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

.github/workflows/deploy.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ jobs:
5858
- name: Generate SvelteKit config
5959
run: pnpm svelte-kit sync
6060

61+
# - name: Set deployment status
62+
# if: steps.diff.outputs.db_changed == 'true'
63+
# env:
64+
# DB_URL: ${{ secrets.DB_URL }}
65+
# DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }}
66+
# run: tsx scripts/deploy-status.ts --deploying
67+
6168
- name: Update database
6269
if: steps.diff.outputs.db_changed == 'true'
6370
env:
@@ -92,3 +99,10 @@ jobs:
9299
93100
git tag -f deploy-prod $GITHUB_SHA
94101
git push --no-verify origin refs/tags/deploy-prod --force
102+
103+
- name: Reset deployment status
104+
if: always()
105+
env:
106+
DB_URL: ${{ secrets.DB_URL }}
107+
DB_AUTH_TOKEN: ${{ secrets.DB_AUTH_TOKEN }}
108+
run: pnpm db:finish-deploy
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE deployment_status (
2+
id INTEGER PRIMARY KEY CHECK (id = 1),
3+
status TEXT NOT NULL CHECK (status IN ('ready', 'deploying')),
4+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
5+
);
6+
7+
INSERT INTO deployment_status (id, status) VALUES (1, 'ready');

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"db:deduce": "tsx scripts/deduce.ts",
2121
"db:test": "tsx scripts/test.ts",
2222
"db:update": "pnpm db:migrate && pnpm db:seed && pnpm db:deduce && pnpm db:test",
23-
"db:watch": "tsx scripts/watch.ts"
23+
"db:watch": "tsx scripts/watch.ts",
24+
"db:start-deploy": "tsx scripts/deploy-status.ts --deploying",
25+
"db:finish-deploy": "tsx scripts/deploy-status.ts --ready"
2426
},
2527
"devDependencies": {
2628
"@sveltejs/adapter-netlify": "^6.0.4",

scripts/deploy-status.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createClient } from '@libsql/client'
2+
import dotenv from 'dotenv'
3+
4+
dotenv.config({ quiet: true })
5+
const DB_URL = process.env.DB_URL
6+
const DB_AUTH_TOKEN = process.env.DB_AUTH_TOKEN
7+
8+
if (!DB_URL) throw new Error('No DB_URL found')
9+
10+
const db = createClient({
11+
url: DB_URL,
12+
authToken: DB_AUTH_TOKEN,
13+
})
14+
15+
const status = process.argv[2]?.slice(2)
16+
17+
await db.execute(
18+
`
19+
UPDATE deployment_status SET
20+
status = ?,
21+
updated_at = CURRENT_TIMESTAMP
22+
WHERE id = 1
23+
`,
24+
[status],
25+
)

0 commit comments

Comments
 (0)