Skip to content

Commit

Permalink
Merge pull request #3138 from dahlia/1.0-maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia authored May 4, 2023
2 parents b360034 + 45d4f86 commit eb6a998
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 44 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/yarn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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<T>.Append()` hadn't update tx executions
even `evaluateActions` set to `true` when `actionEvaluations` are given.
[[#3125]]
Expand Down
20 changes: 14 additions & 6 deletions Libplanet.Tools/Program.cs
Original file line number Diff line number Diff line change
@@ -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.")]
Expand All @@ -31,7 +30,16 @@ public class Program

public static Task Main(string[] args)
{
CryptoConfig.CryptoBackend = new Secp256k1CryptoBackend<SHA256>();
try
{
CryptoConfig.CryptoBackend = new Secp256k1CryptoBackend<SHA256>();
}
catch (Exception)
{
// If it fails to load the Secp256k1CryptoBackend<T> for any reason
// fall back to the DefaultCryptoBackend<T> instead.
}

return CoconaLiteApp.CreateHostBuilder()
.ConfigureServices(services =>
{
Expand Down
25 changes: 21 additions & 4 deletions Libplanet.Tools/bin/npm-test.ps1
Original file line number Diff line number Diff line change
@@ -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 $_
Expand All @@ -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 " "
Expand All @@ -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") `
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tools/bin/npm-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 21 additions & 23 deletions Libplanet.Tools/download.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Inspired by Elm's npm packaging: <https://www.npmjs.com/package/elm>.
"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 = {
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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(`
-------------------------------------------------------------------------------
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion Libplanet/Libplanet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<PackageId>Libplanet</PackageId>
<Title>Libplanet</Title>
<VersionPrefix>1.0.1</VersionPrefix>
<VersionPrefix>1.0.2</VersionPrefix>
<!-- Note: don't be confused by the word "prefix" here. It's merely a
version without suffix like "-dev.123". See the following examples:
Version: 1.2.3-dev.456
Expand Down
Loading

0 comments on commit eb6a998

Please sign in to comment.