Skip to content

Commit 0f4667f

Browse files
authored
Deno Deployment (#157)
* feat: deno continuous deployment * wip: debug * wip * ci: i'm also so stupid
1 parent eb029ef commit 0f4667f

File tree

5 files changed

+218
-5
lines changed

5 files changed

+218
-5
lines changed

.github/workflows/ci.yaml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
clean: true
4040
persist-credentials: false
4141
set-safe-directory: true
42+
fetch-depth: 1
4243
- name: 🐦 Set up Flutter
4344
id: flutter
4445
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
@@ -109,6 +110,7 @@ jobs:
109110
clean: true
110111
persist-credentials: false
111112
set-safe-directory: true
113+
fetch-depth: 1
112114
- name: 🐦 Set up Flutter
113115
id: flutter
114116
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
@@ -153,7 +155,7 @@ jobs:
153155
if: ${{ matrix.target == 'web' }}
154156
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
155157
with:
156-
name: app-${{ matrix.target }}-build
158+
name: build-${{ matrix.target }}
157159
path: "./packages/app/build/"
158160
if-no-files-found: error
159161

@@ -171,6 +173,7 @@ jobs:
171173
clean: true
172174
persist-credentials: false
173175
set-safe-directory: true
176+
fetch-depth: 1
174177
- name: 🐦 Set up Flutter
175178
id: flutter
176179
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
@@ -217,6 +220,7 @@ jobs:
217220
clean: true
218221
persist-credentials: false
219222
set-safe-directory: true
223+
fetch-depth: 1
220224
- name: 🐦 Set up Flutter
221225
id: flutter
222226
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
@@ -273,6 +277,7 @@ jobs:
273277
clean: true
274278
persist-credentials: false
275279
set-safe-directory: true
280+
fetch-depth: 1
276281
- name: 🐦 Set up Flutter
277282
id: flutter
278283
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # v2.18.0
@@ -285,21 +290,61 @@ jobs:
285290
- name: ✨ Verify formatting
286291
run: dart format . --output=none --set-exit-if-changed
287292

293+
deploy:
294+
name: Deploy
295+
needs: ["build"]
296+
runs-on: ubuntu-latest
297+
timeout-minutes: 2
298+
299+
permissions:
300+
id-token: write # Needed to authenticate with Deno Deploy.
301+
concurrency:
302+
group: deploy-${{ github.ref }}
303+
cancel-in-progress: true
304+
305+
steps:
306+
- name: 📚 Git checkout
307+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
308+
with:
309+
submodules: recursive
310+
clean: true
311+
persist-credentials: false
312+
set-safe-directory: true
313+
fetch-depth: 1
314+
sparse-checkout: packages/server
315+
- name: ⚙️ Download build
316+
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
317+
with:
318+
name: build-web
319+
path: "./packages/server/static"
320+
- name: 🔧 Deploy
321+
uses: denoland/deployctl@612f83df2b874c6908d68de5cf3f36a6538fa8f7 # 1.12.0
322+
with:
323+
project: "harvest-hub"
324+
entrypoint: ./src/server.ts
325+
root: packages/server
326+
include: |
327+
src/
328+
static/
329+
deno.json
330+
deno.lock
331+
288332
spell-check:
289333
name: Check Spelling
290334
needs: []
291335
runs-on: ubuntu-latest
292336

293337
steps:
294-
- name: 📚 Git Checkout
338+
- name: 📚 Git checkout
295339
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
296340
with:
297341
submodules: recursive
298342
clean: true
299343
persist-credentials: false
300344
set-safe-directory: true
345+
fetch-depth: 1
301346

302-
- name: 🪄 Spell Check
347+
- name: 🪄 Spell check
303348
uses: streetsidesoftware/cspell-action@934c74da3775ac844ec89503f666f67efb427fed # v6.8.1
304349
with:
305350
files: |
@@ -331,14 +376,15 @@ jobs:
331376
runs-on: ubuntu-latest
332377

333378
steps:
334-
- name: 📚 Git Checkout
379+
- name: 📚 Git checkout
335380
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
336381
with:
337382
submodules: recursive
338383
clean: true
339384
persist-credentials: false
340385
set-safe-directory: true
341-
- name: 🕵️ Markdown linting
386+
fetch-depth: 1
387+
- name: 🕵️ Lint Markdown
342388
uses: DavidAnson/markdownlint-cli2-action@db43aef879112c3119a410d69f66701e0d530809 # v17.0.0
343389
id: markdownlint
344390
with:

packages/server/deno.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"imports": {
3+
"@std/assert": "jsr:@std/assert@^1.0.11",
4+
"@std/http": "jsr:@std/http@^1.0.13",
5+
"@std/path": "jsr:@std/path@^1.0.8"
6+
},
7+
"compilerOptions": {
8+
"strict": true,
9+
"noFallthroughCasesInSwitch": true,
10+
"noImplicitReturns": true,
11+
"noImplicitOverride": true,
12+
"exactOptionalPropertyTypes": true,
13+
"noUncheckedIndexedAccess": true,
14+
"noPropertyAccessFromIndexSignature": true,
15+
"noUnusedLocals": true,
16+
"allowUnusedLabels": false,
17+
"allowUnreachableCode": false,
18+
"noUnusedParameters": true,
19+
"useUnknownInCatchVariables": true,
20+
"verbatimModuleSyntax": true
21+
}
22+
}

