Skip to content

Commit

Permalink
Release v0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Dec 26, 2024
1 parent 34cc683 commit 9d5acb8
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
homepage = "https://hack.ink/polkadot-runtime-releaser"
license = "GPL-3.0"
repository = "https://github.com/hack-ink/polkadot-runtime-releaser"
version = "0.1.8"
version = "0.1.9"

[workspace.dependencies]
# crates.io
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ PPR also supports using a custom Docker image. Use `ppr build --help` to get mor
### Runtime
#### IMPORTANT NOTES
- PRR makes some assumption while deal with the runtime artifacts.
- Runtime crate name is in `{}-runtime` format. E.G. [`polkadot-runtime`](https://github.com/polkadot-fellows/runtimes/blob/46dcafcee64fe4d8c722d071a4a0ca983fcc2f08/relay/polkadot/Cargo.toml#L2)
- WASM file name is in `{}_runtime.compact.compressed.wasm` format. E.G. [`polkadot_runtime.compact.compressed.wasm`](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.3.4)
- Runtime crate name must be in `{}-runtime` format. E.G. [`polkadot-runtime`](https://github.com/polkadot-fellows/runtimes/blob/46dcafcee64fe4d8c722d071a4a0ca983fcc2f08/relay/polkadot/Cargo.toml#L2)
- WASM file name must be in `{}_runtime.compact.compressed.wasm` format. E.G. [`polkadot_runtime.compact.compressed.wasm`](https://github.com/polkadot-fellows/runtimes/releases/tag/v1.3.4)

### GitHub

Expand Down
8 changes: 1 addition & 7 deletions action/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ inputs:
runtime:
description: "Target runtime to build."
required: true
override-runtime-name:
description: "The name to use matching the runtime artifacts."
required: false
features:
description: "Features to enable for the runtime."
required: false
Expand All @@ -30,7 +27,7 @@ runs:
- name: Setup Polkadot Runtime Releaser
shell: bash
run: curl
-L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.8/prr-x86_64-unknown-linux-gnu.tar.gz |
-L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.9/prr-x86_64-unknown-linux-gnu.tar.gz |
tar xz &&
chmod u+x prr &&
mv prr /usr/local/bin/prr
Expand All @@ -39,9 +36,6 @@ runs:
run: |
CMD="prr build ${{ inputs.runtime }}"
if [ ! -z "${{ inputs.override-runtime-name }}" ]; then
CMD="$CMD -n ${{ inputs.override-runtime-name }}"
fi
if [ ! -z "${{ inputs.features }}" ]; then
CMD="$CMD -f ${{ inputs.features }}"
fi
Expand Down
24 changes: 22 additions & 2 deletions action/inspect/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,42 @@ inputs:
runtime:
description: "Target runtime to inspect."
required: true
no-check-version:
description: "Whether to check the runtime version in the `ParachainSystem::authorized_upgrade` call."
required: false
beautify:
description: "Whether to beautify the JSON output."
required: false
verbose:
description: "Whether to print verbose output."
required: false

runs:
using: "composite"
steps:
- name: Setup Polkadot Runtime Releaser
shell: bash
run: curl
-L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.8/prr-x86_64-unknown-linux-gnu.tar.gz |
-L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.9/prr-x86_64-unknown-linux-gnu.tar.gz |
tar xz &&
chmod u+x prr &&
mv prr /usr/local/bin/prr
- name: Inspect runtime
id: inspect
shell: bash
run: |
RESULT=$(prr inspect ${{ inputs.runtime }})
CMD="prr inspect ${{ inputs.runtime }}"
if [ ! -z "${{ inputs.no-check-version }}" ]; then
CMD="$CMD --no-check-version"
fi
if [ ! -z "${{ inputs.beautify }}" ]; then
CMD="$CMD -b"
fi
if [ ! -z "${{ inputs.verbose }}" ]; then
CMD="$CMD -v"
fi
RESULT=$(${CMD})
echo "result=${RESULT}" >> "$GITHUB_OUTPUT"
outputs:
Expand Down
3 changes: 1 addition & 2 deletions action/override/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ runs:
ref: ${{ inputs.ref }}
path: runtime
- name: Build runtime
uses: hack-ink/polkadot-runtime-releaser/action/[email protected].8
uses: hack-ink/polkadot-runtime-releaser/action/[email protected].9
with:
runtime: ${{ inputs.runtime }}
override-runtime-name: ${{ inputs.override-runtime-name }}
features: ${{ inputs.features }}
toolchain-ver: ${{ inputs.toolchain-ver }}
workdir: runtime
Expand Down
2 changes: 1 addition & 1 deletion action/try-runtime/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ runs:
chmod +x try-runtime &&
mv try-runtime /usr/local/bin/try-runtime
- name: Build runtime
uses: hack-ink/polkadot-runtime-releaser/action/[email protected].8
uses: hack-ink/polkadot-runtime-releaser/action/[email protected].9
with:
runtime: ${{ inputs.runtime }}
features: ${{ inputs.features }}
Expand Down
73 changes: 36 additions & 37 deletions cli/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{env, fs, path::PathBuf};
// crates.io
use clap::Parser;
// self
use crate::{cli::Run, prelude::*};
use crate::{
cli::{InspectCmd, Run},
prelude::*,
};
use prr_lib::{docker::RunArgs, rust, wasmer::Wasmer};

const WASM_EXT: &str = "wasm";
Expand All @@ -17,20 +20,15 @@ pub struct BuildCmd {
/// This should be the name of the runtime crate in the <Cargo.toml> file.
#[arg(value_name = "RUNTIME", verbatim_doc_comment)]
runtime: String,
/// The name to use matching the runtime artifacts.
/// This is useful when the runtime crate name is different from the runtime name.
///
/// For example, `staging-kusama-runtime`.
/// With this option, you can specify the runtime name to be `kusama`,
/// and it will match the `kusama_runtime*.wasm` artifacts.
#[arg(long, short = 'n', value_name = "NAME", verbatim_doc_comment)]
override_runtime_name: Option<String>,
/// The features to enable for the runtime.
#[arg(long, short, value_name = "FEATURES", verbatim_doc_comment)]
features: Option<String>,
/// Whether to store the compressed runtime only.
#[arg(long, verbatim_doc_comment)]
no_compressed_only: bool,
/// Whether to generate the digest file for the runtime.
#[arg(long, verbatim_doc_comment)]
no_digest: bool,
/// The toolchain version to use for the build; by default, it is set to <stable>.
///
/// This won't take effect if there is a <rust-toolchain.toml> file in the project directory,
Expand All @@ -42,7 +40,7 @@ pub struct BuildCmd {
long,
short = 'v',
value_name = "VER",
default_value_t = String::from("0.1.8"),
default_value_t = String::from("0.1.9"),
verbatim_doc_comment,
conflicts_with = "override_docker_image"
)]
Expand Down Expand Up @@ -84,9 +82,9 @@ impl Run for BuildCmd {
fn run(self) -> Result<()> {
let Self {
runtime,
override_runtime_name,
features,
no_compressed_only,
no_digest,
toolchain_version,
image_version,
override_docker_image,
Expand All @@ -101,7 +99,7 @@ impl Run for BuildCmd {

let output_dir = {
if !output_dir.exists() {
tracing::info!("creating the output directory {}", output_dir.display());
tracing::info!("creating the output directory {output_dir:?}");

fs::create_dir(&output_dir)?;
}
Expand All @@ -121,10 +119,7 @@ impl Run for BuildCmd {
let output_target_dir = output_dir.join("target");

if !cache_output && output_target_dir.exists() {
tracing::info!(
"purging previous output target directory {}",
output_target_dir.display()
);
tracing::info!("purging previous output target directory {output_target_dir:?}",);

fs::remove_dir_all(&output_target_dir)?;
}
Expand All @@ -145,34 +140,38 @@ impl Run for BuildCmd {
run_args.with_command(&cmd);
run_args.run()?;

let snake_case_rt = if let Some(name) = override_runtime_name {
format!("{name}_runtime")
} else {
runtime.replace("-runtime", "_runtime")
};
// https://github.com/paritytech/polkadot-sdk/blob/ca7817922148c1e6f6856138998f7135f42f3f4f/substrate/utils/wasm-builder/src/wasm_project.rs#L502.
let snake_case_name = runtime.replace("-", "_");
let output_rt =
output_target_dir.join("release/wbuild").join(&runtime).join(&snake_case_rt);
let compressed_wasm = output_rt.with_extension(WASM_EXT_COMPRESSED);
let ver = Wasmer::load(&compressed_wasm)?.runtime_version(true)?.spec_version;
let rt_name = format!("{snake_case_rt}-{ver}");
output_target_dir.join("release/wbuild").join(&runtime).join(&snake_case_name);
let compressed_rt = output_rt.with_extension(WASM_EXT_COMPRESSED);

tracing::info!("loading {compressed_rt:?}");

let wasmer = Wasmer::load(&compressed_rt)?;
let ver = wasmer.runtime_version(true)?.spec_version;
let rt_prefix = output_dir.join(format!("{snake_case_name}-{ver}"));

fs::copy(compressed_wasm, output_dir.join(&rt_name).with_extension(WASM_EXT_COMPRESSED))?;
util::copy(&compressed_rt, &rt_prefix.with_extension(WASM_EXT_COMPRESSED))?;

if no_compressed_only {
fs::copy(
output_rt.with_extension(WASM_EXT_COMPACT),
output_dir.join(&rt_name).with_extension(WASM_EXT_COMPACT),
)?;
fs::copy(
output_rt.with_extension(WASM_EXT),
output_dir.join(&rt_name).with_extension(WASM_EXT),
util::copy(
&output_rt.with_extension(WASM_EXT_COMPACT),
&rt_prefix.with_extension(WASM_EXT_COMPACT),
)?;
util::copy(&output_rt.with_extension(WASM_EXT), &rt_prefix.with_extension(WASM_EXT))?;
}
if !no_digest {
let digest_path = rt_prefix.with_extension("json");

tracing::info!("generating {digest_path:?}");

let digest = InspectCmd::new(compressed_rt, false, false, false).inspect(wasmer)?;

fs::write(&digest_path, digest)?;
}
if !cache_output {
tracing::info!(
"cleaning up the output target directory {}",
output_target_dir.display()
);
tracing::info!("cleaning up the output target directory {output_target_dir:?}",);

fs::remove_dir_all(&output_target_dir)?;
}
Expand Down
36 changes: 28 additions & 8 deletions cli/src/cli/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ pub struct InspectCmd {
#[arg(value_name = "PATH", verbatim_doc_comment)]
path: PathBuf,
/// Whether to check the runtime version in the `ParachainSystem::authorized_upgrade` call.
#[arg(long, default_value_t = true, verbatim_doc_comment)]
check_version: bool,
#[arg(long, verbatim_doc_comment)]
no_check_version: bool,
/// Whether to beautify the JSON output.
#[arg(long, short, verbatim_doc_comment)]
beautify: bool,
/// Whether to print verbose output.
#[arg(short, long, verbatim_doc_comment)]
#[arg(long, short, verbatim_doc_comment)]
verbose: bool,
}
impl Run for InspectCmd {
fn run(self) -> Result<()> {
let Self { path, check_version, verbose } = self;
let wasmer = Wasmer::load(&path)?;
impl InspectCmd {
pub fn new(path: PathBuf, no_check_version: bool, beautify: bool, verbose: bool) -> Self {
Self { path, no_check_version, beautify, verbose }
}

pub fn inspect(self, wasmer: Wasmer) -> Result<String> {
let Self { path, no_check_version, beautify, verbose } = self;
let built_at = fs::metadata(&path)?.created()?;
let compressed = wasmer.compressed()?.len();
let uncompressed = wasmer.decompressed()?.len();
Expand All @@ -35,8 +41,22 @@ impl Run for InspectCmd {
let runtime = wasmer.runtime_version(verbose)?;
let metadata = wasmer.metadata()?.version();
let version = Ver { runtime, metadata };
let check_version = !no_check_version;
let call_hash = CallHash::of(&wasmer, check_version);
let json = serde_json::to_string(&Output { built_at, size, hash, version, call_hash })?;
let output = Output { built_at, size, hash, version, call_hash };
let json = if beautify {
serde_json::to_string_pretty(&output)?
} else {
serde_json::to_string(&output)?
};

Ok(json)
}
}
impl Run for InspectCmd {
fn run(self) -> Result<()> {
let wasmer = Wasmer::load(&self.path)?;
let json = self.inspect(wasmer)?;

println!("{json}");

Expand Down
12 changes: 11 additions & 1 deletion cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// std
use std::time::SystemTime;
use std::{fs, path::Path, time::SystemTime};
// crates.io
use chrono::{DateTime, SecondsFormat, Utc};
use serde::Serializer;
// self
use crate::prelude::*;

pub fn copy(from: &Path, to: &Path) -> Result<()> {
tracing::info!("copying {from:?} to {to:?}");

fs::copy(from, to)?;

Ok(())
}

pub fn ser_system_time<S>(time: &SystemTime, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ubuntu:25.04

LABEL maintainer="[email protected]"
LABEL description="An environment for constructing a deterministic polkadot-sdk-based runtime."
LABEL version="0.1.8"
LABEL version="0.1.9"

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Expand Down
24 changes: 19 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ HOST_UID="${HOST_UID:-}"
HOST_GID="${HOST_GID:-}"

if [ -z "$HOST_UID" ] || [ -z "$HOST_GID" ]; then
echo "HOST_UID/HOST_GID are not set. Running as root."
echo "HOST_UID/HOST_GID are not set, running as root"
exec "$@"
else
echo "Running as UID=${HOST_UID}, GID=${HOST_GID}."
echo "running as UID=${HOST_UID}, GID=${HOST_GID}."

groupadd -g "$HOST_GID" builder
useradd -m -u "$HOST_UID" -g "$HOST_GID" builder
if getent group "${HOST_GID}" >/dev/null 2>&1; then
EXISTING_GROUP_NAME="$(getent group "${HOST_GID}" | cut -d: -f1)"
echo "group with GID ${HOST_GID} already exists: ${EXISTING_GROUP_NAME}, reusing that group"
GROUP_NAME="${EXISTING_GROUP_NAME}"
else
GROUP_NAME="builder"
groupadd -g "${HOST_GID}" "${GROUP_NAME}"
fi

exec gosu builder "$@"
if id -u "${HOST_UID}" >/dev/null 2>&1; then
echo "user with UID ${HOST_UID} already exists, reusing that user"
USER_NAME="$(id -nu "${HOST_UID}")"
else
USER_NAME="builder"
useradd -m -u "${HOST_UID}" -g "${GROUP_NAME}" "${USER_NAME}"
fi

exec gosu "${USER_NAME}" "$@"
fi
2 changes: 1 addition & 1 deletion lib/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
return Ok(());
}

tracing::info!("creating toolchain config {}", toml.display());
tracing::info!("creating toolchain config {toml:?}");

let toolchain = toolchain_config_of(ver);

Expand Down

0 comments on commit 9d5acb8

Please sign in to comment.