Skip to content

Commit 460aeab

Browse files
authored
build: add single-file executable of CLI + make it available as nightly release (#63)
* add nightly release CI * allow cli to be built as single-file executable * upload CLI artifact * fix: correct CLI artifact upload name in CI workflow * explicitely import pino-pretty
1 parent 88f40c1 commit 460aeab

5 files changed

Lines changed: 77 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
check:
11-
name: Check code
11+
name: Check and Build code
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
@@ -24,18 +24,22 @@ jobs:
2424
run: bun run lint
2525

2626
- name: Build all
27-
run: bun run build
28-
29-
- name: Build website
3027
env:
28+
# For website
3129
BACKEND_URL: https://backend-modpackresolver.itrooz.fr
32-
run: cd web && bun run build
30+
run: bun run build
3331

3432
- name: Upload website artifact
3533
uses: actions/upload-pages-artifact@v3
3634
with:
3735
path: 'web/build/'
3836

37+
- name: Upload CLI artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: modpackresolver-cli
41+
path: 'cli/dist/*'
42+
3943
build-backend-image:
4044
name: Build backend image
4145
runs-on: ubuntu-latest
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Inspired from https://github.com/WerWolv/ImHex/blob/16dc199431858de984fb0ed3b50d60a9a9e511b1/.github/workflows/nightly_release.yml
2+
3+
name: Nightly Release
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
env:
12+
NIGHTLY_TAG: nightly
13+
14+
jobs:
15+
nightly-release:
16+
runs-on: ubuntu-24.04
17+
name: 🌃 Update Nightly Release
18+
permissions:
19+
contents: write
20+
21+
steps:
22+
- name: 🧰 Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
path: project
26+
fetch-depth: 0
27+
fetch-tags: true
28+
29+
- name: ⬇️ Download artifacts from latest workflow
30+
uses: dawidd6/action-download-artifact@v6
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
workflow: ci.yml
34+
branch: ${{ github.event.release.target_commitish }}
35+
workflow_conclusion: success
36+
37+
- name: 📦 Update Pre-Release
38+
run: |
39+
set -e
40+
41+
cd project
42+
43+
# Move nightly tag to latest commit
44+
git tag -f $NIGHTLY_TAG HEAD
45+
git push origin $NIGHTLY_TAG --force
46+
47+
# Auth for GitHub CLI
48+
echo "${{ github.token }}" | gh auth login --with-token
49+
50+
# Delete existing assets
51+
for asset in $(gh release view $NIGHTLY_TAG --json assets --jq '.assets[].name'); do
52+
gh release delete-asset $NIGHTLY_TAG "$asset" --yes
53+
done
54+
55+
# Upload new assets
56+
gh release upload $NIGHTLY_TAG ../*.* --clobber

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"pino-pretty": "^13.0.0"
1212
},
1313
"scripts": {
14-
"build": "(cd ../mclib && bun run build) && bun build src/index.ts --outdir dist --minify --target node",
14+
"build": "(cd ../mclib && bun run build) && bun build src/index.ts --outfile dist/modpackresolver-cli --compile",
1515
"start": "(cd ../mclib && bun run build) && bun src/index.ts",
1616
"lint": "eslint .",
1717
"opt:proxy": "HTTP_PROXY=http://127.0.0.1:8080 HTTPS_PROXY=http://127.0.0.1:8080"

cli/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import { program, Option } from '@commander-js/extra-typings';
44
import { CurseForgeRepository, LocalSolutionFinder, LoggerConfig, ModLoader, ModrinthRepository, LogLevel, Constraints, Solution, ModMetadata, RepositoryUtil, ModRepositoryName, RemoteModQueryService, IModQueryService, IRepository, LocalModQueryService } from 'mclib';
55
import { readFileSync } from 'fs';
66
import pino from 'pino';
7+
import pinoPretty from 'pino-pretty';
78

89
// Logging setup
910
const LOG_LEVEL = (process.env.LOG_LEVEL ?? "info") as LogLevel;
1011
const logger = pino({
1112
level: LOG_LEVEL,
1213
base: {
1314
pid: false,
14-
},
15-
transport: {
16-
target: 'pino-pretty',
17-
options: {
18-
colorize: true
19-
}
2015
}
21-
});
16+
}, pinoPretty());
2217
LoggerConfig.setLevel(LOG_LEVEL);
2318

2419
// Fetch wrapper to log timing and errors
@@ -268,4 +263,11 @@ program
268263
}
269264
});
270265

266+
267+
// Workaround. See https://github.com/oven-sh/bun/issues/22283
268+
if (process.argv.length >= 3) {
269+
if (process.argv[2].endsWith('modpackresolver-cli')) {
270+
process.argv.splice(2, 1); // remove argv[2]
271+
}
272+
}
271273
program.parse(process.argv);

mclib/src/logger.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pino from 'pino';
2+
import pinoPretty from 'pino-pretty';
23

34
export enum LogLevel {
45
Fatal = 'fatal',
@@ -13,14 +14,8 @@ const logger = pino({
1314
level: 'info', // default level
1415
base: {
1516
pid: false,
16-
},
17-
transport: {
18-
target: 'pino-pretty',
19-
options: {
20-
colorize: true
21-
}
2217
}
23-
});
18+
}, pinoPretty());
2419

2520
class LoggerConfig {
2621
static setLevel(level: LogLevel): void {

0 commit comments

Comments
 (0)