diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml new file mode 100644 index 0000000..38c1a02 --- /dev/null +++ b/.github/workflows/server.yml @@ -0,0 +1,39 @@ +name: Server + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Setup repo + uses: actions/checkout@v3 + + - name: Setup Deno + uses: denoland/setup-deno@v1 + with: + deno-version: v1.34 + + - name: Build bundles + run: | + deno task build + + - name: Compile for all platforms + run: | + deno task server:dist:linux-x86_64 + deno task server:dist:darwin-x86_64 + deno task server:dist:darwin-aarch64 + deno task server:dist:windows-x86_64 + + - name: Release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: true + files: | + silverbullet-*.zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index e7d7cd7..a40e7c0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ env.sh node_modules *.db test_space +silverbullet \ No newline at end of file diff --git a/cmd/upgrade.ts b/cmd/upgrade.ts index eb6f62a..d8207cd 100644 --- a/cmd/upgrade.ts +++ b/cmd/upgrade.ts @@ -35,3 +35,78 @@ export async function upgradeCommand() { ); } } + +// WIP: This is not yet working, but it's a start +import { dirname } from "https://deno.land/std@0.186.0/path/mod.ts"; + +const silverBulletReleases = + "https://github.com/silverbulletmd/silverbullet/releases"; + +export async function compiledUpgradeCommand() { + console.log("Now going to attempt an upgrade..."); + + const resp = await fetch(`${silverBulletReleases}/latest`, { + redirect: "manual", + }); + const versionedUrl = resp.headers.get("location")!; + const latestVersion = /([^\/]+)$/.exec(versionedUrl); + if (!latestVersion) { + console.error("Could not fetch latest version"); + } + if (version === latestVersion![0]) { + console.log("No version available, we're done here!"); + return; + } + console.log( + "New version available:", + latestVersion![0], + "which I will now personally download. Hang on...", + ); + const installDir = dirname(new URL(Deno.mainModule).pathname); + + const tmpDir = Deno.makeTempDirSync(); + // const zipUrl = "https://github.com/silverbulletmd/silverbullet/releases/download/test-release/silverbullet-server-apple-aarch64.zip"; + const zipUrl = + `${versionedUrl}/download/silverbullet-server-${Deno.build.os}-${Deno.build.arch}.zip`; + const zipPath = `${tmpDir}/silverbullet.zip`; + const command = new Deno.Command("curl", { + args: [ + "-L", + "-o", + zipPath, + zipUrl, + ], + }); + const curlOutput = await command.output(); + console.log( + "Now going to replace the existing silverbullet binary in", + installDir, + ); + if (curlOutput.code !== 0) { + console.error( + "Download failed", + new TextDecoder().decode(curlOutput.stderr), + ); + return; + } + + const unzipCommand = new Deno.Command("unzip", { + args: [ + "-o", + "-d", + installDir, + `${tmpDir}/silverbullet.zip`, + ], + }); + const zipOutput = await unzipCommand.output(); + if (zipOutput.code !== 0) { + console.error( + "Download failed", + new TextDecoder().decode(curlOutput.stderr), + ); + return; + } + await Deno.chmod(`${installDir}/silverbullet`, 0o755); + await Deno.remove(zipPath); + console.log("And done! Restart your server to get the latest and greatest!"); +} diff --git a/deno.jsonc b/deno.jsonc index cb21f93..aae60de 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -14,7 +14,14 @@ "bundle": "deno run -A build_bundle.ts", // Regenerates some bundle files (checked into the repo) // Install lezer-generator with "npm install -g @lezer/generator" - "generate": "lezer-generator common/markdown_parser/query.grammar -o common/markdown_parser/parse-query.js" + "generate": "lezer-generator common/markdown_parser/query.grammar -o common/markdown_parser/parse-query.js", + + // Compile + "compile": "deno task bundle && deno compile -A -o silverbullet dist/silverbullet.js", + "server:dist:linux-x86_64": "deno task bundle && deno compile -A --target x86_64-unknown-linux-gnu dist/silverbullet.js -o silverbullet && zip silverbullet-server-linux-x86_64.zip silverbullet", + "server:dist:darwin-x86_64": "deno task bundle && deno compile -A --target x86_64-apple-darwin dist/silverbullet.js -o silverbullet && zip silverbullet-server-darwin-x86_64.zip silverbullet", + "server:dist:darwin-aarch64": "deno task bundle && deno task bundle && deno compile -A --target aarch64-apple-darwin dist/silverbullet.js -o silverbullet && zip silverbullet-server-darwin-aarch64.zip silverbullet", + "server:dist:windows-x86_64": "deno compile -A --target x86_64-pc-windows-msvc dist/silverbullet.js -o silverbullet.exe && zip silverbullet-server-windows-x86_64.zip silverbullet.exe" }, "compilerOptions": { diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..47ef664 --- /dev/null +++ b/install.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +if ! command -v unzip >/dev/null; then + echo "Error: unzip is required to install SilverBullet." 1>&2 + exit 1 +fi + +case $(uname -sm) in +"Darwin x86_64") target="darwin-x86_64" ;; +"Darwin arm64") target="darwin-aarch64" ;; +"Linux aarch64") + echo "Error: Official SilverBullet builds for Linux aarch64 are not available." 1>&2 + exit 1 + ;; +*) target="linux-x86_64" ;; +esac + +echo "Installing for $target" + +if [ $# -eq 0 ]; then + sb_uri="https://github.com/silverbulletmd/silverbullet/releases/latest/download/silverbullet-server-${target}.zip" +else + sb_uri="https://github.com/silverbulletmd/silverbullet/releases/download/${1}/silverbullet-server-${target}.zip" +fi +exe=silverbullet +bin_dir=. + +curl --fail --location --progress-bar --output "$exe.zip" "$sb_uri" +unzip -d "$bin_dir" -o "$exe.zip" +chmod +x "$exe" +rm "$exe.zip" + +echo "SilverBullet server was installed successfully to $bin, run it directly via ./$exe or move it to a more convenient place." \ No newline at end of file diff --git a/scripts/build_website.sh b/scripts/build_website.sh index 20245ca..28c96fd 100755 --- a/scripts/build_website.sh +++ b/scripts/build_website.sh @@ -48,4 +48,5 @@ echo > website_build/empty.md #echo "Bundling..." deno task bundle cp dist/silverbullet.js website_build/ -cp web/images/logo.ico website_build/ \ No newline at end of file +cp web/images/logo.ico website_build/ +cp install.sh website_build/ \ No newline at end of file