Skip to content

Commit

Permalink
fix substrate-node-template generation (#2050)
Browse files Browse the repository at this point in the history
# Description

This PR updates the node-template-release generation binary as well as
the `node-template-release.sh` file so that we can automatically push
updates to the [substrate-node-template
repository](https://github.com/substrate-developer-hub/substrate-node-template).
I assume this part was not updated after the substrate project has been
moved into the polkadot-sdk mono repo.

# Adjustments
- extend the `node-template-release.sh` to support the substrate
child-folder
- update the `SUBSTRATE_GIT_URL`
- fix the Cargo.toml filter (so that it does not include any
non-relevant .toml files)
- set the workspace-edition to 2021

# Note
In order to auto-generate the artifacts [this
line](https://github.com/paritytech/polkadot-sdk/blob/master/.gitlab/pipeline/build.yml#L320C15-L320C15)
needs to be included in the build.yml script again. Since I do not have
access to the (probably) internal gitlab environment I hope that someone
with actual access can introduce that change.
I also do not know how the auto-publish feature works so that would be
another thing to add later on.

---------

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
d-moos and bkchr authored Nov 1, 2023
1 parent 9987bbb commit 49c0f33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions substrate/scripts/ci/node-template-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
set -e

export TERM=xterm
PROJECT_ROOT=`git rev-parse --show-toplevel`
SUBSTRATE_FOLDER="/substrate"
GIT_ROOT=`git rev-parse --show-toplevel`
PROJECT_ROOT=${GIT_ROOT}${SUBSTRATE_FOLDER}

if [ "$#" -ne 1 ]; then
echo "node-template-release.sh path_to_target_archive"
exit 1
fi

PATH_TO_ARCHIVE=$1
cd $PROJECT_ROOT/scripts/ci/node-template-release

cd $PROJECT_ROOT/scripts/ci/node-template-release
cargo run $PROJECT_ROOT/bin/node-template $PROJECT_ROOT/$PATH_TO_ARCHIVE
16 changes: 11 additions & 5 deletions substrate/scripts/ci/node-template-release/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tar;
use tempfile;
use toml_edit::{self, value, Array, Item, Table};

const SUBSTRATE_GIT_URL: &str = "https://github.com/paritytech/substrate.git";
const SUBSTRATE_GIT_URL: &str = "https://github.com/paritytech/polkadot-sdk.git";

type CargoToml = toml_edit::Document;

Expand Down Expand Up @@ -63,7 +63,7 @@ fn copy_node_template(node_template: &Path, dest_path: &Path) {

/// Find all `Cargo.toml` files in the given path.
fn find_cargo_tomls(path: &PathBuf) -> Vec<PathBuf> {
let path = format!("{}/**/*.toml", path.display());
let path = format!("{}/**/Cargo.toml", path.display());

let glob = glob::glob(&path).expect("Generates globbing pattern");

Expand Down Expand Up @@ -196,7 +196,6 @@ fn update_root_cargo_toml(
) {
let mut workspace = Table::new();
workspace.insert("members", value(Array::from_iter(members.iter())));

let mut workspace_dependencies = Table::new();
deps.values()
.flatten()
Expand All @@ -212,6 +211,10 @@ fn update_root_cargo_toml(
workspace_dependencies[name]["rev"] = value(commit_id);
});

let mut package = Table::new();
package.insert("edition", value("2021"));
workspace.insert("package", Item::Table(package));

workspace.insert("dependencies", Item::Table(workspace_dependencies));
cargo_toml.insert("workspace", Item::Table(workspace));

Expand Down Expand Up @@ -428,9 +431,12 @@ frame-system = { workspace = true }
let expected_toml = r#"[workspace]
members = ["node", "pallets/template", "runtime"]
[workspace.package]
edition = "2021"
[workspace.dependencies]
frame-system = { version = "4.0.0-dev", default-features = true, git = "https://github.com/paritytech/substrate.git", rev = "commit_id" }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", rev = "commit_id" }
frame-system = { version = "4.0.0-dev", default-features = true, git = "https://github.com/paritytech/polkadot-sdk.git", rev = "commit_id" }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", rev = "commit_id" }
[profile]
Expand Down

0 comments on commit 49c0f33

Please sign in to comment.