Skip to content

Commit

Permalink
Merge pull request #325 from JYC333/action
Browse files Browse the repository at this point in the history
FIx Github actions
  • Loading branch information
eliandoran authored Aug 10, 2024
2 parents 4090386 + 6113990 commit 395cf59
Show file tree
Hide file tree
Showing 20 changed files with 1,257 additions and 524 deletions.
60 changes: 57 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [x64, arm64]
os:
- name: macos
image: macos-latest
extension: dmg
- name: linux
image: ubuntu-latest
extension: deb
- name: windows
image: windows-latest
extension: exe
runs-on: ${{ matrix.os.image }}
steps:
- uses: actions/checkout@v4
Expand All @@ -45,9 +49,59 @@ jobs:
- name: Update build info
run: npm run update-build-info
- name: Run electron-forge
run: npm run make-electron
run: npm run make-electron -- --arch=${{ matrix.arch }}
- name: Prepare artifacts (Unix)
if: runner.os != 'windows'
run: |
mkdir -p upload
file=$(find out/make -name '*.zip' -print -quit)
cp "$file" "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.zip"
file=$(find out/make -name '*.${{ matrix.os.extension }}' -print -quit)
cp "$file" "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.${{ matrix.os.extension }}"
- name: Prepare artifacts (Windows)
if: runner.os == 'windows'
run: |
mkdir upload
$file = Get-ChildItem -Path out/make -Filter '*.zip' -Recurse | Select-Object -First 1
Copy-Item -Path $file.FullName -Destination "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.zip"
$file = Get-ChildItem -Path out/make -Filter '*.${{ matrix.os.extension }}' -Recurse | Select-Object -First 1
Copy-Item -Path $file.FullName -Destination "upload/TriliumNextNotes-${{ matrix.os.name }}-${{ matrix.arch }}-${{ github.ref_name }}.${{ matrix.os.extension }}"
- name: Publish artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os.name }}
path: out/make/**
name: TriliumNextNotes ${{ matrix.os.name }} ${{ matrix.arch }}
path: upload/*.zip
overwrite: true
- name: Publish installer artifacts
uses: actions/upload-artifact@v4
with:
name: TriliumNextNotes ${{ matrix.os.name }} ${{ matrix.arch }}
path: upload/*.${{ matrix.os.extension }}
overwrite: true
build_linux_server-x64:
name: Build Linux Server x86_64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up node & dependencies
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run Linux server build (x86_64)
run: |
npm run update-build-info
./bin/build-server.sh
- name: Prepare artifacts
if: runner.os != 'windows'
run: |
mkdir -p upload
file=$(find dist -name '*.tar.xz' -print -quit)
cp "$file" "upload/TriliumNextNotes-linux-x64-${{ github.ref_name }}.tar.xz"
- uses: actions/upload-artifact@v4
with:
name: TriliumNextNotes linux server x64
path: upload/TriliumNextNotes-linux-x64-${{ github.ref_name }}.tar.xz
overwrite: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const anonymizationService = require('../src/services/anonymization');
const fs = require('fs');
const path = require('path');
import anonymizationService from '../src/services/anonymization.js';
import fs from 'fs';
import path from 'path';

fs.writeFileSync(path.resolve(__dirname, 'tpl', 'anonymize-database.sql'), anonymizationService.getFullAnonymizationScript());
4 changes: 2 additions & 2 deletions dump-db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ npm install

## Running

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

```
dump-db.js <path_to_document> <target_directory>
dump-db.ts <path_to_document> <target_directory>
dump the contents of document.db into the target directory
Expand Down
10 changes: 5 additions & 5 deletions dump-db/dump-db.js → dump-db/dump-db.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const dumpService = require('./inc/dump.js');
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import dumpService from './inc/dump.js';

yargs(hideBin(process.argv))
.command('$0 <path_to_document> <target_directory>', 'dump the contents of document.db into the target directory', (yargs) => {
return yargs
.positional('path_to_document', { describe: 'path to the document.db' })
.positional('target_directory', { describe: 'path of the directory into which the notes should be dumped' })
.option('path_to_document', { alias: 'p', describe: 'path to the document.db', type: 'string', demandOption: true })
.option('target_directory', { alias: 't', describe: 'path of the directory into which the notes should be dumped', type: 'string', demandOption: true });
}, (argv) => {
try {
dumpService.dumpDocument(argv.path_to_document, argv.target_directory, {
Expand Down
20 changes: 10 additions & 10 deletions dump-db/inc/data_key.js → dump-db/inc/data_key.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const crypto = require("crypto");
const sql = require('./sql');
const decryptService = require('./decrypt.js');
import crypto from 'crypto';
import sql from './sql.js';
import decryptService from './decrypt.js';

function getDataKey(password) {
function getDataKey(password: any) {
if (!password) {
return null;
}
Expand All @@ -16,28 +16,28 @@ function getDataKey(password) {

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

function getPasswordDerivedKey(password) {
function getPasswordDerivedKey(password: any) {
const salt = getOption('passwordDerivedKeySalt');

return getScryptHash(password, salt);
}

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

return hashed;
}

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

module.exports = {
export default {
getDataKey
};
19 changes: 9 additions & 10 deletions dump-db/inc/decrypt.js → dump-db/inc/decrypt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const crypto = require("crypto");
import crypto from 'crypto';

function decryptString(dataKey, cipherText) {
function decryptString(dataKey: any, cipherText: any) {
const buffer = decrypt(dataKey, cipherText);

if (buffer === null) {
Expand All @@ -16,7 +16,7 @@ function decryptString(dataKey, cipherText) {
return str;
}

function decrypt(key, cipherText, ivLength = 13) {
function decrypt(key: any, cipherText: any, ivLength = 13) {
if (cipherText === null) {
return null;
}
Expand Down Expand Up @@ -46,11 +46,10 @@ function decrypt(key, cipherText, ivLength = 13) {

return payload;
}
catch (e) {
catch (e: any) {
// recovery from https://github.com/zadam/trilium/issues/510
if (e.message?.includes("WRONG_FINAL_BLOCK_LENGTH") || e.message?.includes("wrong final block length")) {
log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");

console.log("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
return cipherText;
}
else {
Expand All @@ -59,7 +58,7 @@ function decrypt(key, cipherText, ivLength = 13) {
}
}

function pad(data) {
function pad(data: any) {
if (data.length > 16) {
data = data.slice(0, 16);
}
Expand All @@ -72,7 +71,7 @@ function pad(data) {
return Buffer.from(data);
}

function arraysIdentical(a, b) {
function arraysIdentical(a: any, b: any) {
let i = a.length;
if (i !== b.length) return false;
while (i--) {
Expand All @@ -81,12 +80,12 @@ function arraysIdentical(a, b) {
return true;
}

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

module.exports = {
export default {
decrypt,
decryptString
};
36 changes: 18 additions & 18 deletions dump-db/inc/dump.js → dump-db/inc/dump.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require("fs");
const sanitize = require("sanitize-filename");
const sql = require('./sql.js');
const decryptService = require('./decrypt.js');
const dataKeyService = require('./data_key.js');
const extensionService = require('./extension.js');

function dumpDocument(documentPath, targetPath, options) {
import fs from 'fs';
import sanitize from 'sanitize-filename';
import sql from './sql.js';
import decryptService from './decrypt.js';
import dataKeyService from './data_key.js';
import extensionService from './extension.js';

function dumpDocument(documentPath: string, targetPath: string, options: { password: any; includeDeleted: any; }) {
const stats = {
succeeded: 0,
failed: 0,
Expand All @@ -19,14 +19,14 @@ function dumpDocument(documentPath, targetPath, options) {

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

const existingPaths = {};
const noteIdToPath = {};
const existingPaths: Record<string, any> = {};
const noteIdToPath: Record<string, any> = {};

dumpNote(targetPath, 'root');

printDumpResults(stats, options);

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

let childTargetPath, noteRow, fileNameWithPath;
Expand Down Expand Up @@ -94,7 +94,7 @@ function dumpDocument(documentPath, targetPath, options) {

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

stats.failed++;
Expand All @@ -108,9 +108,9 @@ function dumpDocument(documentPath, targetPath, options) {
}

try {
fs.mkdirSync(childTargetPath, { recursive: true });
fs.mkdirSync(childTargetPath as string, { recursive: true });
}
catch (e) {
catch (e: any) {
console.error(`DUMPERROR: Creating directory ${childTargetPath} failed with error '${e.message}'`);
}

Expand All @@ -121,7 +121,7 @@ function dumpDocument(documentPath, targetPath, options) {
}
}

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

function isContentEmpty(content) {
function isContentEmpty(content: any) {
if (!content) {
return true;
}
Expand All @@ -150,7 +150,7 @@ function isContentEmpty(content) {
}
}

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

module.exports = {
export default {
dumpDocument
};
8 changes: 4 additions & 4 deletions dump-db/inc/extension.js → dump-db/inc/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
const mimeTypes = require("mime-types");
import path from "path";
import mimeTypes from "mime-types";

function getFileName(note, childTargetPath, safeTitle) {
function getFileName(note: any, childTargetPath: string, safeTitle: string) {
let existingExtension = path.extname(safeTitle).toLowerCase();
let newExtension;

Expand Down Expand Up @@ -29,6 +29,6 @@ function getFileName(note, childTargetPath, safeTitle) {
return fileNameWithPath;
}

module.exports = {
export default {
getFileName
};
17 changes: 0 additions & 17 deletions dump-db/inc/sql.js

This file was deleted.

18 changes: 18 additions & 0 deletions dump-db/inc/sql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Database, { Database as DatabaseType } from "better-sqlite3";

let dbConnection: DatabaseType;

const openDatabase = (documentPath: string) => { dbConnection = new Database(documentPath, { readonly: true }) };

const getRow = (query: string, params: string[] = []): Record<string, any> => dbConnection.prepare(query).get(params) as Record<string, any>;
const getRows = (query: string, params = []) => dbConnection.prepare(query).all(params);
const getValue = (query: string, params: string[] = []) => dbConnection.prepare(query).pluck().get(params);
const getColumn = (query: string, params: string[] = []) => dbConnection.prepare(query).pluck().all(params);

export default {
openDatabase,
getRow,
getRows,
getValue,
getColumn
};
Loading

0 comments on commit 395cf59

Please sign in to comment.