packages/server/deno.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/server/src/server.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { assertEquals, assertStringIncludes } from "@std/assert";
2+
import { join } from "@std/path";
3+
import { respond } from "./server.ts";
4+
5+
async function populateTempDir(
6+
files: readonly { name: string; content: string }[]
7+
): Promise<string> {
8+
const encoder = new TextEncoder();
9+
const tempDirPath = await Deno.makeTempDir();
10+
11+
const promises = files.map(async ({ name, content }) => {
12+
await Deno.writeFile(join(tempDirPath, name), encoder.encode(content));
13+
});
14+
15+
await Promise.all(promises);
16+
17+
return tempDirPath;
18+
}
19+
20+
Deno.test(
21+
"serveDir should return the correct response for an html file",
22+
async () => {
23+
const tempDirPath = await populateTempDir([
24+
{ name: "index.html", content: "" },
25+
{ name: "index.pck", content: "" },
26+
{ name: "index.wasm", content: "" },
27+
]);
28+
29+
const req = new Request("http://localhost");
30+
const res = await respond(req, tempDirPath);
31+
await res.body?.cancel();
32+
33+
assertEquals(res.status, 200);
34+
assertStringIncludes(res.headers.get("Content-Type") ?? "", "text/html");
35+
}
36+
);
37+
38+
Deno.test(
39+
"serveDir should return the correct response for a wasm file",
40+
async () => {
41+
const tempDirPath = await populateTempDir([
42+
{ name: "index.wasm", content: "" },
43+
]);
44+
45+
const req = new Request("http://localhost/index.wasm");
46+
const res = await respond(req, tempDirPath);
47+
await res.body?.cancel();
48+
49+
assertEquals(res.status, 200);
50+
assertStringIncludes(
51+
res.headers.get("Content-Type") ?? "",
52+
"application/wasm"
53+
);
54+
}
55+
);

packages/server/src/server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { serveDir } from "@std/http";
2+
3+
export async function respond(req: Request, dir = "static"): Promise<Response> {
4+
const res = await serveDir(req, {
5+
fsRoot: dir,
6+
enableCors: true,
7+
});
8+
9+
res.headers.set("Cross-Origin-Opener-Policy", "same-origin");
10+
res.headers.set("Cross-Origin-Embedder-Policy", " require-corp");
11+
12+
return res;
13+
}
14+
15+
export default {
16+
fetch: async (req: Request): Promise<Response> => {
17+
return await respond(req);
18+
},
19+
} satisfies Deno.ServeDefaultExport;

0 commit comments

Comments
 (0)