Skip to content

Commit 751e1f9

Browse files
authored
Merge pull request #4 from KilleenCode/test-deploy
Test deploy
2 parents 2cc305d + 1d27736 commit 751e1f9

File tree

5 files changed

+48
-22
lines changed

5 files changed

+48
-22
lines changed

.github/workflows/deploy.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
name: Deploy
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Publish
15+
uses: cloudflare/[email protected]
16+
with:
17+
apiToken: ${{ secrets.CF_API_TOKEN }}
18+
env:
19+
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Tauri Update Server: Cloudflare
22

3+
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/killeencode/tauri-update-cloudflare)
4+
35
Much credit to [@lemarier](https://github.com/lemarier) for the underlying logic at https://github.com/lemarier/updater-deno
46

57
## Cloudflare Wrangler

src/getPlatform.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,17 @@ function extname(filename: string) {
5656
return filename.split('.').pop() || ''
5757
}
5858

59+
export type Asset = { name: string; browser_download_url: string }
60+
5961
export async function findAssetSignature(
6062
fileName: string,
61-
assets: any[],
63+
assets: Asset[],
6264
): Promise<string | undefined> {
6365
// check in our assets if we have a file: `fileName.sig`
6466
// by example fileName can be: App-1.0.0.zip
65-
const matches = [
66-
`${fileName.toLowerCase()}.gz.sig`,
67-
`${fileName.toLowerCase()}.sig`,
68-
]
69-
const foundSignature = assets.find((asset) =>
70-
asset.name.toLowerCase() === `${fileName.toLowerCase()}.sig`,
67+
68+
const foundSignature = assets.find(
69+
(asset) => asset.name.toLowerCase() === `${fileName.toLowerCase()}.sig`,
7170
)
7271

7372
if (!foundSignature) {

src/handler.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Asset,
23
checkPlatform,
34
findAssetSignature,
45
sanitizeVersion,
@@ -7,17 +8,19 @@ import {
78
import semverValid from 'semver/functions/valid'
89
import semverGt from 'semver/functions/gt'
910

10-
1111
type TauriUpdateResponse = {
12-
url: string,
13-
version: string,
14-
notes?: string,
15-
pub_date?: string,
12+
url: string
13+
version: string
14+
notes?: string
15+
pub_date?: string
1616
signature?: string
1717
}
1818

19-
const GITHUB_ACCOUNT = 'killeencode'
20-
const GITHUB_REPO = 'brancato'
19+
declare global {
20+
const GITHUB_ACCOUNT: string
21+
const GITHUB_REPO: string
22+
}
23+
2124
export async function handleRequest(request: Request): Promise<Response> {
2225
const path = new URL(request.url).pathname
2326
const [platform, version] = path.slice(1).split('/')
@@ -36,8 +39,8 @@ export async function handleRequest(request: Request): Promise<Response> {
3639

3740
const release = (await releaseResponse.clone().json()) as {
3841
tag_name: string
39-
assets: any
40-
body: any
42+
assets: Asset[]
43+
body: string
4144
published_at: string
4245
}
4346
if (!platform || !validatePlatform(platform) || !version) {
@@ -48,7 +51,7 @@ export async function handleRequest(request: Request): Promise<Response> {
4851
if (!remoteVersion || !semverValid(remoteVersion)) {
4952
return new Response('Not found', { status: 404 })
5053
}
51-
54+
5255
const shouldUpdate = semverGt(remoteVersion, version)
5356
if (!shouldUpdate) {
5457
return new Response(null, { status: 204 })
@@ -63,17 +66,16 @@ export async function handleRequest(request: Request): Promise<Response> {
6366

6467
// try to find signature for this asset
6568
const signature = await findAssetSignature(name, release.assets)
66-
const data : TauriUpdateResponse = {
69+
const data: TauriUpdateResponse = {
6770
url: browser_download_url,
6871
version: remoteVersion,
6972
notes: release.body,
7073
pub_date: release.published_at,
7174
signature,
7275
}
73-
return new Response(
74-
JSON.stringify(data),
75-
{ headers: { 'Content-Type': 'application/json; charset=utf-8' } },
76-
)
76+
return new Response(JSON.stringify(data), {
77+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
78+
})
7779
}
7880

7981
return new Response(JSON.stringify({ remoteVersion, version, shouldUpdate }))

wrangler.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ route = ""
66
workers_dev = true
77
compatibility_date = "2022-03-26"
88

9+
[vars]
10+
GITHUB_ACCOUNT = 'killeencode'
11+
GITHUB_REPO = 'brancato'
12+
913
[build]
1014
command = "npm install && npm run build"
1115
[build.upload]

0 commit comments

Comments
 (0)