Skip to content

Commit

Permalink
Release v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Dec 24, 2024
1 parent c9b6c3a commit c561f35
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 52 deletions.
21 changes: 17 additions & 4 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions 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.1"
version = "0.1.2"

[workspace.dependencies]
# crates.io
Expand All @@ -21,18 +21,19 @@ blake2 = { version = "0.10" }
chrono = { version = "0.4" }
clap = { version = "4.5" }
color-eyre = { version = "0.6" }
frame-metadata = { version = "18.0" }
ipfs-cid = { version = "2.0" }
md-5 = { version = "0.10" }
parity-scale-codec = { version = "3.6" }
reqwew = { version = "0.6", default-features = false }
sc-executor = { version = "0.40" }
sc-executor-common = { version = "0.35" }
serde = { version = "1.0" }
serde_json = { version = "1.0" }
sha2 = { version = "0.10" }
sp-core = { version = "34.0" }
sp-maybe-compressed-blob = { version = "11.0" }
sp-state-machine = { version = "0.43" }
sp-version = { version = "37.0" }
thiserror = { version = "2.0" }
tokio = { version = "1.42" }
toml = { version = "0.8" }
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ cargo install polkadot-runtime-releaser-cli

#### Install from GitHub
```sh
curl -L ..
# macOS
curl -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/latest/download/prr-aarch64-apple-darwin.zip \
-o prr.zip &&
unzip prr.zip &&
chmod u+x prr &&
rm prr.zip

# Linux
curl -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/latest/download/prr-x86_64-unknown-linux-gnu.tar.gz |
tar xz &&
chmod u+x prr

# If you like to move the binary to `~/.local/bin`. (OPTIONAL)
mkdir -p ~/.local/bin && mv prr ~/.local/bin
```

### Rust Toolchain
Expand Down
32 changes: 27 additions & 5 deletions action/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,40 @@ inputs:
features:
description: "Features to enable for the runtime crate."
required: false
default: ""
toolchain-version:
toolchain-ver:
description: "Rust toolchain version to use."
required: false
default: "stable"
workdir:
description: "Working directory for the runtime."
required: false
output-dir:
description: "Output directory for the runtime."
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.0/polkadot-runtime-releaser.tar.gz | tar xz && chmod +x prr && mv prr /usr/local/bin/prr
run: curl \
-L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.2/polkadot-runtime-releaser.tar.gz | \
tar xz && \
chmod u+x prr && \
mv prr /usr/local/bin/prr
- name: Build
shell: bash
run: prr build ${{ inputs.runtime }} -f ${{ inputs.features }} -t ${{ inputs.toolchain-version }}
run: |
CMD="prr build ${{ inputs.runtime }}"
if [ ! -z "${{ inputs.features }}" ]; then
CMD="$CMD -f ${{ inputs.features }}"
fi
if [ ! -z "${{ inputs.toolchain-ver }}" ]; then
CMD="$CMD -t ${{ inputs.toolchain-ver }}"
fi
if [ ! -z "${{ inputs.workdir }}" ]; then
CMD="$CMD -d ${{ inputs.workdir }}"
fi
if [ ! -z "${{ inputs.output-dir }}" ]; then
CMD="$CMD -o ${{ inputs.output-dir }}"
fi
eval "$CMD"
40 changes: 35 additions & 5 deletions action/override/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,56 @@ branding:
color: "blue"

inputs:
repository:
description: "Repository to fetch the runtime code from."
required: true
ref:
description: "Branch, tag, or commit of the runtime repository to fetch."
required: true
runtime:
description: "Target runtime crate to build."
required: true
features:
description: "Features to enable for the runtime crate."
required: false
default: ""
toolchain-version:
required: true
toolchain-ver:
description: "Rust toolchain version to use."
required: false
default: "stable"
token:
description: "GitHub token for authentication."
required: true
default: ${{ github.token }}

