Implement crate publishing on CI (#12768)

* implement crate publishing from CI

* fix indentation

* use resource_group for job exclusivity

ensure that at most one instance of the publish-crates job is running at any given time to prevent race conditions

* correct publish = false

* Remove YAML anchors as GitLab's `extends:` doesn't need it

* Temporarily force cache upload for the new jobs

* Revert `RUSTY_CACHIER_FORCE_UPLOAD`

* pin libp2p-tcp=0.37.0 for sc-telemetry

* Revert "pin libp2p-tcp=0.37.0 for sc-telemetry"

This reverts commit 29146bfad6c31e8cf0e2f17ad92a71bb81a373af.

* always collect generated crates

* increase timeout for publish-crates-template

* Force upload the new job cache again

* Revert "Force upload the new job cache again"

This reverts commit 5a5feee1b2c51fdef768b25a76be4c3949ec1c99.

* reformat

* improve timeout explanation

* s/usual/average

Co-authored-by: Vladimir Istyufeev <vladimir@parity.io>
This commit is contained in:
João Paulo Silva de Souza
2022-12-07 15:08:48 -03:00
committed by GitHub
parent 3b9d781afc
commit 8751f88fc7
48 changed files with 137 additions and 36 deletions
@@ -365,26 +365,47 @@ fn create_project_cargo_toml(
);
}
/// Find a package by the given `manifest_path` in the metadata.
/// Find a package by the given `manifest_path` in the metadata. In case it can't be found by its
/// manifest_path, fallback to finding it by name; this is necessary during publish because the
/// package's manifest path will be *generated* within a specific packaging directory, thus it won't
/// be found by its original path anymore.
///
/// Panics if the package could not be found.
fn find_package_by_manifest_path<'a>(
pkg_name: &str,
manifest_path: &Path,
crate_metadata: &'a cargo_metadata::Metadata,
) -> &'a cargo_metadata::Package {
crate_metadata
if let Some(pkg) = crate_metadata.packages.iter().find(|p| p.manifest_path == manifest_path) {
return pkg
}
let pkgs_by_name = crate_metadata
.packages
.iter()
.find(|p| p.manifest_path == manifest_path)
.expect("Wasm project exists in its own metadata; qed")
.filter(|p| p.name == pkg_name)
.collect::<Vec<_>>();
let mut pkgs = pkgs_by_name.iter();
if let Some(pkg) = pkgs.next() {
if pkgs.next().is_some() {
panic!(
"Found multiple packages matching the name {pkg_name} ({manifest_path:?}): {:?}",
pkgs_by_name
);
} else {
return pkg
}
} else {
panic!("Failed to find entry for package {pkg_name} ({manifest_path:?})");
}
}
/// Get a list of enabled features for the project.
fn project_enabled_features(
pkg_name: &str,
cargo_manifest: &Path,
crate_metadata: &cargo_metadata::Metadata,
) -> Vec<String> {
let package = find_package_by_manifest_path(cargo_manifest, crate_metadata);
let package = find_package_by_manifest_path(pkg_name, cargo_manifest, crate_metadata);
let std_enabled = package.features.get("std");
@@ -427,10 +448,11 @@ fn project_enabled_features(
/// Returns if the project has the `runtime-wasm` feature
fn has_runtime_wasm_feature_declared(
pkg_name: &str,
cargo_manifest: &Path,
crate_metadata: &cargo_metadata::Metadata,
) -> bool {
let package = find_package_by_manifest_path(cargo_manifest, crate_metadata);
let package = find_package_by_manifest_path(pkg_name, cargo_manifest, crate_metadata);
package.features.keys().any(|k| k == "runtime-wasm")
}
@@ -455,9 +477,10 @@ fn create_project(
fs::create_dir_all(wasm_project_folder.join("src"))
.expect("Wasm project dir create can not fail; qed");
let mut enabled_features = project_enabled_features(project_cargo_toml, crate_metadata);
let mut enabled_features =
project_enabled_features(&crate_name, project_cargo_toml, crate_metadata);
if has_runtime_wasm_feature_declared(project_cargo_toml, crate_metadata) {
if has_runtime_wasm_feature_declared(&crate_name, project_cargo_toml, crate_metadata) {
enabled_features.push("runtime-wasm".into());
}