Skip to content

Commit 395cf59

Browse files
authored
Merge pull request TriliumNext#325 from JYC333/action
FIx Github actions
2 parents 4090386 + 6113990 commit 395cf59

20 files changed

+1257
-524
lines changed

.github/workflows/main.yml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26+
arch: [x64, arm64]
2627
os:
2728
- name: macos
2829
image: macos-latest
30+
extension: dmg
2931
- name: linux
3032
image: ubuntu-latest
33+
extension: deb
3134
- name: windows
3235
image: windows-latest
36+
extension: exe
3337
runs-on: ${{ matrix.os.image }}
3438
steps:
3539
- uses: actions/checkout@v4
@@ -45,9 +49,59 @@ jobs:
4549
- name: Update build info
4650
run: npm run update-build-info
4751
- name: Run electron-forge
48-
run: npm run make-electron
52+
run: npm run make-electron -- --arch=${{ matrix.arch }}
53+
- name: Prepare artifacts (Unix)
54+
if: runner.os != 'windows'
55+
run: |
56+
mkdir -p upload
57+
file=$(find out/make -name '*.zip' -print -quit)
58+
cp "$file" "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.zip"
59+
file=$(find out/make -name '*.${{ matrix.os.extension }}' -print -quit)
60+
cp "$file" "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.${{ matrix.os.extension }}"
61+
- name: Prepare artifacts (Windows)
62+
if: runner.os == 'windows'
63+
run: |
64+
mkdir upload
65+
$file = Get-ChildItem -Path out/make -Filter '*.zip' -Recurse | Select-Object -First 1
66+
Copy-Item -Path $file.FullName -Destination "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.zip"
67+
$file = Get-ChildItem -Path out/make -Filter '*.${{ matrix.os.extension }}' -Recurse | Select-Object -First 1
68+
Copy-Item -Path $file.FullName -Destination "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.${{ matrix.os.extension }}"
4969
- name: Publish artifacts
5070
uses: actions/upload-artifact@v4
5171
with:
52-
name: ${{ matrix.os.name }}
53-
path: out/make/**
72+
name: TriliumNextNotes ${{ matrix.os.name }} ${{ matrix.arch }}
73+
path: upload/*.zip
74+
overwrite: true
75+
- name: Publish installer artifacts
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: TriliumNextNotes ${{ matrix.os.name }} ${{ matrix.arch }}
79+
path: upload/*.${{ matrix.os.extension }}
80+
overwrite: true
81+
build_linux_server-x64:
82+
name: Build Linux Server x86_64
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v4
86+
- name: Set up node & dependencies
87+
uses: actions/setup-node@v4
88+
with:
89+
node-version: 20
90+
cache: "npm"
91+
- name: Install dependencies
92+
run: npm ci
93+
- name: Run Linux server build (x86_64)
94+
run: |
95+
npm run update-build-info
96+
./bin/build-server.sh
97+
- name: Prepare artifacts
98+
if: runner.os != 'windows'
99+
run: |
100+
mkdir -p upload
101+
file=$(find dist -name '*.tar.xz' -print -quit)
102+
cp "$file" "upload/TriliumNextNotes-linux-x64-${{ github.ref_name }}.tar.xz"
103+
- uses: actions/upload-artifact@v4
104+
with:
105+
name: TriliumNextNotes linux server x64
106+
path: upload/TriliumNextNotes-linux-x64-${{ github.ref_name }}.tar.xz
107+
overwrite: true
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const anonymizationService = require('../src/services/anonymization');
4-
const fs = require('fs');
5-
const path = require('path');
3+
import anonymizationService from '../src/services/anonymization.js';
4+
import fs from 'fs';
5+
import path from 'path';
66

77
fs.writeFileSync(path.resolve(__dirname, 'tpl', 'anonymize-database.sql'), anonymizationService.getFullAnonymizationScript());

dump-db/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ npm install
1414

1515
## Running
1616

17-
See output of `node dump-db.js --help`:
17+
See output of `npx esrun dump.ts --help`:
1818

1919
```
20-
dump-db.js <path_to_document> <target_directory>
20+
dump-db.ts <path_to_document> <target_directory>
2121
2222
dump the contents of document.db into the target directory
2323
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
22

3-
const yargs = require('yargs/yargs')
4-
const { hideBin } = require('yargs/helpers')
5-
const dumpService = require('./inc/dump.js');
3+
import yargs from 'yargs';
4+
import { hideBin } from 'yargs/helpers';
5+
import dumpService from './inc/dump.js';
66

77
yargs(hideBin(process.argv))
88
.command('$0 <path_to_document> <target_directory>', 'dump the contents of document.db into the target directory', (yargs) => {
99
return yargs
10-
.positional('path_to_document', { describe: 'path to the document.db' })
11-
.positional('target_directory', { describe: 'path of the directory into which the notes should be dumped' })
10+
.option('path_to_document', { alias: 'p', describe: 'path to the document.db', type: 'string', demandOption: true })
11+
.option('target_directory', { alias: 't', describe: 'path of the directory into which the notes should be dumped', type: 'string', demandOption: true });
1212
}, (argv) => {
1313
try {
1414
dumpService.dumpDocument(argv.path_to_document, argv.target_directory, {
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const crypto = require("crypto");
2-
const sql = require('./sql');
3-
const decryptService = require('./decrypt.js');
1+
import crypto from 'crypto';
2+
import sql from './sql.js';
3+
import decryptService from './decrypt.js';
44

5-
function getDataKey(password) {
5+
function getDataKey(password: any) {
66
if (!password) {
77
return null;
88
}
@@ -16,28 +16,28 @@ function getDataKey(password) {
1616

1717
return decryptedDataKey;
1818
}
19-
catch (e) {
19+
catch (e: any) {
2020
throw new Error(`Cannot read data key, the entered password might be wrong. The underlying error: '${e.message}', stack:\n${e.stack}`);
2121
}
2222
}
2323

24-
function getPasswordDerivedKey(password) {
24+
function getPasswordDerivedKey(password: any) {
2525
const salt = getOption('passwordDerivedKeySalt');
2626

2727
return getScryptHash(password, salt);
2828
}
2929

30-
function getScryptHash(password, salt) {
30+
function getScryptHash(password: any, salt: any) {
3131
const hashed = crypto.scryptSync(password, salt, 32,
32-
{N: 16384, r:8, p:1});
32+
{ N: 16384, r: 8, p: 1 });
3333

3434
return hashed;
3535
}
3636

37-
function getOption(name) {
37+
function getOption(name: string) {
3838
return sql.getValue("SELECT value FROM options WHERE name = ?", [name]);
3939
}
4040

41-
module.exports = {
41+
export default {
4242
getDataKey
4343
};
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const crypto = require("crypto");
1+
import crypto from 'crypto';
22

3-
function decryptString(dataKey, cipherText) {
3+
function decryptString(dataKey: any, cipherText: any) {
44
const buffer = decrypt(dataKey, cipherText);
55

66
if (buffer === null) {
@@ -16,7 +16,7 @@ function decryptString(dataKey, cipherText) {
1616
return str;
1717
}
1818

19-
function decrypt(key, cipherText, ivLength = 13) {
19+
function decrypt(key: any, cipherText: any, ivLength = 13) {
2020
if (cipherText === null) {
2121
return null;
2222
}
@@ -46,11 +46,10 @@ function decrypt(key, cipherText, ivLength = 13) {
4646

4747
return payload;
4848
}
49-
catch (e) {
49+
catch (e: any) {
5050
// recovery from https://github.com/zadam/trilium/issues/510
5151
if (e.message?.includes("WRONG_FINAL_BLOCK_LENGTH") || e.message?.includes("wrong final block length")) {
52-
log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
53-
52+
console.log("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
5453
return cipherText;
5554
}
5655
else {
@@ -59,7 +58,7 @@ function decrypt(key, cipherText, ivLength = 13) {
5958
}
6059
}
6160

62-
function pad(data) {
61+
function pad(data: any) {
6362
if (data.length > 16) {
6463
data = data.slice(0, 16);
6564
}
@@ -72,7 +71,7 @@ function pad(data) {
7271
return Buffer.from(data);
7372
}
7473

75-
function arraysIdentical(a, b) {
74+
function arraysIdentical(a: any, b: any) {
7675
let i = a.length;
7776
if (i !== b.length) return false;
7877
while (i--) {
@@ -81,12 +80,12 @@ function arraysIdentical(a, b) {
8180
return true;
8281
}
8382

84-
function shaArray(content) {
83+
function shaArray(content: any) {
8584
// we use this as simple checksum and don't rely on its security so SHA-1 is good enough
8685
return crypto.createHash('sha1').update(content).digest();
8786
}
8887

89-
module.exports = {
88+
export default {
9089
decrypt,
9190
decryptString
9291
};
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const fs = require("fs");
2-
const sanitize = require("sanitize-filename");
3-
const sql = require('./sql.js');
4-
const decryptService = require('./decrypt.js');
5-
const dataKeyService = require('./data_key.js');
6-
const extensionService = require('./extension.js');
7-
8-
function dumpDocument(documentPath, targetPath, options) {
1+
import fs from 'fs';
2+
import sanitize from 'sanitize-filename';
3+
import sql from './sql.js';
4+
import decryptService from './decrypt.js';
5+
import dataKeyService from './data_key.js';
6+
import extensionService from './extension.js';
7+
8+
function dumpDocument(documentPath: string, targetPath: string, options: { password: any; includeDeleted: any; }) {
99
const stats = {
1010
succeeded: 0,
1111
failed: 0,
@@ -19,14 +19,14 @@ function dumpDocument(documentPath, targetPath, options) {
1919

2020
const dataKey = dataKeyService.getDataKey(options.password);
2121

22-
const existingPaths = {};
23-
const noteIdToPath = {};
22+
const existingPaths: Record<string, any> = {};
23+
const noteIdToPath: Record<string, any> = {};
2424

2525
dumpNote(targetPath, 'root');
2626

2727
printDumpResults(stats, options);
2828

29-
function dumpNote(targetPath, noteId) {
29+
function dumpNote(targetPath: any, noteId: any) {
3030
console.log(`Reading note '${noteId}'`);
3131

3232
let childTargetPath, noteRow, fileNameWithPath;
@@ -94,7 +94,7 @@ function dumpDocument(documentPath, targetPath, options) {
9494

9595
noteIdToPath[noteId] = childTargetPath;
9696
}
97-
catch (e) {
97+
catch (e: any) {
9898
console.error(`DUMPERROR: Writing '${noteId}' failed with error '${e.message}':\n${e.stack}`);
9999

100100
stats.failed++;
@@ -108,9 +108,9 @@ function dumpDocument(documentPath, targetPath, options) {
108108
}
109109

110110
try {
111-
fs.mkdirSync(childTargetPath, { recursive: true });
111+
fs.mkdirSync(childTargetPath as string, { recursive: true });
112112
}
113-
catch (e) {
113+
catch (e: any) {
114114
console.error(`DUMPERROR: Creating directory ${childTargetPath} failed with error '${e.message}'`);
115115
}
116116

@@ -121,7 +121,7 @@ function dumpDocument(documentPath, targetPath, options) {
121121
}
122122
}
123123

124-
function printDumpResults(stats, options) {
124+
function printDumpResults(stats: any, options: any) {
125125
console.log('\n----------------------- STATS -----------------------');
126126
console.log('Successfully dumpted notes: ', stats.succeeded.toString().padStart(5, ' '));
127127
console.log('Protected notes: ', stats.protected.toString().padStart(5, ' '), options.password ? '' : '(skipped)');
@@ -134,7 +134,7 @@ function printDumpResults(stats, options) {
134134
}
135135
}
136136

137-
function isContentEmpty(content) {
137+
function isContentEmpty(content: any) {
138138
if (!content) {
139139
return true;
140140
}
@@ -150,7 +150,7 @@ function isContentEmpty(content) {
150150
}
151151
}
152152

153-
function validatePaths(documentPath, targetPath) {
153+
function validatePaths(documentPath: string, targetPath: string) {
154154
if (!fs.existsSync(documentPath)) {
155155
console.error(`Path to document '${documentPath}' has not been found. Run with --help to see usage.`);
156156
process.exit(1);
@@ -166,6 +166,6 @@ function validatePaths(documentPath, targetPath) {
166166
}
167167
}
168168

169-
module.exports = {
169+
export default {
170170
dumpDocument
171171
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const path = require("path");
2-
const mimeTypes = require("mime-types");
1+
import path from "path";
2+
import mimeTypes from "mime-types";
33

4-
function getFileName(note, childTargetPath, safeTitle) {
4+
function getFileName(note: any, childTargetPath: string, safeTitle: string) {
55
let existingExtension = path.extname(safeTitle).toLowerCase();
66
let newExtension;
77

@@ -29,6 +29,6 @@ function getFileName(note, childTargetPath, safeTitle) {
2929
return fileNameWithPath;
3030
}
3131

32-
module.exports = {
32+
export default {
3333
getFileName
3434
};

dump-db/inc/sql.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

dump-db/inc/sql.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Database, { Database as DatabaseType } from "better-sqlite3";
2+
3+
let dbConnection: DatabaseType;
4+
5+
const openDatabase = (documentPath: string) => { dbConnection = new Database(documentPath, { readonly: true }) };
6+
7+
const getRow = (query: string, params: string[] = []): Record<string, any> => dbConnection.prepare(query).get(params) as Record<string, any>;
8+
const getRows = (query: string, params = []) => dbConnection.prepare(query).all(params);
9+
const getValue = (query: string, params: string[] = []) => dbConnection.prepare(query).pluck().get(params);
10+
const getColumn = (query: string, params: string[] = []) => dbConnection.prepare(query).pluck().all(params);
11+
12+
export default {
13+
openDatabase,
14+
getRow,
15+
getRows,
16+
getValue,
17+
getColumn
18+
};

0 commit comments

Comments
 (0)