Skip to content

Commit 762aef1

Browse files
committed
chore: Add multi release build script
1 parent 6b71265 commit 762aef1

5 files changed

Lines changed: 78 additions & 3 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 6 additions & 1 deletion
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,6 +27,9 @@ 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
@@ -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+
/tmp-dist
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.mjs",
1011
"preview": "vite preview",
1112
"knip": "knip",
1213
"knip:fix": "knip --fix-type exports,types",

scripts/build-release.mjs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { $ } from "bun"
2+
3+
const getLatestTag = async () => {
4+
const out =
5+
await $`git describe --tags $(git rev-list --tags --max-count=1)`.quiet()
6+
return out.text().trim()
7+
}
8+
9+
const getCurrentBranch = async () => {
10+
const out = await $`git rev-parse --abbrev-ref HEAD`.quiet()
11+
return out.text().trim()
12+
}
13+
14+
const pushStash = async () => {
15+
const id = crypto.randomUUID()
16+
const out = await $`git stash push -u -m ${id}`.quiet()
17+
const noStash = out.text().includes("No local changes")
18+
19+
return async () => {
20+
if (noStash) return
21+
await $`git stash apply stash^{/${id}}`.quiet()
22+
}
23+
}
24+
25+
const build = async (name, outDir) => {
26+
console.info(`Build ${name}:`)
27+
await $`bun i --frozen-lockfile`.quiet()
28+
console.info(`√ installed dependencies`)
29+
await $`bun run l10n:build`.quiet()
30+
console.info(`√ extracted translations`)
31+
await $`vite build --outDir=${outDir}`.quiet()
32+
console.info(`√ bundled app`)
33+
console.info("")
34+
}
35+
36+
const main = async () => {
37+
const initialBranch = await getCurrentBranch()
38+
console.info("💾 Saving changes...\n")
39+
const popInitalState = await pushStash()
40+
41+
try {
42+
const tag = await getLatestTag()
43+
const devDir = "tmp-dist/main"
44+
const prodDir = `tmp-dist/${tag}`
45+
46+
await build("dev", devDir)
47+
48+
const popMainDist = await pushStash()
49+
await $`git checkout tags/${tag}`.quiet()
50+
await popMainDist()
51+
52+
await build("prod", prodDir)
53+
54+
console.info("📦️ Build final package...\n")
55+
await $`rm -rf dist`.quiet().catch()
56+
await $`mv -f ${prodDir} dist`.quiet()
57+
await $`mv -f ${devDir} dist/dev`.quiet()
58+
} catch (error) {
59+
console.error("⚠️ Error: Somthing went wrong")
60+
console.error(error)
61+
} finally {
62+
console.info("🔄 Restoring initial state...")
63+
await $`git checkout ${initialBranch}`.quiet()
64+
await popInitalState()
65+
}
66+
}
67+
68+
void 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)