runs:
using: "composite"
steps:
- name: Fetch latest code
uses: actions/checkout@v4
with:
ref: ${{ inputs.runtime }}
path: override
- name: Fetch runtime code
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
path: runtime
- name: Build runtime
uses: ../build/action.yml
with:
runtime: ${{ inputs.runtime }}
features: ${{ inputs.features }}
toolchain-version: ${{ inputs.toolchain-version }}
toolchain-ver: ${{ inputs.toolchain-ver }}
workdir: runtime
output-dir: override/${{ inputs.features }}
- name: Commit changes
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: |
cd override
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Override `${{ inputs.ref }}`"
git push
26 changes: 19 additions & 7 deletions action/try-runtime/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ inputs:
features:
description: "Features to enable for the runtime crate."
required: false
default: ""
toolchain-version:
toolchain-ver:
description: "Rust toolchain version to use."
required: false
default: "stable"
try-runtime-version:
description: "Try Runtime CLI version to use."
required: false
Expand All @@ -29,16 +27,30 @@ runs:
steps:
- name: Setup try runtime CLI
shell: bash
run: curl -L https://github.com/paritytech/try-runtime-cli/releases/download/v${{ inputs.try-runtime-version }}/try-runtime-x86_64-unknown-linux-musl -o try-runtime && chmod +x try-runtime && mv try-runtime /usr/local/bin/try-runtime
run: curl \
-L https://github.com/paritytech/try-runtime-cli/releases/download/v${{ inputs.try-runtime-version }}/try-runtime-x86_64-unknown-linux-musl \
-o try-runtime && \
chmod +x try-runtime && \
mv try-runtime /usr/local/bin/try-runtime
- name: Build runtime
uses: ../build/action.yml
with:
runtime: ${{ inputs.runtime }}
features: ${{ inputs.features }}
toolchain-version: ${{ inputs.toolchain-version }}
toolchain-ver: ${{ inputs.toolchain-ver }}
- name: Try runtime
id: try_runtime
shell: bash
run: try-runtime --runtime $(find polkadot-runtime-releaser-output -name "*.compact.compressed.wasm") on-runtime-upgrade live -u ${{ inputs.uri }} 2>&1 | tee output.log
run: |
echo "output<<EOF" >> $GITHUB_OUTPUT
try-runtime \
--runtime $(find ./polkadot-runtime-releaser-output \
-name "*.compact.compressed.wasm") \
on-runtime-upgrade \
live \
-u ${{ inputs.uri }} \
2>&1 >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment
uses: peter-evans/create-or-update-comment@v4
with:
Expand All @@ -48,6 +60,6 @@ runs:
<summary>Try Runtime Output for ${{ inputs.runtime }}</summary>
```
${{ cat output.log }}
${{ steps.try_runtime.outputs.output }}
```
</details>
52 changes: 31 additions & 21 deletions cli/src/cli/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,19 @@ impl Run for InspectCmd {
let Self { path, check_version, verbose } = self;
let wasmer = Wasmer::load(&path)?;
let built_at = fs::metadata(&path)?.created()?;
let compressed_size = wasmer.compressed()?.len();
let decompressed_size = wasmer.decompressed()?.len();
let compressed = wasmer.compressed()?.len();
let uncompressed = wasmer.decompressed()?.len();
let size = Size { compressed, uncompressed };
let md5 = hasher::md5(&wasmer.code);
let sha256 = hasher::sha256(&wasmer.code);
let blake2_256 = hasher::blake2_256(&wasmer.code);
let ipfs = ipfs_cid::generate_cid_v0(&wasmer.code)?;
let version = wasmer.runtime_version(verbose)?;
let call_hashes = CallHashes::of(&wasmer, check_version);
let json = serde_json::to_string(&Output {
built_at,
compressed_size,
decompressed_size,
md5,
sha256,
blake2_256,
ipfs,
version,
call_hashes,
})?;
let hash = Hash { md5, sha256, blake2_256, ipfs };
let runtime = wasmer.runtime_version(verbose)?;
let metadata = wasmer.metadata()?.version();
let version = Ver { runtime, metadata };
let call_hash = CallHash::of(&wasmer, check_version);
let json = serde_json::to_string(&Output { built_at, size, hash, version, call_hash })?;

println!("{json}");

Expand All @@ -55,29 +49,45 @@ impl Run for InspectCmd {
struct Output {
#[serde(serialize_with = "util::ser_system_time")]
built_at: SystemTime,
size: Size,
hash: Hash,
version: Ver,
call_hash: CallHash,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
struct Size {
#[serde(serialize_with = "util::ser_size_mb")]
compressed_size: usize,
compressed: usize,
#[serde(serialize_with = "util::ser_size_mb")]
decompressed_size: usize,
uncompressed: usize,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
struct Hash {
#[serde(serialize_with = "array_bytes::ser_hex")]
md5: [u8; 16],
#[serde(serialize_with = "array_bytes::ser_hex")]
sha256: [u8; 32],
#[serde(serialize_with = "array_bytes::ser_hex")]
blake2_256: [u8; 32],
ipfs: String,
version: Version,
call_hashes: CallHashes,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
struct CallHashes {
struct Ver {
runtime: Version,
metadata: u32,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
struct CallHash {
#[serde(serialize_with = "array_bytes::ser_hex")]
set_code: [u8; 32],
#[serde(serialize_with = "array_bytes::ser_hex")]
authorized_upgrade: [u8; 32],
}
impl CallHashes {
impl CallHash {
fn of(wasmer: &Wasmer, check_version: bool) -> Self {
let set_code = hasher::blake2_256(
[
Expand Down
6 changes: 3 additions & 3 deletions cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// std
use std::time::SystemTime;
// crates.io
use chrono::{DateTime, Utc};
use chrono::{DateTime, SecondsFormat, Utc};
use serde::Serializer;

pub fn ser_system_time<S>(time: &SystemTime, serializer: S) -> Result<S::Ok, S::Error>
Expand All @@ -10,7 +10,7 @@ where
{
let date = <DateTime<Utc>>::from(*time);

serializer.serialize_str(&date.to_rfc3339())
serializer.serialize_str(&date.to_rfc3339_opts(SecondsFormat::Secs, true))
}

pub fn ser_size_mb<S>(size: &usize, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -50,6 +50,6 @@ fn ser_should_work() {
size: 1024 * 1024
})
.unwrap(),
r#"{"time":"2021-08-01T00:00:00+00:00","size":"1.00 MB (1,048,576 bytes)"}"#
r#"{"time":"2021-08-01T00:00:00Z","size":"1.00 MB (1,048,576 bytes)"}"#
)
}
Loading

0 comments on commit c561f35

Please sign in to comment.