Skip to content

Commit 64b4a9a

Browse files
committed
chore: Add multi release build script
1 parent 6b71265 commit 64b4a9a

5 files changed

Lines changed: 93 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Deploy to Pages
33
on:
44
push:
55
branches: ["main"]
6+
release:
7+
types: created
68

79
# Allows to run this workflow manually from the Actions tab
810
workflow_dispatch:
@@ -25,11 +27,14 @@ jobs:
2527
steps:
2628
- name: Checkout
2729
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
fetch-tags: true
2833

2934
- name: Setup bun
3035
uses: oven-sh/setup-bun@v2
3136
with:
32-
bun-version: "1.1.33"
37+
bun-version: "1.3.6"
3338

3439
- name: Setup Pages
3540
uses: actions/configure-pages@v3
@@ -38,7 +43,7 @@ jobs:
3843
run: bun install
3944

4045
- name: Build project
41-
run: bun run build
46+
run: bun run build:release
4247

4348
- name: Upload artifact
4449
uses: actions/upload-pages-artifact@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# production
1212
/dist
1313
/src/locales/*/messages.js
14+
./worktree-*
1415

1516
# local test files
1617
/.dump

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"dev": "vite",
88
"l10n:build": "lingui extract --clean --overwrite && lingui compile --strict",
9-
"build": "tsc -b && npm run l10n:build && vite build",
9+
"build": "tsc -b && bun run l10n:build && vite build",
10+
"build:release": "bun ./scripts/build-release.ts",
1011
"preview": "vite preview",
1112
"knip": "knip",
1213
"knip:fix": "knip --fix-type exports,types",

scripts/build-release.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { resolve, join } from "node:path"
2+
3+
import { $ } from "bun"
4+
5+
const ROOT_DIR = resolve("./")
6+
const BUILD_DIR = "dist"
7+
8+
const getAbsolutePath = (path: string) => {
9+
const pwd = resolve(path)
10+
11+
if (!pwd.includes(ROOT_DIR)) {
12+
// to protect you and me from big oopsies when running `rm -rf ${pwd}`
13+
console.error(`Cannot escape project directory. pwd: ${pwd}\n`)
14+
process.exit(1)
15+
}
16+
17+
return pwd
18+
}
19+
20+
const getLatestTag = async () =>
21+
$`git describe --tags $(git rev-list --tags --max-count=1)`
22+
.text()
23+
.then(out => out.trim())
24+
25+
type ShellFn = (...args: Parameters<typeof $>) => Promise<string>
26+
27+
const createWorktree = async (path: string, name: string) => {
28+
const pwd = getAbsolutePath(path)
29+
30+
await $`git worktree add -f ${pwd} ${name}`.quiet()
31+
32+
const shell: ShellFn = (...args: Parameters<ShellFn>) =>
33+
$(...args)
34+
.cwd(pwd)
35+
.text()
36+
37+
return {
38+
name,
39+
path,
40+
$: shell,
41+
mv: (source: string, target: string) =>
42+
$`mv -f "${join(pwd, source)}" "${join(ROOT_DIR, target)}"`.quiet(),
43+
rm: () => $`rm -rf ${pwd}`.quiet(),
44+
}
45+
}
46+
47+
const build = async ($: ShellFn, name: string) => {
48+
console.info(`🏗️ Build ${name}:`)
49+
await $`bun i --frozen-lockfile`
50+
console.info(` √ installed dependencies`)
51+
await $`bun run l10n:build`
52+
console.info(` √ extracted translations`)
53+
await $`vite build --outDir="./${BUILD_DIR}"`
54+
console.info(` √ bundled app`)
55+
console.info("")
56+
}
57+
58+
const main = async () => {
59+
try {
60+
const tag = await getLatestTag()
61+
62+
const prod = await createWorktree("./worktree-clocktopus-prod/", tag)
63+
const main = await createWorktree("./worktree-clocktopus-main/", "main")
64+
65+
await build(main.$, main.name)
66+
await build(prod.$, prod.name)
67+
68+
console.info("📦️ Creating final package...")
69+
await $`rm -rf ./dist`.quiet().catch()
70+
await prod.mv(BUILD_DIR, "./dist/")
71+
await main.mv(BUILD_DIR, "./dist/dev")
72+
73+
console.info("🧼 Cleaning up...")
74+
await prod.rm()
75+
await main.rm()
76+
} catch (error) {
77+
console.error("⚠️ Error: Something went wrong\n")
78+
console.error(error)
79+
}
80+
}
81+
82+
await main()

tsconfig.node.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
/* Completeness */
3636
"skipLibCheck": true,
3737
},
38-
"include": ["*"]
38+
"include": ["*", "scripts/*"]
3939
}

0 commit comments

Comments
 (0)