diff --git a/.github/workflows/yarn.yaml b/.github/workflows/yarn.yaml index 306854750da..eb2bf8c0148 100644 --- a/.github/workflows/yarn.yaml +++ b/.github/workflows/yarn.yaml @@ -51,11 +51,13 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Required for the latest-tag action - id: latest-tag name: Get the latest tag uses: WyriHaximus/github-action-get-previous-tag@v1 with: - fallback: 0.27.3 + fallback: 1.0.0 - if: runner.os != 'Windows' run: | set -ev @@ -64,10 +66,11 @@ jobs: env: LATEST_VERSION: ${{ steps.latest-tag.outputs.tag }} - if: runner.os == 'Windows' + shell: pwsh run: | $ErrorActionPreference = "Stop" cd Libplanet.Tools\ - powershell ` + pwsh ` -ExecutionPolicy Bypass ` -File bin\npm-test.ps1 ` -Version $env:LATEST_VERSION diff --git a/CHANGES.md b/CHANGES.md index 3b0943cfb46..c9a45c6d2cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,13 +1,26 @@ Libplanet changelog =================== +Version 1.0.2 +------------- + +Released on May 4, 2023. + + - (Libplanet.Tools) The `planet` command now falls back to the default + cryptography backend instead of crash when it fails to load *libsecp256k1* + at runtime. [[#3138]] + - (@planetarium/cli) Fixed the installer bug that it had failed with some + recent Node.js versions on Windows. [[#3107], [#3138]] + +[#3107]: https://github.com/planetarium/libplanet/issues/3107 +[#3138]: https://github.com/planetarium/libplanet/pull/3138 + + Version 1.0.1 ------------- Released on May 3, 2023. -### Bug fixes - - Fixed a bug where `BlockChain.Append()` hadn't update tx executions even `evaluateActions` set to `true` when `actionEvaluations` are given. [[#3125]] diff --git a/Libplanet.Tools/Program.cs b/Libplanet.Tools/Program.cs index 864d816ee50..63ddd25de29 100644 --- a/Libplanet.Tools/Program.cs +++ b/Libplanet.Tools/Program.cs @@ -1,16 +1,15 @@ -using System.Security.Cryptography; -using Libplanet.Crypto; -using Libplanet.Crypto.Secp256k1; -using CryptoConfig = Libplanet.Crypto.CryptoConfig; - namespace Libplanet.Tools; using System; using System.IO; +using System.Security.Cryptography; using System.Threading.Tasks; using Cocona; +using Libplanet.Crypto.Secp256k1; +using Libplanet.Crypto; using Libplanet.Extensions.Cocona.Commands; using Libplanet.Extensions.Cocona.Extensions; +using CryptoConfig = Libplanet.Crypto.CryptoConfig; [HasSubCommands(typeof(ApvCommand), "apv", Description = "App protocol version utilities.")] [HasSubCommands(typeof(KeyCommand), "key", Description = "Manage private keys.")] @@ -31,7 +30,16 @@ public class Program public static Task Main(string[] args) { - CryptoConfig.CryptoBackend = new Secp256k1CryptoBackend(); + try + { + CryptoConfig.CryptoBackend = new Secp256k1CryptoBackend(); + } + catch (Exception) + { + // If it fails to load the Secp256k1CryptoBackend for any reason + // fall back to the DefaultCryptoBackend instead. + } + return CoconaLiteApp.CreateHostBuilder() .ConfigureServices(services => { diff --git a/Libplanet.Tools/bin/npm-test.ps1 b/Libplanet.Tools/bin/npm-test.ps1 index 6630ea17f03..21b6c92838f 100644 --- a/Libplanet.Tools/bin/npm-test.ps1 +++ b/Libplanet.Tools/bin/npm-test.ps1 @@ -1,11 +1,15 @@ #!/usr/bin/env pwsh param ( [Parameter(Mandatory, Position=0, HelpMessage="Enter a version to download.")] - [ValidatePattern("^[0-9]+\.[1-9][0-9]*\.[0-9]+$")] + [ValidatePattern("^([1-9][0-9]*|0)\.([1-9][0-9]*|0)\.([1-9][0-9]*|0)$")] [string] $Version ) +$ErrorActionPreference = "Stop" +$InformationPreference = "Continue" +$DebugPreference = "Continue" + function New-TemporaryDirectory { New-TemporaryFile | ForEach-Object { Remove-Item $_ @@ -17,6 +21,11 @@ function Test-Npx( [Parameter(Mandatory, Position=0)][string[]]$Command, [Parameter(Mandatory, Position=1)][string]$Expected ) { + if ($env:ACTIONS_RUNNER_DEBUG -eq "true") { + $cmd = $Command -Join " " + & "npx" @Command + Write-Debug "The command 'npx $cmd' terminated with $?." + } $actual = & "npx" @Command if ($actual -ne $Expected) { $cmd = $Command -Join " " @@ -31,9 +40,17 @@ function Test-Planet() { Test-Npx @("planet", "--version") "planet $Version" } -$ErrorActionPreference = "Stop" -$InformationPreference = "Continue" -$DebugPreference = "Continue" +if (-not (Get-Command yarn 2> $null)) { + Write-Error "The yarn is unavailable." + exit 1 +} elseif (-not (Get-Command npm 2> $null)) { + Write-Error "The npm is unavailable." + exit 1 +} elseif (-not (Get-Command npx 2> $null)) { + Write-Error "The npx command is unavailable." + exit 1 +} + $PackageDir = Resolve-Path (Split-Path -Path $PSScriptRoot -Parent) Copy-Item (Join-Path -Path $PackageDir -ChildPath "package.json") ` diff --git a/Libplanet.Tools/bin/npm-test.sh b/Libplanet.Tools/bin/npm-test.sh index 611ffd7a61a..121a3f97ac3 100755 --- a/Libplanet.Tools/bin/npm-test.sh +++ b/Libplanet.Tools/bin/npm-test.sh @@ -3,7 +3,7 @@ set -e if [[ "$1" = "" ]]; then echo error: missing version to download >&2 exit 1 -elif [[ "$1" =~ ^[0-9]+\.[1-9][0-9]*\.[0-9]+$ ]]; then +elif [[ "$1" =~ ^([1-9][0-9]*|0)\.([1-9][0-9]*|0)\.([1-9][0-9]*|0)$ ]]; then version="$1" else echo error: invalid version number: "$1" >&2 diff --git a/Libplanet.Tools/download.mjs b/Libplanet.Tools/download.mjs index 4f06bbcaab0..a50d75fc68e 100644 --- a/Libplanet.Tools/download.mjs +++ b/Libplanet.Tools/download.mjs @@ -2,12 +2,14 @@ // Inspired by Elm's npm packaging: . "use strict"; import child_process from "child_process"; +import { createWriteStream } from "fs"; import { chmod, copyFile, mkdtemp, readFile } from "fs/promises"; +import { pipeline } from "stream/promises"; import os from "os"; import { fileURLToPath } from 'url'; import path from "path"; import fetch from "node-fetch"; -import unzipper from "unzipper"; +import extractZip from "extract-zip"; const URL_BASE = "https://github.com/planetarium/libplanet/releases/download"; const SUFFIXES = { @@ -49,31 +51,21 @@ export async function download(options = {}) { await chmod(dstPath, 0o755); }; - const unarchive = (value) => { - return new Promise((resolve, reject) => { - let retVal; - - if (suffix.toLowerCase().endsWith(".zip")) { - retVal = unzipper.Extract({ path: dirPath }); - retVal.on("close", err => { - if (err) return reject(err); - return resolve(); - }); - } else { - const subproc = child_process.spawn("tar", ["xvJ"], { + const unarchive = (archivePath) => { + if (suffix.toLowerCase().endsWith(".zip")) { + return extractZip(archivePath, { dir: dirPath }); + } else { + return new Promise((resolve, reject) => { + const subproc = child_process.spawn("tar", ["xvJ", archivePath], { cwd: dirPath, - stdio: ["pipe", "ignore", "ignore"] + stdio: ["ignore", "ignore", "ignore"] }); subproc.on("close", code => { if (code !== 0) return reject(code); return resolve(); }); - retVal = subproc.stdin; - } - - retVal.on("error", reject); - value.pipe(retVal); - }); + }); + } }; const adhocSign = () => { @@ -112,9 +104,11 @@ All this package does is downloading that file and put it somewhere. ------------------------------------------------------------------------------- `); - let res; + const archivePath = path.join(dirPath, url.match(/[^/]+$/)[0]); + const writeStream = createWriteStream(archivePath); try { - res = await fetch(url); + const res = await fetch(url); + await pipeline(res.body, writeStream); } catch (err) { console.error(` ------------------------------------------------------------------------------- @@ -130,12 +124,16 @@ ${err} throw e; } try { - await unarchive(res.body); + await unarchive(archivePath); } catch (err) { console.error(` ------------------------------------------------------------------------------- An error occurred during unarchiving Libplanet CLI Tools: + ${archivePath} + +... which is downloaded from: + ${url} Report this issue from https://github.com/planetarium/libplanet/issues diff --git a/Libplanet.Tools/package.json b/Libplanet.Tools/package.json index f8f8fe230c9..8f5a0f438f7 100644 --- a/Libplanet.Tools/package.json +++ b/Libplanet.Tools/package.json @@ -22,8 +22,8 @@ "install.mjs" ], "dependencies": { - "node-fetch": "^3.1.1", - "unzipper": "^0.10.11" + "extract-zip": "^2.0.1", + "node-fetch": "^3.1.1" }, "type": "module", "scripts": { diff --git a/Libplanet/Libplanet.csproj b/Libplanet/Libplanet.csproj index e397fa6353f..6821f1bbafc 100644 --- a/Libplanet/Libplanet.csproj +++ b/Libplanet/Libplanet.csproj @@ -2,7 +2,7 @@ Libplanet Libplanet - 1.0.1 + 1.0.2